Skip to content

Make test suite compatible with PHPCS 3.8.0 #304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,24 @@ public function getFixture($fixtureFilename)
{
return realpath(__DIR__ . '/VariableAnalysisSniff/fixtures/' . $fixtureFilename);
}

public function setSniffProperty($phpcsFile, $property, $value)
{
if (version_compare(Config::VERSION, '3.8.0', '>=')) {
$phpcsFile->ruleset->setSniffProperty(
'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff',
$property,
[
'scope' => 'sniff',
'value' => $value,
]
);
} else {
$phpcsFile->ruleset->setSniffProperty(
'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff',
$property,
$value
);
}
}
}
12 changes: 2 additions & 10 deletions Tests/VariableAnalysisSniff/ArrowFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ public function testArrowFunctions()
{
$fixtureFile = $this->getFixture('ArrowFunctionFixture.php');
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile);
$phpcsFile->ruleset->setSniffProperty(
'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff',
'allowUnusedParametersBeforeUsed',
'true'
);
$this->setSniffProperty($phpcsFile, 'allowUnusedParametersBeforeUsed', 'true');
$phpcsFile->process();
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
$expectedWarnings = [
Expand All @@ -41,11 +37,7 @@ public function testArrowFunctionsWithoutUnusedBeforeUsed()
{
$fixtureFile = $this->getFixture('ArrowFunctionFixture.php');
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile);
$phpcsFile->ruleset->setSniffProperty(
'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff',
'allowUnusedParametersBeforeUsed',
'false'
);
$this->setSniffProperty($phpcsFile, 'allowUnusedParametersBeforeUsed', 'false');
$phpcsFile->process();
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
$expectedWarnings = [
Expand Down
18 changes: 3 additions & 15 deletions Tests/VariableAnalysisSniff/GlobalScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ public function testGlobalScopeWarnings()
{
$fixtureFile = $this->getFixture('GlobalScopeFixture.php');
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile);
$phpcsFile->ruleset->setSniffProperty(
'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff',
'allowUndefinedVariablesInFileScope',
'false'
);
$this->setSniffProperty($phpcsFile, 'allowUndefinedVariablesInFileScope', 'false');
$phpcsFile->process();
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
$expectedErrors = [
Expand All @@ -31,11 +27,7 @@ public function testGlobalScopeWarningsWithAllowUndefinedVariablesInFileScope()
{
$fixtureFile = $this->getFixture('GlobalScopeFixture.php');
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile);
$phpcsFile->ruleset->setSniffProperty(
'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff',
'allowUndefinedVariablesInFileScope',
'true'
);
$this->setSniffProperty($phpcsFile, 'allowUndefinedVariablesInFileScope', 'true');
$phpcsFile->process();
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
$expectedErrors = [
Expand All @@ -51,11 +43,7 @@ public function testGlobalScopeWarningsWithAllowUnusedVariablesInFileScope()
{
$fixtureFile = $this->getFixture('GlobalScopeFixture.php');
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile);
$phpcsFile->ruleset->setSniffProperty(
'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff',
'allowUnusedVariablesInFileScope',
'true'
);
$this->setSniffProperty($phpcsFile, 'allowUnusedVariablesInFileScope', 'true');
$phpcsFile->process();
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
$expectedErrors = [
Expand Down
36 changes: 6 additions & 30 deletions Tests/VariableAnalysisSniff/IfConditionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ public function testIfConditionWarnings()
{
$fixtureFile = $this->getFixture('FunctionWithIfConditionFixture.php');
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile);
$phpcsFile->ruleset->setSniffProperty(
'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff',
'allowUnusedParametersBeforeUsed',
'true'
);
$this->setSniffProperty($phpcsFile, 'allowUnusedParametersBeforeUsed', 'true');
$phpcsFile->process();
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
$expectedWarnings = [
Expand Down Expand Up @@ -43,16 +39,8 @@ public function testIfConditionWarningsWithValidUndefinedVariableNames()
{
$fixtureFile = $this->getFixture('FunctionWithIfConditionFixture.php');
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile);
$phpcsFile->ruleset->setSniffProperty(
'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff',
'validUndefinedVariableNames',
'second'
);
$phpcsFile->ruleset->setSniffProperty(
'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff',
'allowUnusedParametersBeforeUsed',
'true'
);
$this->setSniffProperty($phpcsFile, 'validUndefinedVariableNames', 'second');
$this->setSniffProperty($phpcsFile, 'allowUnusedParametersBeforeUsed', 'true');
$phpcsFile->process();
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
$expectedWarnings = [
Expand All @@ -75,11 +63,7 @@ public function testInlineIfConditionWarnings()
{
$fixtureFile = $this->getFixture('FunctionWithInlineIfConditionFixture.php');
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile);
$phpcsFile->ruleset->setSniffProperty(
'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff',
'allowUnusedParametersBeforeUsed',
'true'
);
$this->setSniffProperty($phpcsFile, 'allowUnusedParametersBeforeUsed', 'true');
$phpcsFile->process();
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
$expectedWarnings = [
Expand Down Expand Up @@ -110,16 +94,8 @@ public function testInlineIfConditionWarningsWithValidUndefinedVariableNames()
{
$fixtureFile = $this->getFixture('FunctionWithInlineIfConditionFixture.php');
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile);
$phpcsFile->ruleset->setSniffProperty(
'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff',
'validUndefinedVariableNames',
'second'
);
$phpcsFile->ruleset->setSniffProperty(
'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff',
'allowUnusedParametersBeforeUsed',
'true'
);
$this->setSniffProperty($phpcsFile, 'validUndefinedVariableNames', 'second');
$this->setSniffProperty($phpcsFile, 'allowUnusedParametersBeforeUsed', 'true');
$phpcsFile->process();
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
$expectedWarnings = [
Expand Down
12 changes: 2 additions & 10 deletions Tests/VariableAnalysisSniff/UnusedFollowedByRequireTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ public function testUnusedFollowedByRequireDoesNotWarnWhenSet()
{
$fixtureFile = $this->getFixture('UnusedFollowedByRequireFixture.php');
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile);
$phpcsFile->ruleset->setSniffProperty(
'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff',
'allowUnusedVariablesBeforeRequire',
'true'
);
$this->setSniffProperty($phpcsFile, 'allowUnusedVariablesBeforeRequire', 'true');
$phpcsFile->process();
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
$expectedWarnings = [
Expand All @@ -53,11 +49,7 @@ public function testUnusedFollowedByRequireDoesNotBreakOtherThingsWhenSet()
{
$fixtureFile = $this->getFixture('FunctionWithoutParamFixture.php');
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile);
$phpcsFile->ruleset->setSniffProperty(
'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff',
'allowUnusedVariablesBeforeRequire',
'true'
);
$this->setSniffProperty($phpcsFile, 'allowUnusedVariablesBeforeRequire', 'true');
$phpcsFile->process();
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
$expectedWarnings = [
Expand Down
Loading