diff --git a/Tests/BaseTestCase.php b/Tests/BaseTestCase.php index 1bba04b..b33cd89 100644 --- a/Tests/BaseTestCase.php +++ b/Tests/BaseTestCase.php @@ -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 + ); + } + } } diff --git a/Tests/VariableAnalysisSniff/ArrowFunctionTest.php b/Tests/VariableAnalysisSniff/ArrowFunctionTest.php index 471d315..94db882 100644 --- a/Tests/VariableAnalysisSniff/ArrowFunctionTest.php +++ b/Tests/VariableAnalysisSniff/ArrowFunctionTest.php @@ -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 = [ @@ -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 = [ diff --git a/Tests/VariableAnalysisSniff/GlobalScopeTest.php b/Tests/VariableAnalysisSniff/GlobalScopeTest.php index 2ec7506..3cd4d1b 100644 --- a/Tests/VariableAnalysisSniff/GlobalScopeTest.php +++ b/Tests/VariableAnalysisSniff/GlobalScopeTest.php @@ -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 = [ @@ -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 = [ @@ -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 = [ diff --git a/Tests/VariableAnalysisSniff/IfConditionTest.php b/Tests/VariableAnalysisSniff/IfConditionTest.php index e51e080..c3e57c9 100644 --- a/Tests/VariableAnalysisSniff/IfConditionTest.php +++ b/Tests/VariableAnalysisSniff/IfConditionTest.php @@ -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 = [ @@ -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 = [ @@ -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 = [ @@ -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 = [ diff --git a/Tests/VariableAnalysisSniff/UnusedFollowedByRequireTest.php b/Tests/VariableAnalysisSniff/UnusedFollowedByRequireTest.php index 83d4086..2e158cb 100644 --- a/Tests/VariableAnalysisSniff/UnusedFollowedByRequireTest.php +++ b/Tests/VariableAnalysisSniff/UnusedFollowedByRequireTest.php @@ -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 = [ @@ -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 = [ diff --git a/Tests/VariableAnalysisSniff/VariableAnalysisTest.php b/Tests/VariableAnalysisSniff/VariableAnalysisTest.php index 4035c6e..8736677 100644 --- a/Tests/VariableAnalysisSniff/VariableAnalysisTest.php +++ b/Tests/VariableAnalysisSniff/VariableAnalysisTest.php @@ -53,11 +53,7 @@ public function testFunctionWithDefaultParamErrors() { $fixtureFile = $this->getFixture('FunctionWithDefaultParamFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'allowUnusedParametersBeforeUsed', - 'false' - ); + $this->setSniffProperty($phpcsFile, 'allowUnusedParametersBeforeUsed', 'false'); $phpcsFile->process(); $lines = $this->getErrorLineNumbersFromFile($phpcsFile); $expectedErrors = []; @@ -68,11 +64,7 @@ public function testFunctionWithDefaultParamWarnings() { $fixtureFile = $this->getFixture('FunctionWithDefaultParamFixture.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 = [ @@ -125,11 +117,7 @@ public function testFunctionWithForeachWarnings() { $fixtureFile = $this->getFixture('FunctionWithForeachFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'allowUnusedForeachVariables', - 'false' - ); + $this->setSniffProperty($phpcsFile, 'allowUnusedForeachVariables', 'false'); $phpcsFile->process(); $lines = $this->getWarningLineNumbersFromFile($phpcsFile); $expectedWarnings = [ @@ -187,11 +175,7 @@ public function testClassWithMembersWarnings() { $fixtureFile = $this->getFixture('ClassWithMembersFixture.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 = [ @@ -240,11 +224,7 @@ public function testFunctionWithClosureErrors() { $fixtureFile = $this->getFixture('FunctionWithClosureFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'allowUnusedParametersBeforeUsed', - 'false' - ); + $this->setSniffProperty($phpcsFile, 'allowUnusedParametersBeforeUsed', 'false'); $phpcsFile->process(); $lines = $this->getErrorLineNumbersFromFile($phpcsFile); $expectedErrors = [ @@ -258,11 +238,7 @@ public function testFunctionWithClosureWarnings() { $fixtureFile = $this->getFixture('FunctionWithClosureFixture.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 = [ @@ -328,11 +304,7 @@ public function testFunctionWithReferenceWarningsAllowsCustomFunctions() { $fixtureFile = $this->getFixture('FunctionWithReferenceFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'sitePassByRefFunctions', - 'my_reference_function:2,3 another_reference_function:2,...' - ); + $this->setSniffProperty($phpcsFile, 'sitePassByRefFunctions', 'my_reference_function:2,3 another_reference_function:2,...'); $phpcsFile->process(); $lines = $this->getWarningLineNumbersFromFile($phpcsFile); $expectedWarnings = [ @@ -361,11 +333,7 @@ public function testFunctionWithReferenceWarningsAllowsWordPressFunctionsIfSet() { $fixtureFile = $this->getFixture('FunctionWithReferenceFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'allowWordPressPassByRefFunctions', - 'true' - ); + $this->setSniffProperty($phpcsFile, 'allowWordPressPassByRefFunctions', 'true'); $phpcsFile->process(); $lines = $this->getWarningLineNumbersFromFile($phpcsFile); $expectedWarnings = [ @@ -529,11 +497,7 @@ public function testCompactErrors() { $fixtureFile = $this->getFixture('CompactFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'allowUnusedParametersBeforeUsed', - 'false' - ); + $this->setSniffProperty($phpcsFile, 'allowUnusedParametersBeforeUsed', 'false'); $phpcsFile->process(); $lines = $this->getErrorLineNumbersFromFile($phpcsFile); $expectedErrors = []; @@ -544,11 +508,7 @@ public function testCompactWarnings() { $fixtureFile = $this->getFixture('CompactFixture.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 = [ @@ -568,11 +528,7 @@ public function testCompactWarningsHaveCorrectSniffCodes() { $fixtureFile = $this->getFixture('CompactFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'allowUnusedParametersBeforeUsed', - 'false' - ); + $this->setSniffProperty($phpcsFile, 'allowUnusedParametersBeforeUsed', 'false'); $phpcsFile->process(); $warnings = $phpcsFile->getWarnings(); @@ -617,11 +573,7 @@ public function testVariableFunctionCallsCountAsUsage() { $fixtureFile = $this->getFixture('FunctionWithVariableCallFixture.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 = [18]; @@ -690,11 +642,7 @@ public function testUnusedParamsAreReported() { $fixtureFile = $this->getFixture('FunctionWithUnusedParamsFixture.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 = [ @@ -712,11 +660,7 @@ public function testUnusedParamsHaveCorrectSniffCodes() { $fixtureFile = $this->getFixture('FunctionWithUnusedParamsFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'allowUnusedParametersBeforeUsed', - 'false' - ); + $this->setSniffProperty($phpcsFile, 'allowUnusedParametersBeforeUsed', 'false'); $phpcsFile->process(); $warnings = $phpcsFile->getWarnings(); @@ -733,16 +677,8 @@ public function testValidUnusedVariableNamesIgnoresUnusedVariables() { $fixtureFile = $this->getFixture('FunctionWithUnusedParamsFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'allowUnusedParametersBeforeUsed', - 'false' - ); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'validUnusedVariableNames', - 'ignored' - ); + $this->setSniffProperty($phpcsFile, 'allowUnusedParametersBeforeUsed', 'false'); + $this->setSniffProperty($phpcsFile, 'validUnusedVariableNames', 'ignored'); $phpcsFile->process(); $lines = $this->getWarningLineNumbersFromFile($phpcsFile); $expectedWarnings = [ @@ -759,16 +695,8 @@ public function testAllowUnusedFunctionParametersIgnoresUnusedVariables() { $fixtureFile = $this->getFixture('FunctionWithUnusedParamsFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'allowUnusedParametersBeforeUsed', - 'false' - ); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'allowUnusedFunctionParameters', - 'true' - ); + $this->setSniffProperty($phpcsFile, 'allowUnusedParametersBeforeUsed', 'false'); + $this->setSniffProperty($phpcsFile, 'allowUnusedFunctionParameters', 'true'); $phpcsFile->process(); $lines = $this->getWarningLineNumbersFromFile($phpcsFile); $expectedWarnings = []; @@ -779,16 +707,8 @@ public function testAllowUnusedCaughtExceptionsIgnoresUnusedVariablesIfSet() { $fixtureFile = $this->getFixture('FunctionWithUnusedParamsFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'allowUnusedParametersBeforeUsed', - 'false' - ); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'allowUnusedCaughtExceptions', - 'true' - ); + $this->setSniffProperty($phpcsFile, 'allowUnusedParametersBeforeUsed', 'false'); + $this->setSniffProperty($phpcsFile, 'allowUnusedCaughtExceptions', 'true'); $phpcsFile->process(); $lines = $this->getWarningLineNumbersFromFile($phpcsFile); $expectedWarnings = [ @@ -806,16 +726,8 @@ public function testAllowUnusedCaughtExceptionsDoesNotIgnoreUnusedVariablesIfFal { $fixtureFile = $this->getFixture('FunctionWithUnusedParamsFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'allowUnusedParametersBeforeUsed', - 'false' - ); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'allowUnusedCaughtExceptions', - 'false' - ); + $this->setSniffProperty($phpcsFile, 'allowUnusedParametersBeforeUsed', 'false'); + $this->setSniffProperty($phpcsFile, 'allowUnusedCaughtExceptions', 'false'); $phpcsFile->process(); $lines = $this->getWarningLineNumbersFromFile($phpcsFile); $expectedWarnings = [ @@ -834,16 +746,8 @@ public function testIgnoreUnusedRegexpIgnoresUnusedVariables() { $fixtureFile = $this->getFixture('FunctionWithUnusedParamsFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'allowUnusedParametersBeforeUsed', - 'false' - ); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'ignoreUnusedRegexp', - '/^unused_/' - ); + $this->setSniffProperty($phpcsFile, 'allowUnusedParametersBeforeUsed', 'false'); + $this->setSniffProperty($phpcsFile, 'ignoreUnusedRegexp', '/^unused_/'); $phpcsFile->process(); $lines = $this->getWarningLineNumbersFromFile($phpcsFile); $expectedWarnings = [ @@ -877,11 +781,7 @@ public function testValidUndefinedVariableNamesIgnoresVarsInGlobalScope() { $fixtureFile = $this->getFixture('FunctionWithGlobalVarFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'validUndefinedVariableNames', - 'ice_cream' - ); + $this->setSniffProperty($phpcsFile, 'validUndefinedVariableNames', 'ice_cream'); $phpcsFile->process(); $lines = $this->getWarningLineNumbersFromFile($phpcsFile); $expectedWarnings = [ @@ -898,11 +798,7 @@ public function testValidUndefinedVariableNamesIgnoresUndefinedProperties() { $fixtureFile = $this->getFixture('ClassReferenceFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'validUndefinedVariableNames', - 'ignored_property' - ); + $this->setSniffProperty($phpcsFile, 'validUndefinedVariableNames', 'ignored_property'); $phpcsFile->process(); $lines = $this->getWarningLineNumbersFromFile($phpcsFile); $expectedWarnings = [ @@ -920,11 +816,7 @@ public function testValidUndefinedVariableRegexpIgnoresUndefinedProperties() { $fixtureFile = $this->getFixture('ClassReferenceFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'validUndefinedVariableRegexp', - '/^undefined_/' - ); + $this->setSniffProperty($phpcsFile, 'validUndefinedVariableRegexp', '/^undefined_/'); $phpcsFile->process(); $lines = $this->getWarningLineNumbersFromFile($phpcsFile); $expectedWarnings = [ @@ -940,11 +832,7 @@ public function testUnusedArgumentsBeforeUsedArgumentsAreFoundIfFalse() { $fixtureFile = $this->getFixture('UnusedAfterUsedFixture.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 = [ @@ -1012,11 +900,7 @@ public function testUnusedForeachVariablesAreNotIgnoredIfDisabled() { $fixtureFile = $this->getFixture('UnusedForeachFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'allowUnusedForeachVariables', - 'false' - ); + $this->setSniffProperty($phpcsFile, 'allowUnusedForeachVariables', 'false'); $phpcsFile->process(); $lines = $this->getWarningLineNumbersFromFile($phpcsFile); $expectedWarnings = [ @@ -1040,11 +924,7 @@ public function testUnusedForeachVariablesAreIgnoredIfSet() { $fixtureFile = $this->getFixture('UnusedForeachFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'allowUnusedForeachVariables', - 'true' - ); + $this->setSniffProperty($phpcsFile, 'allowUnusedForeachVariables', 'true'); $phpcsFile->process(); $lines = $this->getWarningLineNumbersFromFile($phpcsFile); $expectedWarnings = [ @@ -1134,11 +1014,7 @@ public function testAssignmentByReferenceWithIgnoreUnusedMatch() { $fixtureFile = $this->getFixture('AssignmentByReferenceFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); - $phpcsFile->ruleset->setSniffProperty( - 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', - 'ignoreUnusedRegexp', - '/^varX$/' - ); + $this->setSniffProperty($phpcsFile, 'ignoreUnusedRegexp', '/^varX$/'); $phpcsFile->process(); $lines = $this->getWarningLineNumbersFromFile($phpcsFile); $expectedWarnings = [ diff --git a/Tests/VariableAnalysisSniff/VariableArgumentListTest.php b/Tests/VariableAnalysisSniff/VariableArgumentListTest.php index f96384d..2975715 100644 --- a/Tests/VariableAnalysisSniff/VariableArgumentListTest.php +++ b/Tests/VariableAnalysisSniff/VariableArgumentListTest.php @@ -10,11 +10,7 @@ public function testVariableArgumentList() { $fixtureFile = $this->getFixture('VariableArgumentListFixture.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 = [ @@ -31,11 +27,7 @@ public function testVariableArgumentListWithoutUnusedBeforeUsed() { $fixtureFile = $this->getFixture('VariableArgumentListFixture.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 = [