From df2a845e07fbcab854dff737d47992503100d743 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 6 Jun 2023 23:02:50 +0200 Subject: [PATCH 01/13] Composer: update the PHPUnit Polyfills A PHPUnit 10 compatible version of the PHPUnit Polyfills has been released, so let's start using it. Ref: * https://github.com/Yoast/PHPUnit-Polyfills/releases/tag/2.0.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0a7a3d4f..04f124b9 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "phpcsstandards/phpcsdevcs": "^1.1.6", "php-parallel-lint/php-parallel-lint": "^1.3.2", "php-parallel-lint/php-console-highlighter": "^1.0", - "yoast/phpunit-polyfills": "^1.0.5" + "yoast/phpunit-polyfills": "^1.0.5 || ^2.0.0" }, "minimum-stability": "dev", "prefer-stable": true, From ce14e92e46b3b9611b2cfac7d0e7ac9d755acbbe Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 6 Jun 2023 23:22:29 +0200 Subject: [PATCH 02/13] Tests/PolyfilledTestCase: make compatible with PHPUnit Polyfills 2.x As the available traits are different between the 1.x and 2.x versions of the PHPUnit Polyfills, two different class definitions are needed. This change uses the available PHPUnit Polyfills version number to load the correct class. --- Tests/PolyfilledTestCase.php | 113 ++++++++++++++++++++++++----------- 1 file changed, 79 insertions(+), 34 deletions(-) diff --git a/Tests/PolyfilledTestCase.php b/Tests/PolyfilledTestCase.php index 58af5e3d..eea44978 100644 --- a/Tests/PolyfilledTestCase.php +++ b/Tests/PolyfilledTestCase.php @@ -6,20 +6,27 @@ * @copyright 2019-2020 PHPCSUtils Contributors * @license https://opensource.org/licenses/LGPL-3.0 LGPL3 * @link https://github.com/PHPCSStandards/PHPCSUtils + * + * @phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses + * @phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound */ namespace PHPCSUtils\Tests; use PHPCSUtils\Tests\AssertAttributeSame; use PHPCSUtils\TestUtils\UtilityMethodTestCase; +use Yoast\PHPUnitPolyfills\Autoload; use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource; use Yoast\PHPUnitPolyfills\Polyfills\AssertEqualsSpecializations; use Yoast\PHPUnitPolyfills\Polyfills\AssertFileDirectory; use Yoast\PHPUnitPolyfills\Polyfills\AssertFileEqualsSpecializations; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIgnoringLineEndings; use Yoast\PHPUnitPolyfills\Polyfills\AssertionRenames; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsList; use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; use Yoast\PHPUnitPolyfills\Polyfills\AssertNumericType; use Yoast\PHPUnitPolyfills\Polyfills\AssertObjectEquals; +use Yoast\PHPUnitPolyfills\Polyfills\AssertObjectProperty; use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; use Yoast\PHPUnitPolyfills\Polyfills\EqualToSpecializations; use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; @@ -27,39 +34,77 @@ use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionObject; use Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException; -/** - * Abstract utilty method base test case which includes all available polyfills. - * - * This test case includes all polyfills from the PHPUnit Polyfill library to make them - * available to the tests. - * - * Generally speaking, this testcase only needs to be used when the concrete test class will - * use functionality which has changed in PHPUnit cross-version. - * In all other cases, the `UtilityMethodTestCase` can be extended directly. - * - * {@internal The list of included polyfill traits should be reviewed after each new - * release of the PHPUnit Polyfill library.} - * - * @since 1.0.0 - */ -abstract class PolyfilledTestCase extends UtilityMethodTestCase -{ - // PHPCSUtils native helper. - use AssertAttributeSame; +if (\version_compare(Autoload::VERSION, '2.0.0', '>=')) { + /** + * Abstract utility method base test case which includes all available polyfills (PHPUnit Polyfills 2.x compaible). + * + * This test case includes all polyfills from the PHPUnit Polyfill library to make them + * available to the tests. + * + * Generally speaking, this testcase only needs to be used when the concrete test class will + * use functionality which has changed in PHPUnit cross-version. + * In all other cases, the `UtilityMethodTestCase` can be extended directly. + * + * {@internal The list of included polyfill traits should be reviewed after each new + * release of the PHPUnit Polyfill library.} + * + * @since 1.0.0 + */ + abstract class PolyfilledTestCase extends UtilityMethodTestCase + { + // PHPCSUtils native helper. + use AssertAttributeSame; + + // PHPUnit Polyfills. + use AssertClosedResource; + use AssertEqualsSpecializations; + use AssertFileEqualsSpecializations; + use AssertIgnoringLineEndings; + use AssertionRenames; + use AssertIsList; + use AssertIsType; + use AssertObjectEquals; + use AssertObjectProperty; + use AssertStringContains; + use EqualToSpecializations; + use ExpectExceptionMessageMatches; + use ExpectExceptionObject; + } +} else { + /** + * Abstract utility method base test case which includes all available polyfills (PHPUnit Polyfills 1.x compaible). + * + * This test case includes all polyfills from the PHPUnit Polyfill library to make them + * available to the tests. + * + * Generally speaking, this testcase only needs to be used when the concrete test class will + * use functionality which has changed in PHPUnit cross-version. + * In all other cases, the `UtilityMethodTestCase` can be extended directly. + * + * {@internal The list of included polyfill traits should be reviewed after each new + * release of the PHPUnit Polyfill library.} + * + * @since 1.0.0 + */ + abstract class PolyfilledTestCase extends UtilityMethodTestCase + { + // PHPCSUtils native helper. + use AssertAttributeSame; - // PHPUnit Polyfills. - use AssertClosedResource; - use AssertEqualsSpecializations; - use AssertFileDirectory; - use AssertFileEqualsSpecializations; - use AssertionRenames; - use AssertIsType; - use AssertNumericType; - use AssertObjectEquals; - use AssertStringContains; - use EqualToSpecializations; - use ExpectException; - use ExpectExceptionMessageMatches; - use ExpectExceptionObject; - use ExpectPHPException; + // PHPUnit Polyfills. + use AssertClosedResource; + use AssertEqualsSpecializations; + use AssertFileDirectory; + use AssertFileEqualsSpecializations; + use AssertionRenames; + use AssertIsType; + use AssertNumericType; + use AssertObjectEquals; + use AssertStringContains; + use EqualToSpecializations; + use ExpectException; + use ExpectExceptionMessageMatches; + use ExpectExceptionObject; + use ExpectPHPException; + } } From 80c372379f95d93ff1fdb8698bb983eccb36e911 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 6 Jun 2023 23:22:53 +0200 Subject: [PATCH 03/13] Tests/ConfigDataTest: switch to the PHPUnit Polyfills TestCase --- Tests/BackCompat/Helper/ConfigDataTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Tests/BackCompat/Helper/ConfigDataTest.php b/Tests/BackCompat/Helper/ConfigDataTest.php index 9c3b1fcd..316e3ff4 100644 --- a/Tests/BackCompat/Helper/ConfigDataTest.php +++ b/Tests/BackCompat/Helper/ConfigDataTest.php @@ -12,8 +12,7 @@ use PHP_CodeSniffer\Config; use PHPCSUtils\BackCompat\Helper; -use PHPUnit\Framework\TestCase; -use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * Test class. @@ -27,7 +26,6 @@ */ final class ConfigDataTest extends TestCase { - use ExpectException; /** * Test the getConfigData() and setConfigData() method when used in a cross-version compatible manner. From 47a75495f498a8538b753a519b527a24faaf302b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 6 Jun 2023 23:24:29 +0200 Subject: [PATCH 04/13] Tests: make dataproviders `static` As of PHPUnit 10, data providers are (again) expected to be `static` methods. This updates the test suite to respect that. Includes removing the use of `$this` from select data providers. Refs: * https://github.com/sebastianbergmann/phpunit/commit/9caafe2d49b33a21f87db248a8ad6ca7c7bdac09 * sebastianbergmann/phpunit 5100 --- .../AbstractArrayDeclaration/GetActualArrayKeyTest.php | 2 +- Tests/BackCompat/BCFile/FindExtendedClassNameTest.php | 2 +- .../BCFile/FindImplementedInterfaceNamesTest.php | 2 +- Tests/BackCompat/BCFile/GetClassPropertiesTest.php | 4 ++-- Tests/BackCompat/BCFile/GetDeclarationNameJSTest.php | 4 ++-- Tests/BackCompat/BCFile/GetDeclarationNameTest.php | 4 ++-- Tests/BackCompat/BCFile/GetMemberPropertiesTest.php | 4 ++-- Tests/BackCompat/BCFile/GetMethodParametersTest.php | 6 +++--- Tests/BackCompat/BCFile/GetMethodPropertiesTest.php | 2 +- Tests/BackCompat/BCFile/GetTokensAsStringTest.php | 4 ++-- Tests/BackCompat/BCFile/IsReferenceTest.php | 2 +- Tests/BackCompat/BCTokens/UnchangedTokenArraysTest.php | 4 ++-- .../SpacesFixer/TrailingCommentHandlingNewlineTest.php | 2 +- Tests/Fixers/SpacesFixer/TrailingCommentHandlingTest.php | 2 +- Tests/Internal/Cache/GetClearTest.php | 2 +- Tests/Internal/Cache/SetTest.php | 4 ++-- Tests/Internal/IsShortArrayOrList/ConstructorTest.php | 4 ++-- Tests/Internal/IsShortArrayOrList/IsInForeachTest.php | 6 +++--- .../IsShortArrayOrList/IsShortArrayBracketBC1Test.php | 2 +- .../IsShortArrayOrList/IsShortArrayBracketBC2Test.php | 2 +- .../IsShortArrayOrList/IsShortArrayBracketBC3Test.php | 2 +- .../IsShortArrayOrList/IsShortArrayBracketBC4Test.php | 2 +- .../IsShortArrayOrList/IsShortArrayBracketBC5Test.php | 2 +- .../IsShortArrayOrList/IsShortArrayBracketBC6Test.php | 2 +- .../IsShortArrayOrList/IsShortArrayOrListTest.php | 2 +- Tests/Internal/IsShortArrayOrList/IsSquareBracketTest.php | 2 +- Tests/Internal/IsShortArrayOrList/SolveTest.php | 2 +- Tests/Internal/IsShortArrayOrList/WalkInsideTest.php | 6 +++--- Tests/Internal/IsShortArrayOrList/WalkOutsideTest.php | 4 ++-- .../Internal/IsShortArrayOrListWithCache/CachingTest.php | 2 +- .../IsShortArrayOrListWithCache/EntryPointsTest.php | 2 +- .../IsShortArrayOrListWithCache/IsValidStackPtrTest.php | 4 ++-- .../Internal/IsShortArrayOrListWithCache/ProcessTest.php | 2 +- Tests/Internal/NoFileCache/GetClearTest.php | 2 +- Tests/Internal/NoFileCache/SetTest.php | 4 ++-- .../UtilityMethodTestCase/GetTargetTokenTest.php | 2 +- Tests/Tokens/Collections/PropertyBasedTokenArraysTest.php | 2 +- Tests/Tokens/TokenHelper/TokenExistsTest.php | 2 +- Tests/Utils/Arrays/GetDoubleArrowPtrTest.php | 2 +- Tests/Utils/Arrays/GetOpenCloseTest.php | 4 ++-- Tests/Utils/Conditions/GetConditionTest.php | 4 ++-- Tests/Utils/Context/InAttributeTest.php | 4 ++-- Tests/Utils/Context/InEmptyTest.php | 2 +- Tests/Utils/Context/InForConditionTest.php | 4 ++-- Tests/Utils/Context/InForeachConditionTest.php | 4 ++-- Tests/Utils/Context/InIssetTest.php | 2 +- Tests/Utils/Context/InUnsetTest.php | 2 +- Tests/Utils/ControlStructures/GetCaughtExceptionsTest.php | 2 +- Tests/Utils/ControlStructures/HasBodyTest.php | 2 +- Tests/Utils/ControlStructures/IsElseIfTest.php | 2 +- .../FunctionDeclarations/IsMagicFunctionNameTest.php | 4 ++-- .../Utils/FunctionDeclarations/IsMagicMethodNameTest.php | 4 ++-- .../IsPHPDoubleUnderscoreMethodNameTest.php | 4 ++-- Tests/Utils/FunctionDeclarations/SpecialFunctionsTest.php | 2 +- Tests/Utils/GetTokensAsString/GetTokensAsStringTest.php | 2 +- Tests/Utils/Lists/GetAssignmentsTest.php | 4 ++-- Tests/Utils/Lists/GetOpenCloseTest.php | 4 ++-- Tests/Utils/MessageHelper/AddMessageTest.php | 4 ++-- Tests/Utils/MessageHelper/ShowEscapeCharsTest.php | 2 +- Tests/Utils/MessageHelper/StringToErrorcodeTest.php | 4 ++-- Tests/Utils/Namespaces/DetermineNamespaceTest.php | 2 +- Tests/Utils/Namespaces/GetDeclaredNameTest.php | 2 +- Tests/Utils/Namespaces/NamespaceTypeTest.php | 2 +- Tests/Utils/NamingConventions/IsEqualTest.php | 2 +- .../Utils/NamingConventions/IsValidIdentifierNameTest.php | 2 +- Tests/Utils/Numbers/GetCompleteNumberTest.php | 2 +- Tests/Utils/Numbers/GetDecimalValueTest.php | 4 ++-- .../ObjectDeclarations/FindExtendedClassNameDiffTest.php | 2 +- .../ObjectDeclarations/FindExtendedInterfaceNamesTest.php | 2 +- .../FindImplementedInterfaceNamesDiffTest.php | 2 +- .../ObjectDeclarations/GetClassPropertiesDiffTest.php | 2 +- Tests/Utils/ObjectDeclarations/GetNameDiffTest.php | 4 ++-- Tests/Utils/Operators/IsShortTernaryTest.php | 2 +- Tests/Utils/Operators/IsUnaryPlusMinusJSTest.php | 2 +- Tests/Utils/Operators/IsUnaryPlusMinusTest.php | 2 +- Tests/Utils/Operators/IsUnaryPlusMinusTestCase.php | 2 +- Tests/Utils/Orthography/FirstCharTest.php | 2 +- Tests/Utils/Orthography/IsLastCharPunctuationTest.php | 2 +- Tests/Utils/Parentheses/ParenthesesTest.php | 8 ++++---- Tests/Utils/PassedParameters/GetParameterCountTest.php | 2 +- .../Utils/PassedParameters/GetParameterFromStackTest.php | 8 ++++---- Tests/Utils/PassedParameters/GetParametersNamedTest.php | 2 +- .../GetParametersSkipShortArrayCheckTest.php | 2 +- Tests/Utils/PassedParameters/GetParametersTest.php | 4 ++-- .../Utils/PassedParameters/GetParametersWithLimitTest.php | 4 ++-- Tests/Utils/PassedParameters/HasParametersTest.php | 4 ++-- Tests/Utils/Scopes/IsOOConstantTest.php | 2 +- Tests/Utils/Scopes/IsOOMethodTest.php | 2 +- Tests/Utils/Scopes/IsOOPropertyTest.php | 2 +- Tests/Utils/TextStrings/GetCompleteTextStringTest.php | 4 ++-- .../Utils/TextStrings/GetEndOfCompleteTextStringTest.php | 2 +- Tests/Utils/TextStrings/StripQuotesTest.php | 2 +- .../UseStatements/SplitAndMergeImportUseStatementTest.php | 2 +- Tests/Utils/UseStatements/SplitImportUseStatementTest.php | 4 ++-- Tests/Utils/UseStatements/UseTypeTest.php | 2 +- Tests/Utils/Variables/GetMemberPropertiesDiffTest.php | 4 ++-- Tests/Utils/Variables/GetMemberPropertiesTest.php | 2 +- Tests/Utils/Variables/IsPHPReservedVarNameTest.php | 4 ++-- Tests/Utils/Variables/IsSuperglobalTest.php | 6 +++--- Tests/Xtra/Tokens/TokenNameTest.php | 2 +- 100 files changed, 146 insertions(+), 146 deletions(-) diff --git a/Tests/AbstractSniffs/AbstractArrayDeclaration/GetActualArrayKeyTest.php b/Tests/AbstractSniffs/AbstractArrayDeclaration/GetActualArrayKeyTest.php index ed3b2fe4..dd3e3fed 100644 --- a/Tests/AbstractSniffs/AbstractArrayDeclaration/GetActualArrayKeyTest.php +++ b/Tests/AbstractSniffs/AbstractArrayDeclaration/GetActualArrayKeyTest.php @@ -71,7 +71,7 @@ public function testGetActualArrayKey($testMarker, $expected, $expectedFrom) * * @return array */ - public function dataGetActualArrayKey() + public static function dataGetActualArrayKey() { return [ 'unsupported-key-types' => [ diff --git a/Tests/BackCompat/BCFile/FindExtendedClassNameTest.php b/Tests/BackCompat/BCFile/FindExtendedClassNameTest.php index fb794dd5..5fc5c98f 100644 --- a/Tests/BackCompat/BCFile/FindExtendedClassNameTest.php +++ b/Tests/BackCompat/BCFile/FindExtendedClassNameTest.php @@ -102,7 +102,7 @@ public function testFindExtendedClassName($identifier, $expected) * * @return array */ - public function dataExtendedClass() + public static function dataExtendedClass() { return [ [ diff --git a/Tests/BackCompat/BCFile/FindImplementedInterfaceNamesTest.php b/Tests/BackCompat/BCFile/FindImplementedInterfaceNamesTest.php index ef44e19f..ef70910e 100644 --- a/Tests/BackCompat/BCFile/FindImplementedInterfaceNamesTest.php +++ b/Tests/BackCompat/BCFile/FindImplementedInterfaceNamesTest.php @@ -100,7 +100,7 @@ public function testFindImplementedInterfaceNames($identifier, $expected) * * @return array */ - public function dataImplementedInterface() + public static function dataImplementedInterface() { return [ [ diff --git a/Tests/BackCompat/BCFile/GetClassPropertiesTest.php b/Tests/BackCompat/BCFile/GetClassPropertiesTest.php index 9121c5b4..9ccfef3a 100644 --- a/Tests/BackCompat/BCFile/GetClassPropertiesTest.php +++ b/Tests/BackCompat/BCFile/GetClassPropertiesTest.php @@ -61,7 +61,7 @@ public function testNotAClassException($testMarker, $tokenType) * * @return array */ - public function dataNotAClassException() + public static function dataNotAClassException() { return [ 'interface' => [ @@ -106,7 +106,7 @@ public function testGetClassProperties($testMarker, $expected) * * @return array */ - public function dataGetClassProperties() + public static function dataGetClassProperties() { return [ 'no-properties' => [ diff --git a/Tests/BackCompat/BCFile/GetDeclarationNameJSTest.php b/Tests/BackCompat/BCFile/GetDeclarationNameJSTest.php index b34e2b70..eb58af1a 100644 --- a/Tests/BackCompat/BCFile/GetDeclarationNameJSTest.php +++ b/Tests/BackCompat/BCFile/GetDeclarationNameJSTest.php @@ -69,7 +69,7 @@ public function testGetDeclarationNameNull($testMarker, $targetType) * * @return array */ - public function dataGetDeclarationNameNull() + public static function dataGetDeclarationNameNull() { return [ 'closure' => [ @@ -108,7 +108,7 @@ public function testGetDeclarationName($testMarker, $expected, $targetType = nul * * @return array */ - public function dataGetDeclarationName() + public static function dataGetDeclarationName() { return [ 'function' => [ diff --git a/Tests/BackCompat/BCFile/GetDeclarationNameTest.php b/Tests/BackCompat/BCFile/GetDeclarationNameTest.php index 11de6a2c..f4fbe64c 100644 --- a/Tests/BackCompat/BCFile/GetDeclarationNameTest.php +++ b/Tests/BackCompat/BCFile/GetDeclarationNameTest.php @@ -62,7 +62,7 @@ public function testGetDeclarationNameNull($testMarker, $targetType) * * @return array */ - public function dataGetDeclarationNameNull() + public static function dataGetDeclarationNameNull() { return [ 'closure' => [ @@ -121,7 +121,7 @@ public function testGetDeclarationName($testMarker, $expected, $targetType = nul * * @return array */ - public function dataGetDeclarationName() + public static function dataGetDeclarationName() { return [ 'function' => [ diff --git a/Tests/BackCompat/BCFile/GetMemberPropertiesTest.php b/Tests/BackCompat/BCFile/GetMemberPropertiesTest.php index 1101384d..e47ca18b 100644 --- a/Tests/BackCompat/BCFile/GetMemberPropertiesTest.php +++ b/Tests/BackCompat/BCFile/GetMemberPropertiesTest.php @@ -80,7 +80,7 @@ public function testGetMemberProperties($identifier, $expected) * * @return array */ - public function dataGetMemberProperties() + public static function dataGetMemberProperties() { $php8Names = parent::usesPhp8NameTokens(); @@ -1073,7 +1073,7 @@ public function testNotClassPropertyException($identifier) * * @return array */ - public function dataNotClassProperty() + public static function dataNotClassProperty() { return [ ['/* testMethodParam */'], diff --git a/Tests/BackCompat/BCFile/GetMethodParametersTest.php b/Tests/BackCompat/BCFile/GetMethodParametersTest.php index 9ea1faa3..4aca57bf 100644 --- a/Tests/BackCompat/BCFile/GetMethodParametersTest.php +++ b/Tests/BackCompat/BCFile/GetMethodParametersTest.php @@ -63,7 +63,7 @@ public function testUnexpectedTokenException($commentString, $targetTokenType) * * @return array */ - public function dataUnexpectedTokenException() + public static function dataUnexpectedTokenException() { return [ 'interface' => [ @@ -105,7 +105,7 @@ public function testInvalidUse($identifier) * * @return array */ - public function dataInvalidUse() + public static function dataInvalidUse() { return [ 'ImportUse' => ['/* testImportUse */'], @@ -141,7 +141,7 @@ public function testNoParams($commentString, $targetTokenType = [T_FUNCTION, T_C * * @return array */ - public function dataNoParams() + public static function dataNoParams() { return [ 'FunctionNoParams' => ['/* testFunctionNoParams */'], diff --git a/Tests/BackCompat/BCFile/GetMethodPropertiesTest.php b/Tests/BackCompat/BCFile/GetMethodPropertiesTest.php index ee20479d..159d24ef 100644 --- a/Tests/BackCompat/BCFile/GetMethodPropertiesTest.php +++ b/Tests/BackCompat/BCFile/GetMethodPropertiesTest.php @@ -60,7 +60,7 @@ public function testNotAFunctionException($commentString, $targetTokenType) * * @return array */ - public function dataNotAFunctionException() + public static function dataNotAFunctionException() { return [ 'return' => [ diff --git a/Tests/BackCompat/BCFile/GetTokensAsStringTest.php b/Tests/BackCompat/BCFile/GetTokensAsStringTest.php index b3df5437..c1856ca9 100644 --- a/Tests/BackCompat/BCFile/GetTokensAsStringTest.php +++ b/Tests/BackCompat/BCFile/GetTokensAsStringTest.php @@ -116,7 +116,7 @@ public function testGetTokensAsString($testMarker, $startTokenType, $length, $ex * * @return array */ - public function dataGetTokensAsString() + public static function dataGetTokensAsString() { $php8Names = parent::usesPhp8NameTokens(); @@ -289,7 +289,7 @@ public function testGetOrigContent($testMarker, $startTokenType, $length, $expec * * @return array */ - public function dataGetOrigContent() + public static function dataGetOrigContent() { return [ 'use-with-comments' => [ diff --git a/Tests/BackCompat/BCFile/IsReferenceTest.php b/Tests/BackCompat/BCFile/IsReferenceTest.php index 2bb169df..6af58103 100644 --- a/Tests/BackCompat/BCFile/IsReferenceTest.php +++ b/Tests/BackCompat/BCFile/IsReferenceTest.php @@ -85,7 +85,7 @@ public function testIsReference($identifier, $expected) * * @return array */ - public function dataIsReference() + public static function dataIsReference() { return [ 'issue-1971-list-first-in-file' => [ diff --git a/Tests/BackCompat/BCTokens/UnchangedTokenArraysTest.php b/Tests/BackCompat/BCTokens/UnchangedTokenArraysTest.php index d7199a74..94255fad 100644 --- a/Tests/BackCompat/BCTokens/UnchangedTokenArraysTest.php +++ b/Tests/BackCompat/BCTokens/UnchangedTokenArraysTest.php @@ -469,7 +469,7 @@ public function testUnchangedTokenArrays($name, $expected) * * @return array */ - public function dataUnchangedTokenArrays() + public static function dataUnchangedTokenArrays() { $phpunitProp = [ 'backupGlobals' => true, @@ -484,7 +484,7 @@ public function dataUnchangedTokenArrays() ]; $data = []; - $tokenArrays = \get_object_vars($this); + $tokenArrays = \get_class_vars(__CLASS__); foreach ($tokenArrays as $name => $expected) { if (isset($phpunitProp[$name])) { continue; diff --git a/Tests/Fixers/SpacesFixer/TrailingCommentHandlingNewlineTest.php b/Tests/Fixers/SpacesFixer/TrailingCommentHandlingNewlineTest.php index 5bf75275..954393b6 100644 --- a/Tests/Fixers/SpacesFixer/TrailingCommentHandlingNewlineTest.php +++ b/Tests/Fixers/SpacesFixer/TrailingCommentHandlingNewlineTest.php @@ -156,7 +156,7 @@ public function testNoFixesMade() * * @return array */ - public function dataCheckAndFixNoError() + public static function dataCheckAndFixNoError() { return [ 'correct-newline-before' => [ diff --git a/Tests/Fixers/SpacesFixer/TrailingCommentHandlingTest.php b/Tests/Fixers/SpacesFixer/TrailingCommentHandlingTest.php index 5c771d57..037a689c 100644 --- a/Tests/Fixers/SpacesFixer/TrailingCommentHandlingTest.php +++ b/Tests/Fixers/SpacesFixer/TrailingCommentHandlingTest.php @@ -182,7 +182,7 @@ public function testFixesMade() * * @return array */ - public function dataCheckAndFix() + public static function dataCheckAndFix() { return [ 'trailing-comment-not-fixable' => [ diff --git a/Tests/Internal/Cache/GetClearTest.php b/Tests/Internal/Cache/GetClearTest.php index 420394a1..b0c8d352 100644 --- a/Tests/Internal/Cache/GetClearTest.php +++ b/Tests/Internal/Cache/GetClearTest.php @@ -282,7 +282,7 @@ public function testGetWillRetrievedPreviouslySetValue($id, $expected) * * @return array */ - public function dataEveryTypeOfInput() + public static function dataEveryTypeOfInput() { $allTypes = TypeProviderHelper::getAll(); $data = []; diff --git a/Tests/Internal/Cache/SetTest.php b/Tests/Internal/Cache/SetTest.php index b82e67ec..9ad746ba 100644 --- a/Tests/Internal/Cache/SetTest.php +++ b/Tests/Internal/Cache/SetTest.php @@ -115,7 +115,7 @@ public function testSetAcceptsEveryTypeOfInput($input) * * @return array */ - public function dataEveryTypeOfInput() + public static function dataEveryTypeOfInput() { return TypeProviderHelper::getAll(); } @@ -157,7 +157,7 @@ public function testSetAcceptsIntAndStringIdKeys($id) * * @return array */ - public function dataSetAcceptsIntAndStringIdKeys() + public static function dataSetAcceptsIntAndStringIdKeys() { return [ 'ID: int zero' => [ diff --git a/Tests/Internal/IsShortArrayOrList/ConstructorTest.php b/Tests/Internal/IsShortArrayOrList/ConstructorTest.php index 612f88f8..306ee6da 100644 --- a/Tests/Internal/IsShortArrayOrList/ConstructorTest.php +++ b/Tests/Internal/IsShortArrayOrList/ConstructorTest.php @@ -64,7 +64,7 @@ public function testNotOpenBracket($testMarker, $targetType) * * @return array */ - public function dataNotOpenBracket() + public static function dataNotOpenBracket() { return [ 'long-array' => [ @@ -115,7 +115,7 @@ public function testSupportedBrackets($testMarker, $targetType) * * @return array */ - public function dataSupportedBrackets() + public static function dataSupportedBrackets() { return [ 'short-array-open-bracket' => [ diff --git a/Tests/Internal/IsShortArrayOrList/IsInForeachTest.php b/Tests/Internal/IsShortArrayOrList/IsInForeachTest.php index d28e9117..905603f5 100644 --- a/Tests/Internal/IsShortArrayOrList/IsInForeachTest.php +++ b/Tests/Internal/IsShortArrayOrList/IsInForeachTest.php @@ -69,7 +69,7 @@ public function testIsInForeach($testMarker, $expected) * * @return array */ - public function dataIsInForeachResolved() + public static function dataIsInForeachResolved() { return [ 'resolved: short array in foreach' => [ @@ -114,7 +114,7 @@ public function dataIsInForeachResolved() * * @return array */ - public function dataIsInForeachNestedResolvedViaOuter() + public static function dataIsInForeachNestedResolvedViaOuter() { return [ 'resolved-on-outer: short array in foreach nested at start' => [ @@ -159,7 +159,7 @@ public function dataIsInForeachNestedResolvedViaOuter() * * @return array */ - public function dataIsInForeachUndetermined() + public static function dataIsInForeachUndetermined() { return [ 'undetermined: short array in function call in foreach' => [ diff --git a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC1Test.php b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC1Test.php index 48856cf0..e2801e2b 100644 --- a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC1Test.php +++ b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC1Test.php @@ -52,7 +52,7 @@ public function testIsShortArrayBracket($testMarker, $expected) * * @return array */ - public function dataIsShortArrayBracket() + public static function dataIsShortArrayBracket() { return [ 'issue-1971-list-first-in-file' => [ diff --git a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC2Test.php b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC2Test.php index 2c999392..1d5753da 100644 --- a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC2Test.php +++ b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC2Test.php @@ -52,7 +52,7 @@ public function testIsShortArrayBracket($testMarker, $expected) * * @return array */ - public function dataIsShortArrayBracket() + public static function dataIsShortArrayBracket() { return [ // Make sure the utility method does not throw false positives for a short array at the start of a file. diff --git a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC3Test.php b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC3Test.php index 342e296c..6ca30c68 100644 --- a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC3Test.php +++ b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC3Test.php @@ -52,7 +52,7 @@ public function testIsShortArrayBracket($testMarker, $expected) * * @return array */ - public function dataIsShortArrayBracket() + public static function dataIsShortArrayBracket() { return [ 'issue-1971-short-array-first-in-file' => [ diff --git a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC4Test.php b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC4Test.php index 20ca21e8..7f2a45a5 100644 --- a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC4Test.php +++ b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC4Test.php @@ -52,7 +52,7 @@ public function testIsShortArrayBracket($testMarker, $expected) * * @return array */ - public function dataIsShortArrayBracket() + public static function dataIsShortArrayBracket() { return [ 'issue-1971-short-list-first-in-file' => [ diff --git a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC5Test.php b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC5Test.php index 01a164e0..f26f8507 100644 --- a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC5Test.php +++ b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC5Test.php @@ -52,7 +52,7 @@ public function testIsShortArrayBracket($testMarker, $expected) * * @return array */ - public function dataIsShortArrayBracket() + public static function dataIsShortArrayBracket() { return [ 'issue-1971-short-list-first-in-file' => [ diff --git a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC6Test.php b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC6Test.php index d703fbf8..dc267a62 100644 --- a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC6Test.php +++ b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC6Test.php @@ -52,7 +52,7 @@ public function testIsShortArrayBracket($testMarker, $expected) * * @return array */ - public function dataIsShortArrayBracket() + public static function dataIsShortArrayBracket() { return [ 'issue-1971-short-list-first-in-file' => [ diff --git a/Tests/Internal/IsShortArrayOrList/IsShortArrayOrListTest.php b/Tests/Internal/IsShortArrayOrList/IsShortArrayOrListTest.php index f7cc7019..aa221281 100644 --- a/Tests/Internal/IsShortArrayOrList/IsShortArrayOrListTest.php +++ b/Tests/Internal/IsShortArrayOrList/IsShortArrayOrListTest.php @@ -54,7 +54,7 @@ public function testIsShortArrayOrList($testMarker, $expected) * * @return array */ - public function dataIsShortArrayOrList() + public static function dataIsShortArrayOrList() { return [ 'short-array-comparison-no-assignment' => [ diff --git a/Tests/Internal/IsShortArrayOrList/IsSquareBracketTest.php b/Tests/Internal/IsShortArrayOrList/IsSquareBracketTest.php index cd10578d..6c36029a 100644 --- a/Tests/Internal/IsShortArrayOrList/IsSquareBracketTest.php +++ b/Tests/Internal/IsShortArrayOrList/IsSquareBracketTest.php @@ -63,7 +63,7 @@ public function testSquareBrackets($testMarker) * * @return array */ - public function dataSquareBrackets() + public static function dataSquareBrackets() { return [ 'array-assignment-no-key' => [ diff --git a/Tests/Internal/IsShortArrayOrList/SolveTest.php b/Tests/Internal/IsShortArrayOrList/SolveTest.php index b51f8d4a..1e136ed0 100644 --- a/Tests/Internal/IsShortArrayOrList/SolveTest.php +++ b/Tests/Internal/IsShortArrayOrList/SolveTest.php @@ -50,7 +50,7 @@ public function testSolve($testMarker, $expected) * * @return array */ - public function dataSolve() + public static function dataSolve() { return [ 'real square brackets' => [ diff --git a/Tests/Internal/IsShortArrayOrList/WalkInsideTest.php b/Tests/Internal/IsShortArrayOrList/WalkInsideTest.php index d034bc6d..8a23c0cd 100644 --- a/Tests/Internal/IsShortArrayOrList/WalkInsideTest.php +++ b/Tests/Internal/IsShortArrayOrList/WalkInsideTest.php @@ -49,7 +49,7 @@ public function testWalkInsideUndetermined($testMarker, $expected) * * @return array */ - public function dataWalkInsideUndetermined() + public static function dataWalkInsideUndetermined() { return [ 'nested-short-array-empty' => [ @@ -134,7 +134,7 @@ public function testWalkInsideResolved($testMarker, $expected) * * @return array */ - public function dataWalkInsideResolved() + public static function dataWalkInsideResolved() { return [ 'nested-short-array-no-vars-or-nested-null' => [ @@ -276,7 +276,7 @@ public function testRecursionLimit($testMarker, $expected) * * @return array */ - public function dataRecursionLimit() + public static function dataRecursionLimit() { return [ 'nested-short-array-with-nested-short-array-recursion-4' => [ diff --git a/Tests/Internal/IsShortArrayOrList/WalkOutsideTest.php b/Tests/Internal/IsShortArrayOrList/WalkOutsideTest.php index 984a2bea..820eb0a2 100644 --- a/Tests/Internal/IsShortArrayOrList/WalkOutsideTest.php +++ b/Tests/Internal/IsShortArrayOrList/WalkOutsideTest.php @@ -52,7 +52,7 @@ public function testWalkOutside($testMarker, $expected) * * @return array */ - public function dataWalkOutside() + public static function dataWalkOutside() { return [ 'nested-short-array-start-of-file' => [ @@ -188,7 +188,7 @@ public function testReuseCacheFromAdjacent($testMarker, $adjacent1, $adjacent2, * * @return array */ - public function dataReuseCacheFromAdjacent() + public static function dataReuseCacheFromAdjacent() { return [ 'nested-short-array' => [ diff --git a/Tests/Internal/IsShortArrayOrListWithCache/CachingTest.php b/Tests/Internal/IsShortArrayOrListWithCache/CachingTest.php index 3fd0f45c..672aa43c 100644 --- a/Tests/Internal/IsShortArrayOrListWithCache/CachingTest.php +++ b/Tests/Internal/IsShortArrayOrListWithCache/CachingTest.php @@ -69,7 +69,7 @@ public function testResultIsCached($testMarker, $expected) * * @return array */ - public function dataResultIsCached() + public static function dataResultIsCached() { return [ 'short array' => [ diff --git a/Tests/Internal/IsShortArrayOrListWithCache/EntryPointsTest.php b/Tests/Internal/IsShortArrayOrListWithCache/EntryPointsTest.php index 0bbee83f..a50ce9b0 100644 --- a/Tests/Internal/IsShortArrayOrListWithCache/EntryPointsTest.php +++ b/Tests/Internal/IsShortArrayOrListWithCache/EntryPointsTest.php @@ -136,7 +136,7 @@ public function testGetTypeInternal($testMarker, $targetType) * * @return array */ - public function dataEntryPoints() + public static function dataEntryPoints() { return [ 'not a square bracket' => [ diff --git a/Tests/Internal/IsShortArrayOrListWithCache/IsValidStackPtrTest.php b/Tests/Internal/IsShortArrayOrListWithCache/IsValidStackPtrTest.php index eadbbdd2..d91560b0 100644 --- a/Tests/Internal/IsShortArrayOrListWithCache/IsValidStackPtrTest.php +++ b/Tests/Internal/IsShortArrayOrListWithCache/IsValidStackPtrTest.php @@ -68,7 +68,7 @@ public function testNotBracket($testMarker, $targetType) * * @return array */ - public function dataNotBracket() + public static function dataNotBracket() { return [ 'long-array' => [ @@ -109,7 +109,7 @@ public function testValidBracket($testMarker, $targetType) * * @return array */ - public function dataValidBracket() + public static function dataValidBracket() { return [ 'open square bracket' => [ diff --git a/Tests/Internal/IsShortArrayOrListWithCache/ProcessTest.php b/Tests/Internal/IsShortArrayOrListWithCache/ProcessTest.php index 7a651867..39519c67 100644 --- a/Tests/Internal/IsShortArrayOrListWithCache/ProcessTest.php +++ b/Tests/Internal/IsShortArrayOrListWithCache/ProcessTest.php @@ -61,7 +61,7 @@ public function testSupportedBrackets($testMarker, $targetType, $expected) * * @return array */ - public function dataSupportedBrackets() + public static function dataSupportedBrackets() { return [ 'short array open bracket' => [ diff --git a/Tests/Internal/NoFileCache/GetClearTest.php b/Tests/Internal/NoFileCache/GetClearTest.php index e00ca447..d7eebb03 100644 --- a/Tests/Internal/NoFileCache/GetClearTest.php +++ b/Tests/Internal/NoFileCache/GetClearTest.php @@ -234,7 +234,7 @@ public function testGetWillRetrievedPreviouslySetValue($id, $expected) * * @return array */ - public function dataEveryTypeOfInput() + public static function dataEveryTypeOfInput() { $allTypes = TypeProviderHelper::getAll(); $data = []; diff --git a/Tests/Internal/NoFileCache/SetTest.php b/Tests/Internal/NoFileCache/SetTest.php index 916f53f0..e663ecc1 100644 --- a/Tests/Internal/NoFileCache/SetTest.php +++ b/Tests/Internal/NoFileCache/SetTest.php @@ -109,7 +109,7 @@ public function testSetAcceptsEveryTypeOfInput($input) * * @return array */ - public function dataEveryTypeOfInput() + public static function dataEveryTypeOfInput() { return TypeProviderHelper::getAll(); } @@ -151,7 +151,7 @@ public function testSetAcceptsIntAndStringIdKeys($id) * * @return array */ - public function dataSetAcceptsIntAndStringIdKeys() + public static function dataSetAcceptsIntAndStringIdKeys() { return [ 'ID: int zero' => [ diff --git a/Tests/TestUtils/UtilityMethodTestCase/GetTargetTokenTest.php b/Tests/TestUtils/UtilityMethodTestCase/GetTargetTokenTest.php index 162da8f5..d07f6387 100644 --- a/Tests/TestUtils/UtilityMethodTestCase/GetTargetTokenTest.php +++ b/Tests/TestUtils/UtilityMethodTestCase/GetTargetTokenTest.php @@ -67,7 +67,7 @@ public function testGetTargetToken($expected, $commentString, $tokenType, $token * * @return array */ - public function dataGetTargetToken() + public static function dataGetTargetToken() { return [ 'single-token-type' => [ diff --git a/Tests/Tokens/Collections/PropertyBasedTokenArraysTest.php b/Tests/Tokens/Collections/PropertyBasedTokenArraysTest.php index b2113575..d1d83bc5 100644 --- a/Tests/Tokens/Collections/PropertyBasedTokenArraysTest.php +++ b/Tests/Tokens/Collections/PropertyBasedTokenArraysTest.php @@ -52,7 +52,7 @@ public function testPropertyBasedTokenArrays($name) * * @return array */ - public function dataPropertyBasedTokenArrays() + public static function dataPropertyBasedTokenArrays() { $names = [ 'alternativeControlStructureSyntaxes', diff --git a/Tests/Tokens/TokenHelper/TokenExistsTest.php b/Tests/Tokens/TokenHelper/TokenExistsTest.php index 96f23266..711f8c4b 100644 --- a/Tests/Tokens/TokenHelper/TokenExistsTest.php +++ b/Tests/Tokens/TokenHelper/TokenExistsTest.php @@ -62,7 +62,7 @@ public function testTokenExists($name, $expected) * * @return array */ - public function dataTokenExists() + public static function dataTokenExists() { return [ 'Token which doesn\'t exist either way' => [ diff --git a/Tests/Utils/Arrays/GetDoubleArrowPtrTest.php b/Tests/Utils/Arrays/GetDoubleArrowPtrTest.php index 8ff7fa75..d0057d16 100644 --- a/Tests/Utils/Arrays/GetDoubleArrowPtrTest.php +++ b/Tests/Utils/Arrays/GetDoubleArrowPtrTest.php @@ -138,7 +138,7 @@ public function testGetDoubleArrowPtr($testMarker, $expected) * * @return array */ - public function dataGetDoubleArrowPtr() + public static function dataGetDoubleArrowPtr() { return [ 'test-no-arrow' => [ diff --git a/Tests/Utils/Arrays/GetOpenCloseTest.php b/Tests/Utils/Arrays/GetOpenCloseTest.php index 98a4dea9..c6cfe5c1 100644 --- a/Tests/Utils/Arrays/GetOpenCloseTest.php +++ b/Tests/Utils/Arrays/GetOpenCloseTest.php @@ -58,7 +58,7 @@ public function testNotArrayOpenToken($testMarker, $targetToken) * * @return array */ - public function dataNotArrayOpenToken() + public static function dataNotArrayOpenToken() { return [ 'short-list' => [ @@ -118,7 +118,7 @@ public function testGetOpenClose($testMarker, $targetToken, $expected) * * @return array */ - public function dataGetOpenClose() + public static function dataGetOpenClose() { return [ 'long-array' => [ diff --git a/Tests/Utils/Conditions/GetConditionTest.php b/Tests/Utils/Conditions/GetConditionTest.php index e2dcc63c..c8b84d9c 100644 --- a/Tests/Utils/Conditions/GetConditionTest.php +++ b/Tests/Utils/Conditions/GetConditionTest.php @@ -150,7 +150,7 @@ public function testGetFirstCondition($testMarker) * * @return array */ - public function dataGetFirstCondition() + public static function dataGetFirstCondition() { $data = []; foreach (self::$testTargets as $marker) { @@ -195,7 +195,7 @@ public function testGetLastCondition($testMarker, $expected) * * @return array */ - public function dataGetLastCondition() + public static function dataGetLastCondition() { return [ 'testSeriouslyNestedMethod' => [ diff --git a/Tests/Utils/Context/InAttributeTest.php b/Tests/Utils/Context/InAttributeTest.php index 95333014..d09faa41 100644 --- a/Tests/Utils/Context/InAttributeTest.php +++ b/Tests/Utils/Context/InAttributeTest.php @@ -58,7 +58,7 @@ public function testNotInAttribute($testMarker, $targetType) * * @return array */ - public function dataNotInAttribute() + public static function dataNotInAttribute() { return [ 'code nowhere near an attribute [1]' => [ @@ -122,7 +122,7 @@ public function testInAttribute($testMarker, $targetType) * * @return array */ - public function dataInAttribute() + public static function dataInAttribute() { return [ 'single line attribute - attribute name' => [ diff --git a/Tests/Utils/Context/InEmptyTest.php b/Tests/Utils/Context/InEmptyTest.php index 0a49654a..62750d1c 100644 --- a/Tests/Utils/Context/InEmptyTest.php +++ b/Tests/Utils/Context/InEmptyTest.php @@ -58,7 +58,7 @@ public function testInEmpty($testMarker, $expected) * * @return array */ - public function dataInEmpty() + public static function dataInEmpty() { return [ 'method-called-empty' => [ diff --git a/Tests/Utils/Context/InForConditionTest.php b/Tests/Utils/Context/InForConditionTest.php index 57531278..89d3ee99 100644 --- a/Tests/Utils/Context/InForConditionTest.php +++ b/Tests/Utils/Context/InForConditionTest.php @@ -57,7 +57,7 @@ public function testNotInFor($testMarker) * * @return array */ - public function dataNotInFor() + public static function dataNotInFor() { return [ 'no-parenthesis' => ['/* testNoParentheses */'], @@ -103,7 +103,7 @@ public function testInForCondition($testMarker, $expected, $targetType = \T_VARI * * @return array */ - public function dataInForCondition() + public static function dataInForCondition() { return [ 'expr1' => [ diff --git a/Tests/Utils/Context/InForeachConditionTest.php b/Tests/Utils/Context/InForeachConditionTest.php index 4ce9f86c..f14e73ce 100644 --- a/Tests/Utils/Context/InForeachConditionTest.php +++ b/Tests/Utils/Context/InForeachConditionTest.php @@ -57,7 +57,7 @@ public function testNotInForeach($testMarker) * * @return array */ - public function dataNotInForeach() + public static function dataNotInForeach() { return [ 'no-parenthesis' => ['/* testNoParentheses */'], @@ -102,7 +102,7 @@ public function testInForeachCondition($testMarker, $expected, $targetType = \T_ * * @return array */ - public function dataInForeachCondition() + public static function dataInForeachCondition() { return [ 'before' => [ diff --git a/Tests/Utils/Context/InIssetTest.php b/Tests/Utils/Context/InIssetTest.php index e332e75b..c48a7433 100644 --- a/Tests/Utils/Context/InIssetTest.php +++ b/Tests/Utils/Context/InIssetTest.php @@ -58,7 +58,7 @@ public function testInIsset($testMarker, $expected) * * @return array */ - public function dataInIsset() + public static function dataInIsset() { return [ 'method-called-isset' => [ diff --git a/Tests/Utils/Context/InUnsetTest.php b/Tests/Utils/Context/InUnsetTest.php index b0b65cae..350f38aa 100644 --- a/Tests/Utils/Context/InUnsetTest.php +++ b/Tests/Utils/Context/InUnsetTest.php @@ -58,7 +58,7 @@ public function testInUnset($testMarker, $expected) * * @return array */ - public function dataInUnset() + public static function dataInUnset() { return [ 'method-called-unset' => [ diff --git a/Tests/Utils/ControlStructures/GetCaughtExceptionsTest.php b/Tests/Utils/ControlStructures/GetCaughtExceptionsTest.php index 32d4dcba..fdafc00f 100644 --- a/Tests/Utils/ControlStructures/GetCaughtExceptionsTest.php +++ b/Tests/Utils/ControlStructures/GetCaughtExceptionsTest.php @@ -93,7 +93,7 @@ public function testGetCaughtExceptions($testMarker, $expected) * * @return array */ - public function dataGetCaughtExceptions() + public static function dataGetCaughtExceptions() { $php8Names = parent::usesPhp8NameTokens(); diff --git a/Tests/Utils/ControlStructures/HasBodyTest.php b/Tests/Utils/ControlStructures/HasBodyTest.php index 456115f7..9ffc7ca3 100644 --- a/Tests/Utils/ControlStructures/HasBodyTest.php +++ b/Tests/Utils/ControlStructures/HasBodyTest.php @@ -78,7 +78,7 @@ public function testHasBody($testMarker, $hasBody, $hasNonEmptyBody) * * @return array */ - public function dataHasBody() + public static function dataHasBody() { return [ 'if-without-body' => [ diff --git a/Tests/Utils/ControlStructures/IsElseIfTest.php b/Tests/Utils/ControlStructures/IsElseIfTest.php index cc63b327..2f292465 100644 --- a/Tests/Utils/ControlStructures/IsElseIfTest.php +++ b/Tests/Utils/ControlStructures/IsElseIfTest.php @@ -70,7 +70,7 @@ public function testIsElseIf($testMarker, $expected) * * @return array */ - public function dataIsElseIf() + public static function dataIsElseIf() { return [ 'if' => [ diff --git a/Tests/Utils/FunctionDeclarations/IsMagicFunctionNameTest.php b/Tests/Utils/FunctionDeclarations/IsMagicFunctionNameTest.php index 0b81a56f..991c2ff8 100644 --- a/Tests/Utils/FunctionDeclarations/IsMagicFunctionNameTest.php +++ b/Tests/Utils/FunctionDeclarations/IsMagicFunctionNameTest.php @@ -46,7 +46,7 @@ public function testIsMagicFunctionName($name) * * @return array */ - public function dataIsMagicFunctionName() + public static function dataIsMagicFunctionName() { return [ 'lowercase' => ['__autoload'], @@ -76,7 +76,7 @@ public function testIsNotMagicFunctionName($name) * * @return array */ - public function dataIsNotMagicFunctionName() + public static function dataIsNotMagicFunctionName() { return [ 'no_underscore' => ['noDoubleUnderscore'], diff --git a/Tests/Utils/FunctionDeclarations/IsMagicMethodNameTest.php b/Tests/Utils/FunctionDeclarations/IsMagicMethodNameTest.php index 1ad5f01c..5fa84844 100644 --- a/Tests/Utils/FunctionDeclarations/IsMagicMethodNameTest.php +++ b/Tests/Utils/FunctionDeclarations/IsMagicMethodNameTest.php @@ -63,7 +63,7 @@ public function testIsSpecialMethodName($name) * * @return array */ - public function dataIsMagicMethodName() + public static function dataIsMagicMethodName() { return [ // Normal case. @@ -144,7 +144,7 @@ public function testIsNotSpecialMethodName($name) * * @return array */ - public function dataIsNotMagicMethodName() + public static function dataIsNotMagicMethodName() { return [ 'no_underscore' => ['construct'], diff --git a/Tests/Utils/FunctionDeclarations/IsPHPDoubleUnderscoreMethodNameTest.php b/Tests/Utils/FunctionDeclarations/IsPHPDoubleUnderscoreMethodNameTest.php index f5735666..79e74ad9 100644 --- a/Tests/Utils/FunctionDeclarations/IsPHPDoubleUnderscoreMethodNameTest.php +++ b/Tests/Utils/FunctionDeclarations/IsPHPDoubleUnderscoreMethodNameTest.php @@ -64,7 +64,7 @@ public function testIsSpecialMethodName($name) * * @return array */ - public function dataIsPHPDoubleUnderscoreMethodName() + public static function dataIsPHPDoubleUnderscoreMethodName() { return [ // Normal case. @@ -135,7 +135,7 @@ public function testIsNotSpecialMethodName($name) * * @return array */ - public function dataIsNotPHPDoubleUnderscoreMethodName() + public static function dataIsNotPHPDoubleUnderscoreMethodName() { return [ 'no_underscore' => ['getLastResponseHeaders'], diff --git a/Tests/Utils/FunctionDeclarations/SpecialFunctionsTest.php b/Tests/Utils/FunctionDeclarations/SpecialFunctionsTest.php index 499c64c3..52f1ee19 100644 --- a/Tests/Utils/FunctionDeclarations/SpecialFunctionsTest.php +++ b/Tests/Utils/FunctionDeclarations/SpecialFunctionsTest.php @@ -162,7 +162,7 @@ public function testIsSpecialMethod($testMarker, $expected) * * @return array */ - public function dataItsAKindOfMagic() + public static function dataItsAKindOfMagic() { return [ 'MagicMethodInClass' => [ diff --git a/Tests/Utils/GetTokensAsString/GetTokensAsStringTest.php b/Tests/Utils/GetTokensAsString/GetTokensAsStringTest.php index 30f6b6fb..0202545a 100644 --- a/Tests/Utils/GetTokensAsString/GetTokensAsStringTest.php +++ b/Tests/Utils/GetTokensAsString/GetTokensAsStringTest.php @@ -241,7 +241,7 @@ public function testCompactNoComments($testMarker, $startTokenType, $expected) * * @return array */ - public function dataGetTokensAsString() + public static function dataGetTokensAsString() { return [ 'namespace' => [ diff --git a/Tests/Utils/Lists/GetAssignmentsTest.php b/Tests/Utils/Lists/GetAssignmentsTest.php index 3bbf364c..ee799080 100644 --- a/Tests/Utils/Lists/GetAssignmentsTest.php +++ b/Tests/Utils/Lists/GetAssignmentsTest.php @@ -64,7 +64,7 @@ public function testNotListToken($testMarker, $targetToken) * * @return array */ - public function dataNotListToken() + public static function dataNotListToken() { return [ 'not-a-list' => [ @@ -128,7 +128,7 @@ public function testGetAssignments($testMarker, $targetToken, $expected) * * @return array */ - public function dataGetAssignments() + public static function dataGetAssignments() { return [ 'long-list-empty' => [ diff --git a/Tests/Utils/Lists/GetOpenCloseTest.php b/Tests/Utils/Lists/GetOpenCloseTest.php index 76be9d73..d169af39 100644 --- a/Tests/Utils/Lists/GetOpenCloseTest.php +++ b/Tests/Utils/Lists/GetOpenCloseTest.php @@ -58,7 +58,7 @@ public function testNotListOpenToken($testMarker, $targetToken) * * @return array */ - public function dataNotListOpenToken() + public static function dataNotListOpenToken() { return [ 'short-array' => [ @@ -118,7 +118,7 @@ public function testGetOpenClose($testMarker, $targetToken, $expected) * * @return array */ - public function dataGetOpenClose() + public static function dataGetOpenClose() { return [ 'long-list' => [ diff --git a/Tests/Utils/MessageHelper/AddMessageTest.php b/Tests/Utils/MessageHelper/AddMessageTest.php index f9a1ccc7..6313a584 100644 --- a/Tests/Utils/MessageHelper/AddMessageTest.php +++ b/Tests/Utils/MessageHelper/AddMessageTest.php @@ -86,7 +86,7 @@ public function testAddMessage($testMarker, $isError, $expected) * * @return array */ - public function dataAddMessage() + public static function dataAddMessage() { return [ 'add-error' => [ @@ -152,7 +152,7 @@ public function testAddFixableMessage($testMarker, $isError, $expected) * * @return array */ - public function dataAddFixableMessage() + public static function dataAddFixableMessage() { return [ 'add-fixable-error' => [ diff --git a/Tests/Utils/MessageHelper/ShowEscapeCharsTest.php b/Tests/Utils/MessageHelper/ShowEscapeCharsTest.php index a2240cb6..726e3ae7 100644 --- a/Tests/Utils/MessageHelper/ShowEscapeCharsTest.php +++ b/Tests/Utils/MessageHelper/ShowEscapeCharsTest.php @@ -47,7 +47,7 @@ public function testShowEscapeChars($input, $expected) * * @return array */ - public function dataShowEscapeChars() + public static function dataShowEscapeChars() { return [ 'no-escape-chars' => [ diff --git a/Tests/Utils/MessageHelper/StringToErrorcodeTest.php b/Tests/Utils/MessageHelper/StringToErrorcodeTest.php index f45f46b1..d42750b6 100644 --- a/Tests/Utils/MessageHelper/StringToErrorcodeTest.php +++ b/Tests/Utils/MessageHelper/StringToErrorcodeTest.php @@ -47,7 +47,7 @@ public function testStringToErrorCode($input, $expected) * * @return array */ - public function dataStringToErrorCode() + public static function dataStringToErrorCode() { return [ 'no-special-chars' => [ @@ -99,7 +99,7 @@ public function testStringToErrorCodeWithCaseChange($input, $expected) * * @return array */ - public function dataStringToErrorCodeWithCaseChange() + public static function dataStringToErrorCodeWithCaseChange() { return [ 'no-special-chars' => [ diff --git a/Tests/Utils/Namespaces/DetermineNamespaceTest.php b/Tests/Utils/Namespaces/DetermineNamespaceTest.php index 3256217a..8799e8fd 100644 --- a/Tests/Utils/Namespaces/DetermineNamespaceTest.php +++ b/Tests/Utils/Namespaces/DetermineNamespaceTest.php @@ -86,7 +86,7 @@ public function testDetermineNamespace($testMarker, $expected) * * @return array */ - public function dataDetermineNamespace() + public static function dataDetermineNamespace() { return [ 'no-namespace' => [ diff --git a/Tests/Utils/Namespaces/GetDeclaredNameTest.php b/Tests/Utils/Namespaces/GetDeclaredNameTest.php index bfbfc518..ae61faad 100644 --- a/Tests/Utils/Namespaces/GetDeclaredNameTest.php +++ b/Tests/Utils/Namespaces/GetDeclaredNameTest.php @@ -96,7 +96,7 @@ public function testGetDeclaredNameDirty($testMarker, $expected, $skipOnPHP8 = f * * @return array */ - public function dataGetDeclaredName() + public static function dataGetDeclaredName() { return [ 'global-namespace-curlies' => [ diff --git a/Tests/Utils/Namespaces/NamespaceTypeTest.php b/Tests/Utils/Namespaces/NamespaceTypeTest.php index 320eae61..c79dad58 100644 --- a/Tests/Utils/Namespaces/NamespaceTypeTest.php +++ b/Tests/Utils/Namespaces/NamespaceTypeTest.php @@ -111,7 +111,7 @@ public function testIsOperator($testMarker, $expected, $skipOnPHP8 = false) * * @return array */ - public function dataNamespaceType() + public static function dataNamespaceType() { return [ 'namespace-declaration' => [ diff --git a/Tests/Utils/NamingConventions/IsEqualTest.php b/Tests/Utils/NamingConventions/IsEqualTest.php index 85104ce9..d5f7e767 100644 --- a/Tests/Utils/NamingConventions/IsEqualTest.php +++ b/Tests/Utils/NamingConventions/IsEqualTest.php @@ -48,7 +48,7 @@ public function testIsEqual($inputA, $inputB, $expected) * * @return array */ - public function dataIsEqual() + public static function dataIsEqual() { return [ 'a-z-0-9-only-same-case' => [ diff --git a/Tests/Utils/NamingConventions/IsValidIdentifierNameTest.php b/Tests/Utils/NamingConventions/IsValidIdentifierNameTest.php index d3b6b195..9db7fca2 100644 --- a/Tests/Utils/NamingConventions/IsValidIdentifierNameTest.php +++ b/Tests/Utils/NamingConventions/IsValidIdentifierNameTest.php @@ -47,7 +47,7 @@ public function testIsValidIdentifierName($input, $expected) * * @return array */ - public function dataIsValidIdentifierName() + public static function dataIsValidIdentifierName() { return [ // Valid names. diff --git a/Tests/Utils/Numbers/GetCompleteNumberTest.php b/Tests/Utils/Numbers/GetCompleteNumberTest.php index c65e9efc..55173dad 100644 --- a/Tests/Utils/Numbers/GetCompleteNumberTest.php +++ b/Tests/Utils/Numbers/GetCompleteNumberTest.php @@ -70,7 +70,7 @@ public function testGetCompleteNumber($testMarker, $expected) * * @return array */ - public function dataGetCompleteNumber() + public static function dataGetCompleteNumber() { /* * Disabling the hexnumeric string detection for the rest of the file. diff --git a/Tests/Utils/Numbers/GetDecimalValueTest.php b/Tests/Utils/Numbers/GetDecimalValueTest.php index 0dd2fec8..11f82e88 100644 --- a/Tests/Utils/Numbers/GetDecimalValueTest.php +++ b/Tests/Utils/Numbers/GetDecimalValueTest.php @@ -47,7 +47,7 @@ public function testGetDecimalValue($input, $expected) * * @return array */ - public function dataGetDecimalValue() + public static function dataGetDecimalValue() { return [ // Decimal integers. @@ -110,7 +110,7 @@ public function testGetDecimalValueInvalid($input) * * @return array */ - public function dataGetDecimalValueInvalid() + public static function dataGetDecimalValueInvalid() { return [ 'not-a-string-bool' => [true], diff --git a/Tests/Utils/ObjectDeclarations/FindExtendedClassNameDiffTest.php b/Tests/Utils/ObjectDeclarations/FindExtendedClassNameDiffTest.php index 5da5a50e..ddaa3a18 100644 --- a/Tests/Utils/ObjectDeclarations/FindExtendedClassNameDiffTest.php +++ b/Tests/Utils/ObjectDeclarations/FindExtendedClassNameDiffTest.php @@ -53,7 +53,7 @@ public function testFindExtendedClassName($testMarker, $expected) * * @return array */ - public function dataFindExtendedClassName() + public static function dataFindExtendedClassName() { return [ 'phpcs-annotation-and-comments' => [ diff --git a/Tests/Utils/ObjectDeclarations/FindExtendedInterfaceNamesTest.php b/Tests/Utils/ObjectDeclarations/FindExtendedInterfaceNamesTest.php index 3da86aaa..4d927f5d 100644 --- a/Tests/Utils/ObjectDeclarations/FindExtendedInterfaceNamesTest.php +++ b/Tests/Utils/ObjectDeclarations/FindExtendedInterfaceNamesTest.php @@ -73,7 +73,7 @@ public function testFindExtendedInterfaceNames($testMarker, $expected) * * @return array */ - public function dataFindExtendedInterfaceNames() + public static function dataFindExtendedInterfaceNames() { return [ 'not-extended' => [ diff --git a/Tests/Utils/ObjectDeclarations/FindImplementedInterfaceNamesDiffTest.php b/Tests/Utils/ObjectDeclarations/FindImplementedInterfaceNamesDiffTest.php index 34706c96..68bba35c 100644 --- a/Tests/Utils/ObjectDeclarations/FindImplementedInterfaceNamesDiffTest.php +++ b/Tests/Utils/ObjectDeclarations/FindImplementedInterfaceNamesDiffTest.php @@ -53,7 +53,7 @@ public function testFindImplementedInterfaceNames($testMarker, $expected) * * @return array */ - public function dataFindImplementedInterfaceNames() + public static function dataFindImplementedInterfaceNames() { return [ 'phpcs-annotation-and-comments' => [ diff --git a/Tests/Utils/ObjectDeclarations/GetClassPropertiesDiffTest.php b/Tests/Utils/ObjectDeclarations/GetClassPropertiesDiffTest.php index 8a2b8a48..85ce83ba 100644 --- a/Tests/Utils/ObjectDeclarations/GetClassPropertiesDiffTest.php +++ b/Tests/Utils/ObjectDeclarations/GetClassPropertiesDiffTest.php @@ -76,7 +76,7 @@ public function testGetClassProperties($testMarker, $expected) * * @return array */ - public function dataGetClassProperties() + public static function dataGetClassProperties() { return [ 'phpcs-annotation' => [ diff --git a/Tests/Utils/ObjectDeclarations/GetNameDiffTest.php b/Tests/Utils/ObjectDeclarations/GetNameDiffTest.php index b09173a8..1bcb6942 100644 --- a/Tests/Utils/ObjectDeclarations/GetNameDiffTest.php +++ b/Tests/Utils/ObjectDeclarations/GetNameDiffTest.php @@ -63,7 +63,7 @@ public function testGetNameNull($testMarker, $targetType) * * @return array */ - public function dataGetNameNull() + public static function dataGetNameNull() { return [ 'live-coding' => [ @@ -102,7 +102,7 @@ public function testGetName($testMarker, $expected, $targetType = null) * * @return array */ - public function dataGetName() + public static function dataGetName() { return [ 'trait-name-starts-with-number' => [ diff --git a/Tests/Utils/Operators/IsShortTernaryTest.php b/Tests/Utils/Operators/IsShortTernaryTest.php index 9539f3b6..7dfee745 100644 --- a/Tests/Utils/Operators/IsShortTernaryTest.php +++ b/Tests/Utils/Operators/IsShortTernaryTest.php @@ -74,7 +74,7 @@ public function testIsShortTernary($testMarker, $expected) * * @return array */ - public function dataIsShortTernary() + public static function dataIsShortTernary() { return [ 'long-ternary' => [ diff --git a/Tests/Utils/Operators/IsUnaryPlusMinusJSTest.php b/Tests/Utils/Operators/IsUnaryPlusMinusJSTest.php index ef47170d..8b52d441 100644 --- a/Tests/Utils/Operators/IsUnaryPlusMinusJSTest.php +++ b/Tests/Utils/Operators/IsUnaryPlusMinusJSTest.php @@ -38,7 +38,7 @@ final class IsUnaryPlusMinusJSTest extends IsUnaryPlusMinusTestCase * * @return array */ - public function dataIsUnaryPlusMinus() + public static function dataIsUnaryPlusMinus() { return [ 'non-unary-plus' => [ diff --git a/Tests/Utils/Operators/IsUnaryPlusMinusTest.php b/Tests/Utils/Operators/IsUnaryPlusMinusTest.php index 93514299..45d4c842 100644 --- a/Tests/Utils/Operators/IsUnaryPlusMinusTest.php +++ b/Tests/Utils/Operators/IsUnaryPlusMinusTest.php @@ -31,7 +31,7 @@ final class IsUnaryPlusMinusTest extends IsUnaryPlusMinusTestCase * * @return array */ - public function dataIsUnaryPlusMinus() + public static function dataIsUnaryPlusMinus() { return [ 'non-unary-plus' => [ diff --git a/Tests/Utils/Operators/IsUnaryPlusMinusTestCase.php b/Tests/Utils/Operators/IsUnaryPlusMinusTestCase.php index cb441f01..705caafb 100644 --- a/Tests/Utils/Operators/IsUnaryPlusMinusTestCase.php +++ b/Tests/Utils/Operators/IsUnaryPlusMinusTestCase.php @@ -73,5 +73,5 @@ public function testIsUnaryPlusMinus($testMarker, $expected) * * @return array */ - abstract public function dataIsUnaryPlusMinus(); + abstract public static function dataIsUnaryPlusMinus(); } diff --git a/Tests/Utils/Orthography/FirstCharTest.php b/Tests/Utils/Orthography/FirstCharTest.php index b474ac4e..b8d17497 100644 --- a/Tests/Utils/Orthography/FirstCharTest.php +++ b/Tests/Utils/Orthography/FirstCharTest.php @@ -65,7 +65,7 @@ public function testIsFirstCharLowercase($input, $expected) * * @return array */ - public function dataFirstChar() + public static function dataFirstChar() { $data = [ // Quotes should be stripped before passing the string. diff --git a/Tests/Utils/Orthography/IsLastCharPunctuationTest.php b/Tests/Utils/Orthography/IsLastCharPunctuationTest.php index d177e252..ab5ce131 100644 --- a/Tests/Utils/Orthography/IsLastCharPunctuationTest.php +++ b/Tests/Utils/Orthography/IsLastCharPunctuationTest.php @@ -54,7 +54,7 @@ public function testIsLastCharPunctuation($input, $expected, $allowedChars = nul * * @return array */ - public function dataIsLastCharPunctuation() + public static function dataIsLastCharPunctuation() { return [ // Quotes should be stripped before passing the string. diff --git a/Tests/Utils/Parentheses/ParenthesesTest.php b/Tests/Utils/Parentheses/ParenthesesTest.php index 76b365a3..4f2dd4d0 100644 --- a/Tests/Utils/Parentheses/ParenthesesTest.php +++ b/Tests/Utils/Parentheses/ParenthesesTest.php @@ -620,7 +620,7 @@ public function testGetLastOwner($testName, $expectedResults) * * @return array */ - public function dataWalkParentheses() + public static function dataWalkParentheses() { $data = [ 'testIfWithArray-$a' => [ @@ -973,7 +973,7 @@ public function testHasOwner($testName, $expectedResults) * * @return array */ - public function dataHasOwner() + public static function dataHasOwner() { return [ 'testIfWithArray-$a' => [ @@ -1217,7 +1217,7 @@ public function testFirstOwnerIn($testName, $validOwners, $expected) * * @return array */ - public function dataFirstOwnerIn() + public static function dataFirstOwnerIn() { return [ 'testElseIfWithClosure-$a-elseif' => [ @@ -1308,7 +1308,7 @@ public function testLastOwnerIn($testName, $validOwners, $expected) * * @return array */ - public function dataLastOwnerIn() + public static function dataLastOwnerIn() { return [ 'testElseIfWithClosure-$a-closure' => [ diff --git a/Tests/Utils/PassedParameters/GetParameterCountTest.php b/Tests/Utils/PassedParameters/GetParameterCountTest.php index 49d85db4..9edf8fe4 100644 --- a/Tests/Utils/PassedParameters/GetParameterCountTest.php +++ b/Tests/Utils/PassedParameters/GetParameterCountTest.php @@ -60,7 +60,7 @@ public function testGetParameterCount($testMarker, $expected, $targetContent = n * * @return array */ - public function dataGetParameterCount() + public static function dataGetParameterCount() { $php8Names = parent::usesPhp8NameTokens(); diff --git a/Tests/Utils/PassedParameters/GetParameterFromStackTest.php b/Tests/Utils/PassedParameters/GetParameterFromStackTest.php index b600f753..ab79308f 100644 --- a/Tests/Utils/PassedParameters/GetParameterFromStackTest.php +++ b/Tests/Utils/PassedParameters/GetParameterFromStackTest.php @@ -73,7 +73,7 @@ public function testGetParameterNonFunctionCallNoParamName($testMarker, $targetT * * @return array */ - public function dataGetParameterNonFunctionCallNoParamName() + public static function dataGetParameterNonFunctionCallNoParamName() { return [ 'isset' => [ @@ -175,7 +175,7 @@ public function testGetParameterFunctionCallWithParamName($testMarker, $expected * * @return array */ - public function dataGetParameterFunctionCallWithParamName() + public static function dataGetParameterFunctionCallWithParamName() { return [ 'all-named-non-standard-order' => [ @@ -284,7 +284,7 @@ public function testGetParameterFromStack($testMarker, $expectedName, $expectedE * * @return array */ - public function dataGetParameterFromStack() + public static function dataGetParameterFromStack() { return [ 'all-params-all-positional' => [ @@ -450,7 +450,7 @@ public function testGetParameterFromStackNamedAfterVariadic($offset, $names, $ex * * @return array */ - public function dataGetParameterFromStackNamedAfterVariadic() + public static function dataGetParameterFromStackNamedAfterVariadic() { return [ 'first param, positional' => [ diff --git a/Tests/Utils/PassedParameters/GetParametersNamedTest.php b/Tests/Utils/PassedParameters/GetParametersNamedTest.php index 75c446dc..31fdce68 100644 --- a/Tests/Utils/PassedParameters/GetParametersNamedTest.php +++ b/Tests/Utils/PassedParameters/GetParametersNamedTest.php @@ -77,7 +77,7 @@ public function testGetParameters($testMarker, $targetType, $expected, $targetCo * * @return array */ - public function dataGetParameters() + public static function dataGetParameters() { $php8Names = parent::usesPhp8NameTokens(); diff --git a/Tests/Utils/PassedParameters/GetParametersSkipShortArrayCheckTest.php b/Tests/Utils/PassedParameters/GetParametersSkipShortArrayCheckTest.php index fdb7a4b9..786bf7b3 100644 --- a/Tests/Utils/PassedParameters/GetParametersSkipShortArrayCheckTest.php +++ b/Tests/Utils/PassedParameters/GetParametersSkipShortArrayCheckTest.php @@ -113,7 +113,7 @@ public function testGetParametersSkipShortArrayCheck($testMarker, $targetType, $ * * @return array */ - public function dataTestCases() + public static function dataTestCases() { return [ 'no-params' => [ diff --git a/Tests/Utils/PassedParameters/GetParametersTest.php b/Tests/Utils/PassedParameters/GetParametersTest.php index ccc8433c..ead9f87d 100644 --- a/Tests/Utils/PassedParameters/GetParametersTest.php +++ b/Tests/Utils/PassedParameters/GetParametersTest.php @@ -88,7 +88,7 @@ public function testGetParameters($testMarker, $targetType, $expected) * * @return array */ - public function dataGetParameters() + public static function dataGetParameters() { return [ 'function-call' => [ @@ -725,7 +725,7 @@ public function testGetParameter($testMarker, $targetType, $paramPosition, $expe * * @return array */ - public function dataGetParameter() + public static function dataGetParameter() { return [ 'function-call-param-4' => [ diff --git a/Tests/Utils/PassedParameters/GetParametersWithLimitTest.php b/Tests/Utils/PassedParameters/GetParametersWithLimitTest.php index bfcb271b..03a5ebe1 100644 --- a/Tests/Utils/PassedParameters/GetParametersWithLimitTest.php +++ b/Tests/Utils/PassedParameters/GetParametersWithLimitTest.php @@ -73,7 +73,7 @@ public function testGetParametersWithIneffectiveLimit($limit) * * @return array */ - public function dataGetParametersWithIneffectiveLimit() + public static function dataGetParametersWithIneffectiveLimit() { return [ 'invalid-limit-wrong-type-null' => [null], @@ -133,7 +133,7 @@ public function testGetParametersWithLimit($testMarker, $targetType, $limit, $ex * * @return array */ - public function dataGetParametersWithLimit() + public static function dataGetParametersWithLimit() { return [ 'function-call' => [ diff --git a/Tests/Utils/PassedParameters/HasParametersTest.php b/Tests/Utils/PassedParameters/HasParametersTest.php index 71d6d1fd..e7084028 100644 --- a/Tests/Utils/PassedParameters/HasParametersTest.php +++ b/Tests/Utils/PassedParameters/HasParametersTest.php @@ -83,7 +83,7 @@ public function testNotACallToConstructor($testMarker, $targetType) * * @return array */ - public function dataNotACallToConstructor() + public static function dataNotACallToConstructor() { return [ 'parent' => [ @@ -146,7 +146,7 @@ public function testHasParameters($testMarker, $targetType, $expected, $targetCo * * @return array */ - public function dataHasParameters() + public static function dataHasParameters() { $php8Names = parent::usesPhp8NameTokens(); diff --git a/Tests/Utils/Scopes/IsOOConstantTest.php b/Tests/Utils/Scopes/IsOOConstantTest.php index 911514d0..38a43f22 100644 --- a/Tests/Utils/Scopes/IsOOConstantTest.php +++ b/Tests/Utils/Scopes/IsOOConstantTest.php @@ -78,7 +78,7 @@ public function testIsOOConstant($testMarker, $expected) * * @return array */ - public function dataIsOOConstant() + public static function dataIsOOConstant() { return [ 'global-const' => [ diff --git a/Tests/Utils/Scopes/IsOOMethodTest.php b/Tests/Utils/Scopes/IsOOMethodTest.php index 540cdb93..30b62889 100644 --- a/Tests/Utils/Scopes/IsOOMethodTest.php +++ b/Tests/Utils/Scopes/IsOOMethodTest.php @@ -78,7 +78,7 @@ public function testIsOOMethod($testMarker, $expected) * * @return array */ - public function dataIsOOMethod() + public static function dataIsOOMethod() { return [ 'global-function' => [ diff --git a/Tests/Utils/Scopes/IsOOPropertyTest.php b/Tests/Utils/Scopes/IsOOPropertyTest.php index 5e3f9c04..9e444ca8 100644 --- a/Tests/Utils/Scopes/IsOOPropertyTest.php +++ b/Tests/Utils/Scopes/IsOOPropertyTest.php @@ -78,7 +78,7 @@ public function testIsOOProperty($testMarker, $expected) * * @return array */ - public function dataIsOOProperty() + public static function dataIsOOProperty() { return [ 'global-var' => [ diff --git a/Tests/Utils/TextStrings/GetCompleteTextStringTest.php b/Tests/Utils/TextStrings/GetCompleteTextStringTest.php index 5a80ee38..d658f1b9 100644 --- a/Tests/Utils/TextStrings/GetCompleteTextStringTest.php +++ b/Tests/Utils/TextStrings/GetCompleteTextStringTest.php @@ -107,7 +107,7 @@ public function testNotFirstTextStringException($method) * * @return array */ - public function dataExceptions() + public static function dataExceptions() { return [ 'getCompleteTextString' => ['getCompleteTextString'], @@ -144,7 +144,7 @@ public function testGetCompleteTextString($testMarker, $expected, $expectedWithQ * * @return array */ - public function dataGetCompleteTextString() + public static function dataGetCompleteTextString() { return [ 'single-line-constant-encapsed-string' => [ diff --git a/Tests/Utils/TextStrings/GetEndOfCompleteTextStringTest.php b/Tests/Utils/TextStrings/GetEndOfCompleteTextStringTest.php index f16d3053..569c9f52 100644 --- a/Tests/Utils/TextStrings/GetEndOfCompleteTextStringTest.php +++ b/Tests/Utils/TextStrings/GetEndOfCompleteTextStringTest.php @@ -55,7 +55,7 @@ public function testGetEndOfDoubleQuotedString($testMarker, $expectedContent) * * @return array */ - public function dataGetEndOfDoubleQuotedString() + public static function dataGetEndOfDoubleQuotedString() { return [ 'Simple embedded variable 1' => [ diff --git a/Tests/Utils/TextStrings/StripQuotesTest.php b/Tests/Utils/TextStrings/StripQuotesTest.php index 56faac11..dd05088b 100644 --- a/Tests/Utils/TextStrings/StripQuotesTest.php +++ b/Tests/Utils/TextStrings/StripQuotesTest.php @@ -47,7 +47,7 @@ public function testStripQuotes($input, $expected) * * @return array */ - public function dataStripQuotes() + public static function dataStripQuotes() { return [ 'simple-string-double-quotes' => [ diff --git a/Tests/Utils/UseStatements/SplitAndMergeImportUseStatementTest.php b/Tests/Utils/UseStatements/SplitAndMergeImportUseStatementTest.php index b550bce2..fc81ab18 100644 --- a/Tests/Utils/UseStatements/SplitAndMergeImportUseStatementTest.php +++ b/Tests/Utils/UseStatements/SplitAndMergeImportUseStatementTest.php @@ -52,7 +52,7 @@ public function testSplitAndMergeImportUseStatement($testMarker, $expected, $pre * * @return array */ - public function dataSplitAndMergeImportUseStatement() + public static function dataSplitAndMergeImportUseStatement() { $data = [ 'name-plain' => [ diff --git a/Tests/Utils/UseStatements/SplitImportUseStatementTest.php b/Tests/Utils/UseStatements/SplitImportUseStatementTest.php index 83b40647..c75eccda 100644 --- a/Tests/Utils/UseStatements/SplitImportUseStatementTest.php +++ b/Tests/Utils/UseStatements/SplitImportUseStatementTest.php @@ -75,7 +75,7 @@ public function testNonImportUseTokenPassed($testMarker) * * @return array */ - public function dataNonImportUseTokenPassed() + public static function dataNonImportUseTokenPassed() { return [ 'closure-use' => ['/* testClosureUse */'], @@ -107,7 +107,7 @@ public function testSplitImportUseStatement($testMarker, $expected) * * @return array */ - public function dataSplitImportUseStatement() + public static function dataSplitImportUseStatement() { return [ 'plain' => [ diff --git a/Tests/Utils/UseStatements/UseTypeTest.php b/Tests/Utils/UseStatements/UseTypeTest.php index 81faabb9..d2f23a05 100644 --- a/Tests/Utils/UseStatements/UseTypeTest.php +++ b/Tests/Utils/UseStatements/UseTypeTest.php @@ -118,7 +118,7 @@ public function testIsTraitUse($testMarker, $expected) * * @return array */ - public function dataUseType() + public static function dataUseType() { return [ 'import-1' => [ diff --git a/Tests/Utils/Variables/GetMemberPropertiesDiffTest.php b/Tests/Utils/Variables/GetMemberPropertiesDiffTest.php index 3e5c189d..f1e072ca 100644 --- a/Tests/Utils/Variables/GetMemberPropertiesDiffTest.php +++ b/Tests/Utils/Variables/GetMemberPropertiesDiffTest.php @@ -65,7 +65,7 @@ public function testNotClassPropertyException($testMarker) * * @return array */ - public function dataNotClassPropertyException() + public static function dataNotClassPropertyException() { return [ 'interface property' => ['/* testInterfaceProperty */'], @@ -105,7 +105,7 @@ public function testGetMemberProperties($identifier, $expected) * * @return array */ - public function dataGetMemberProperties() + public static function dataGetMemberProperties() { return [ 'php8.2-pseudo-type-true' => [ diff --git a/Tests/Utils/Variables/GetMemberPropertiesTest.php b/Tests/Utils/Variables/GetMemberPropertiesTest.php index 619f7a2f..30e07e5b 100644 --- a/Tests/Utils/Variables/GetMemberPropertiesTest.php +++ b/Tests/Utils/Variables/GetMemberPropertiesTest.php @@ -63,7 +63,7 @@ public static function setUpTestFile() * * @return array */ - public function dataGetMemberProperties() + public static function dataGetMemberProperties() { $data = parent::dataGetMemberProperties(); diff --git a/Tests/Utils/Variables/IsPHPReservedVarNameTest.php b/Tests/Utils/Variables/IsPHPReservedVarNameTest.php index acc7adaa..dc466fc4 100644 --- a/Tests/Utils/Variables/IsPHPReservedVarNameTest.php +++ b/Tests/Utils/Variables/IsPHPReservedVarNameTest.php @@ -46,7 +46,7 @@ public function testIsPHPReservedVarName($name) * * @return array */ - public function dataIsPHPReservedVarName() + public static function dataIsPHPReservedVarName() { return [ // With dollar sign. @@ -118,7 +118,7 @@ public function testIsPHPReservedVarNameFalse($name) * * @return array */ - public function dataIsPHPReservedVarNameFalse() + public static function dataIsPHPReservedVarNameFalse() { return [ // Different case. diff --git a/Tests/Utils/Variables/IsSuperglobalTest.php b/Tests/Utils/Variables/IsSuperglobalTest.php index 57019d49..8bec4bd3 100644 --- a/Tests/Utils/Variables/IsSuperglobalTest.php +++ b/Tests/Utils/Variables/IsSuperglobalTest.php @@ -64,7 +64,7 @@ public function testIsSuperglobal($testMarker, $expected, $targetType = \T_VARIA * * @return array */ - public function dataIsSuperglobal() + public static function dataIsSuperglobal() { return [ 'not-a-variable' => [ @@ -157,7 +157,7 @@ public function testIsSuperglobalName($name) * * @return array */ - public function dataIsSuperglobalName() + public static function dataIsSuperglobalName() { return [ '$_SERVER' => ['$_SERVER'], @@ -193,7 +193,7 @@ public function testIsSuperglobalNameFalse($name) * * @return array */ - public function dataIsSuperglobalNameFalse() + public static function dataIsSuperglobalNameFalse() { return [ 'non-reserved-var' => ['$not_a_superglobal'], diff --git a/Tests/Xtra/Tokens/TokenNameTest.php b/Tests/Xtra/Tokens/TokenNameTest.php index b72c9a85..3eb9f636 100644 --- a/Tests/Xtra/Tokens/TokenNameTest.php +++ b/Tests/Xtra/Tokens/TokenNameTest.php @@ -50,7 +50,7 @@ public function testTokenName($tokenCode, $expected) * * @return array */ - public function dataTokenName() + public static function dataTokenName() { return [ 'PHP native token: T_ECHO' => [ From 8f3df559e32a05424c40250734dfef50731768d3 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 6 Jun 2023 23:37:41 +0200 Subject: [PATCH 05/13] Tests/SpacerFixer: make data providers `static` for compatibility with PHPUnit 10 --- .../SpacesFixer/SpacesFixerNewlineTest.php | 2 +- .../SpacesFixer/SpacesFixerNoSpaceTest.php | 2 +- .../SpacesFixer/SpacesFixerOneSpaceTest.php | 2 +- Tests/Fixers/SpacesFixer/SpacesFixerTestCase.php | 16 ++++++++-------- .../SpacesFixer/SpacesFixerTwoSpaceTest.php | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Tests/Fixers/SpacesFixer/SpacesFixerNewlineTest.php b/Tests/Fixers/SpacesFixer/SpacesFixerNewlineTest.php index 9e426aad..c89ed2c1 100644 --- a/Tests/Fixers/SpacesFixer/SpacesFixerNewlineTest.php +++ b/Tests/Fixers/SpacesFixer/SpacesFixerNewlineTest.php @@ -50,7 +50,7 @@ final class SpacesFixerNewlineTest extends SpacesFixerTestCase * * @var array */ - protected $compliantCases = [ + protected static $compliantCases = [ 'newline-and-trailing-spaces', 'multiple-newlines-and-spaces', 'comment-and-new line', diff --git a/Tests/Fixers/SpacesFixer/SpacesFixerNoSpaceTest.php b/Tests/Fixers/SpacesFixer/SpacesFixerNoSpaceTest.php index 366706ef..573184b5 100644 --- a/Tests/Fixers/SpacesFixer/SpacesFixerNoSpaceTest.php +++ b/Tests/Fixers/SpacesFixer/SpacesFixerNoSpaceTest.php @@ -50,7 +50,7 @@ final class SpacesFixerNoSpaceTest extends SpacesFixerTestCase * * @var array */ - protected $compliantCases = ['no-space']; + protected static $compliantCases = ['no-space']; /** * Full path to the fixed version of the test case file associated with this test class. diff --git a/Tests/Fixers/SpacesFixer/SpacesFixerOneSpaceTest.php b/Tests/Fixers/SpacesFixer/SpacesFixerOneSpaceTest.php index 2fe33692..22d9c287 100644 --- a/Tests/Fixers/SpacesFixer/SpacesFixerOneSpaceTest.php +++ b/Tests/Fixers/SpacesFixer/SpacesFixerOneSpaceTest.php @@ -50,7 +50,7 @@ final class SpacesFixerOneSpaceTest extends SpacesFixerTestCase * * @var array */ - protected $compliantCases = [ + protected static $compliantCases = [ 'one-space', 'comment-and-space', ]; diff --git a/Tests/Fixers/SpacesFixer/SpacesFixerTestCase.php b/Tests/Fixers/SpacesFixer/SpacesFixerTestCase.php index 57988e94..36863bc6 100644 --- a/Tests/Fixers/SpacesFixer/SpacesFixerTestCase.php +++ b/Tests/Fixers/SpacesFixer/SpacesFixerTestCase.php @@ -71,7 +71,7 @@ abstract class SpacesFixerTestCase extends UtilityMethodTestCase * * @var array */ - protected $compliantCases = []; + protected static $compliantCases = []; /** * Full path to the fixed version of the test case file associated with this test class. @@ -156,12 +156,12 @@ public function testCheckAndFixNoError($testMarker, $expected) * * @return array */ - public function dataCheckAndFixNoError() + public static function dataCheckAndFixNoError() { $data = []; - $baseData = $this->getAllData(); + $baseData = self::getAllData(); - foreach ($this->compliantCases as $caseName) { + foreach (static::$compliantCases as $caseName) { if (isset($baseData[$caseName])) { $data[$caseName] = $baseData[$caseName]; } @@ -244,11 +244,11 @@ public function testCheckAndFix($testMarker, $expected, $type) * * @return array */ - public function dataCheckAndFix() + public static function dataCheckAndFix() { - $data = $this->getAllData(); + $data = self::getAllData(); - foreach ($this->compliantCases as $caseName) { + foreach (static::$compliantCases as $caseName) { unset($data[$caseName]); } @@ -303,7 +303,7 @@ public function testFixesMade() * * @return array */ - protected function getAllData() + protected static function getAllData() { return [ 'no-space' => [ diff --git a/Tests/Fixers/SpacesFixer/SpacesFixerTwoSpaceTest.php b/Tests/Fixers/SpacesFixer/SpacesFixerTwoSpaceTest.php index 9c31d17b..8c2eabe8 100644 --- a/Tests/Fixers/SpacesFixer/SpacesFixerTwoSpaceTest.php +++ b/Tests/Fixers/SpacesFixer/SpacesFixerTwoSpaceTest.php @@ -52,7 +52,7 @@ final class SpacesFixerTwoSpaceTest extends SpacesFixerTestCase * * @var array */ - protected $compliantCases = ['two-spaces']; + protected static $compliantCases = ['two-spaces']; /** * Full path to the fixed version of the test case file associated with this test class. From 6e8a439fe8695ed48c46d00de14e77a6f1f9e016 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 6 Jun 2023 23:41:32 +0200 Subject: [PATCH 06/13] Tests/InterpolatedVariablesTest: make data providers `static` for compatibility with PHPUnit 10 --- .../TextStrings/InterpolatedVariablesTest.php | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/Tests/Utils/TextStrings/InterpolatedVariablesTest.php b/Tests/Utils/TextStrings/InterpolatedVariablesTest.php index 5e590f62..240be1f4 100644 --- a/Tests/Utils/TextStrings/InterpolatedVariablesTest.php +++ b/Tests/Utils/TextStrings/InterpolatedVariablesTest.php @@ -33,7 +33,7 @@ final class InterpolatedVariablesTest extends TestCase * * @var array */ - private $embeds = [ + private static $embeds = [ // Simple. '$foo', '{$foo}', @@ -125,7 +125,7 @@ final class InterpolatedVariablesTest extends TestCase * * @var array */ - private $phrases = [ + private static $phrases = [ 'single line' => "%s this is nonsense %s\tbut that's not the point %s", 'single line, embed followed by non-space 1' => '%s- dash %s+ plus %s', 'single line, embed followed by non-space 2' => '%s. dash %s= plus %s', @@ -197,10 +197,10 @@ public function testStripEmbeds($input, $expected) * * @return array */ - public function dataEmbedsInPhrases() + public static function dataEmbedsInPhrases() { $data = []; - foreach ($this->embeds as $embed) { + foreach (self::$embeds as $embed) { $data[$embed . '| Plain embed (heredoc)'] = [ 'input' => $embed, 'expected' => [ @@ -217,64 +217,64 @@ public function dataEmbedsInPhrases() ]; // Plain, no double quotes (heredoc). - $phraseKey = \array_rand($this->phrases); + $phraseKey = \array_rand(self::$phrases); $dataKey = $embed . '| Embed at start of plain phrase in: ' . $phraseKey; $data[$dataKey] = [ - 'input' => \sprintf($this->phrases[$phraseKey], $embed, '', ''), + 'input' => \sprintf(self::$phrases[$phraseKey], $embed, '', ''), 'expected' => [ 'get' => [$embed], - 'stripped' => \sprintf($this->phrases[$phraseKey], '', '', ''), + 'stripped' => \sprintf(self::$phrases[$phraseKey], '', '', ''), ], ]; - $phraseKey = \array_rand($this->phrases); + $phraseKey = \array_rand(self::$phrases); $dataKey = $embed . '| Embed in middle of plain phrase in: ' . $phraseKey; $data[$dataKey] = [ - 'input' => \sprintf($this->phrases[$phraseKey], '', $embed, ''), + 'input' => \sprintf(self::$phrases[$phraseKey], '', $embed, ''), 'expected' => [ 'get' => [$embed], - 'stripped' => \sprintf($this->phrases[$phraseKey], '', '', ''), + 'stripped' => \sprintf(self::$phrases[$phraseKey], '', '', ''), ], ]; - $phraseKey = \array_rand($this->phrases); + $phraseKey = \array_rand(self::$phrases); $dataKey = $embed . '| Embed at end of plain phrase in: ' . $phraseKey; $data[$dataKey] = [ - 'input' => \sprintf($this->phrases[$phraseKey], '', '', $embed), + 'input' => \sprintf(self::$phrases[$phraseKey], '', '', $embed), 'expected' => [ 'get' => [$embed], - 'stripped' => \sprintf($this->phrases[$phraseKey], '', '', ''), + 'stripped' => \sprintf(self::$phrases[$phraseKey], '', '', ''), ], ]; // Phrase in double quotes. - $phraseKey = \array_rand($this->phrases); + $phraseKey = \array_rand(self::$phrases); $dataKey = $embed . '| Embed at start of quoted phrase in: ' . $phraseKey; $data[$dataKey] = [ - 'input' => '"' . \sprintf($this->phrases[$phraseKey], $embed, '', '') . '"', + 'input' => '"' . \sprintf(self::$phrases[$phraseKey], $embed, '', '') . '"', 'expected' => [ 'get' => [$embed], - 'stripped' => '"' . \sprintf($this->phrases[$phraseKey], '', '', '') . '"', + 'stripped' => '"' . \sprintf(self::$phrases[$phraseKey], '', '', '') . '"', ], ]; - $phraseKey = \array_rand($this->phrases); + $phraseKey = \array_rand(self::$phrases); $dataKey = $embed . '| Embed in middle of quoted phrase in: ' . $phraseKey; $data[$dataKey] = [ - 'input' => '"' . \sprintf($this->phrases[$phraseKey], '', $embed, '') . '"', + 'input' => '"' . \sprintf(self::$phrases[$phraseKey], '', $embed, '') . '"', 'expected' => [ 'get' => [$embed], - 'stripped' => '"' . \sprintf($this->phrases[$phraseKey], '', '', '') . '"', + 'stripped' => '"' . \sprintf(self::$phrases[$phraseKey], '', '', '') . '"', ], ]; - $phraseKey = \array_rand($this->phrases); + $phraseKey = \array_rand(self::$phrases); $dataKey = $embed . '| Embed at end of quoted phrase in: ' . $phraseKey; $data[$dataKey] = [ - 'input' => '"' . \sprintf($this->phrases[$phraseKey], '', '', $embed) . '"', + 'input' => '"' . \sprintf(self::$phrases[$phraseKey], '', '', $embed) . '"', 'expected' => [ 'get' => [$embed], - 'stripped' => '"' . \sprintf($this->phrases[$phraseKey], '', '', '') . '"', + 'stripped' => '"' . \sprintf(self::$phrases[$phraseKey], '', '', '') . '"', ], ]; } @@ -290,7 +290,7 @@ public function dataEmbedsInPhrases() * * @return array */ - public function dataEscaping() + public static function dataEscaping() { $embedAtEnd = '"Foo: %s%s"'; $embedAtStart = '%s%s Foo'; // Not, no double quotes! @@ -361,7 +361,7 @@ public function dataEscaping() * * @return array */ - public function dataSpecificCases() + public static function dataSpecificCases() { return [ // No embeds. From 90a6179c1e4bb03577f8a26601a0e21e3b2251ec Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 6 Jun 2023 23:53:17 +0200 Subject: [PATCH 07/13] Tests/[NoFile]Cache/SetTest: remove use of the remove PHPUnit `TestCase::getName()` method ... in favour of just using a randomly generated ID for the cache. --- Tests/Internal/Cache/SetTest.php | 2 +- Tests/Internal/NoFileCache/SetTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Internal/Cache/SetTest.php b/Tests/Internal/Cache/SetTest.php index 9ad746ba..343cf0cb 100644 --- a/Tests/Internal/Cache/SetTest.php +++ b/Tests/Internal/Cache/SetTest.php @@ -95,7 +95,7 @@ public static function resetCachingStatus() */ public function testSetAcceptsEveryTypeOfInput($input) { - $id = $this->getName(); + $id = \base_convert(\rand((int) 10e16, (int) 10e20), 10, 36); Cache::set(self::$phpcsFile, __METHOD__, $id, $input); $this->assertTrue( diff --git a/Tests/Internal/NoFileCache/SetTest.php b/Tests/Internal/NoFileCache/SetTest.php index e663ecc1..aaeb4faf 100644 --- a/Tests/Internal/NoFileCache/SetTest.php +++ b/Tests/Internal/NoFileCache/SetTest.php @@ -89,7 +89,7 @@ public static function resetCachingStatus() */ public function testSetAcceptsEveryTypeOfInput($input) { - $id = $this->getName(); + $id = \base_convert(\rand((int) 10e16, (int) 10e20), 10, 36); NoFileCache::set(__METHOD__, $id, $input); $this->assertTrue( From c1ad96c5ad7b003fad6451763145b26bd2bba31d Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 11 Jun 2023 19:10:28 +0200 Subject: [PATCH 08/13] Tests/HasNewLineSupportTest: work round removal of the `setOutputCallback()` method PHPUnit 10.0 removed the `TestCase::setOutputCallback()` method without replacement. Refs: * sebastianbergmann/phpunit 5319 --- Tests/Xtra/Messages/HasNewLineSupportTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Tests/Xtra/Messages/HasNewLineSupportTest.php b/Tests/Xtra/Messages/HasNewLineSupportTest.php index 6943c078..e9e399fe 100644 --- a/Tests/Xtra/Messages/HasNewLineSupportTest.php +++ b/Tests/Xtra/Messages/HasNewLineSupportTest.php @@ -77,9 +77,6 @@ public function testHasNewLineSupport() // Make sure space on empty line is included (often removed by file editor). $expected = \str_replace("|\n", "| \n", $expected); - $this->expectOutputString($expected); - $this->setOutputCallback([$this, 'normalizeOutput']); - /* * Create the error. */ @@ -102,12 +99,17 @@ public function testHasNewLineSupport() $reportClass = new Full(); $reportData = $reporter->prepareFileReport(self::$phpcsFile); + \ob_start(); $reportClass->generateFileReport( $reportData, self::$phpcsFile, self::$phpcsFile->config->showSources, $config->reportWidth ); + $output = \ob_get_contents(); + \ob_end_clean(); + + $this->assertSame($expected, $this->normalizeOutput($output)); } /** From ed53f2ed4fbeee0e6c2c9b4c1305a698ea186d22 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 11 Jun 2023 05:04:08 +0200 Subject: [PATCH 09/13] Tests/AbstractArrayDeclarationSniffTest: various tweaks and improvements --- .../AbstractArrayDeclarationSniffTest.php | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php b/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php index fbdf04f9..d832162e 100644 --- a/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php +++ b/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php @@ -132,8 +132,8 @@ public function testSingleLineShortArrayNoKeysNoTrailingComma() ->method('processOpenClose') ->with( $this->identicalTo(self::$phpcsFile), - $this->equalTo($target), - $this->equalTo($target + 5) + $this->identicalTo($target), + $this->identicalTo($target + 5) ); $mockObj->expects($this->exactly(2)) @@ -164,8 +164,8 @@ public function testSingleLineShortArrayNoKeysNoTrailingComma() ->method('processComma') ->with( $this->identicalTo(self::$phpcsFile), - $this->equalTo($target + 2), - $this->equalTo(1) + $this->identicalTo($target + 2), + $this->identicalTo(1) ); $mockObj->process(self::$phpcsFile, $target); @@ -199,8 +199,8 @@ public function testMultiLineLongArrayKeysTrailingComma() ->method('processOpenClose') ->with( $this->identicalTo(self::$phpcsFile), - $this->equalTo($target + 1), - $this->equalTo($target + 35) + $this->identicalTo($target + 1), + $this->identicalTo($target + 35) ); $mockObj->expects($this->exactly(3)) @@ -296,8 +296,8 @@ public function testMultiLineShortArrayMixedKeysNoKeys() ->method('processOpenClose') ->with( $this->identicalTo(self::$phpcsFile), - $this->equalTo($target), - $this->equalTo($target + 22) + $this->identicalTo($target), + $this->identicalTo($target + 22) ); $mockObj->expects($this->exactly(2)) @@ -319,8 +319,10 @@ public function testMultiLineShortArrayMixedKeysNoKeys() $mockObj->expects($this->once()) ->method('processNoKey') - ->withConsecutive( - [$this->identicalTo(self::$phpcsFile), $this->equalTo($target + 9), $this->equalTo(2)] + ->with( + $this->identicalTo(self::$phpcsFile), + $this->identicalTo($target + 9), + $this->identicalTo(2) ); $mockObj->expects($this->exactly(2)) From 8ecebee0e37da2b2d2f04ab7ffbeab1b6ae7e5c8 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 11 Jun 2023 04:55:07 +0200 Subject: [PATCH 10/13] Tests: add new `ExpectWithConsecutiveArgs` helper trait ... to provide a work-around for the removal of the `InvocationMocker->withConsecutive()` method, which was removed without replacement in PHPUnit 10.0. Refs: * sebastianbergmann/phpunit 4026 * sebastianbergmann/phpunit 4255 * sebastianbergmann/phpunit 4564 --- Tests/ExpectWithConsecutiveArgs.php | 81 +++++++++++++++++++++++++++++ Tests/PolyfilledTestCase.php | 5 +- 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 Tests/ExpectWithConsecutiveArgs.php diff --git a/Tests/ExpectWithConsecutiveArgs.php b/Tests/ExpectWithConsecutiveArgs.php new file mode 100644 index 00000000..12073926 --- /dev/null +++ b/Tests/ExpectWithConsecutiveArgs.php @@ -0,0 +1,81 @@ +withConsecutive()` method could be used to test + * this, but that method was removed in PHPUnit 10.0. + * + * @since 1.0.7 + */ +trait ExpectWithConsecutiveArgs +{ + + /** + * PHPUnit cross-version helper method to test the arguments passed to a method in a mocked object. + * + * @param object $mockObject The object mock. + * @param object $countMatcher Matcher for number of time the method is expected to be called. + * @param string $methodName The name of the method on which to set the expectations. + * @param array $expectedArgs Multi-dimentional array of arguments expected to be passed in consecutive calls. + * + * @return object Expectation object. + */ + final public function setExpectationWithConsecutiveArgs($mockObject, $countMatcher, $methodName, $expectedArgs) + { + $methodExpectation = $mockObject->expects($countMatcher) + ->method($methodName); + + if (\method_exists($methodExpectation, 'withConsecutive')) { + // PHPUnit 4.x - 9.x. + + $expectationsArray = []; + foreach ($expectedArgs as $key => $series) { + foreach ($series as $arg) { + $expectationsArray[$key][] = $this->identicalTo($arg); + } + } + + return \call_user_func_array([$methodExpectation, 'withConsecutive'], $expectationsArray); + } + + // PHPUnit 10+. + return $methodExpectation->willReturnCallback( + function () use (&$expectedArgs, $countMatcher, $methodName) { + $actualArgs = \func_get_args(); + $expected = \array_shift($expectedArgs); + + $this->assertCount( + \count($expected), + $actualArgs, + \sprintf( + 'Actual number of arguments received does not match expected for call %d to method %s', + $countMatcher->numberOfInvocations(), + $methodName + ) + ); + + $this->assertSame( + $expected, + $actualArgs, + \sprintf( + 'Arguments received do not match expected arguments for call %d to method %s', + $countMatcher->numberOfInvocations(), + $methodName + ) + ); + } + ); + } +} diff --git a/Tests/PolyfilledTestCase.php b/Tests/PolyfilledTestCase.php index eea44978..2cd04b3c 100644 --- a/Tests/PolyfilledTestCase.php +++ b/Tests/PolyfilledTestCase.php @@ -14,6 +14,7 @@ namespace PHPCSUtils\Tests; use PHPCSUtils\Tests\AssertAttributeSame; +use PHPCSUtils\Tests\ExpectWithConsecutiveArgs; use PHPCSUtils\TestUtils\UtilityMethodTestCase; use Yoast\PHPUnitPolyfills\Autoload; use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource; @@ -52,8 +53,9 @@ */ abstract class PolyfilledTestCase extends UtilityMethodTestCase { - // PHPCSUtils native helper. + // PHPCSUtils native helpers. use AssertAttributeSame; + use ExpectWithConsecutiveArgs; // PHPUnit Polyfills. use AssertClosedResource; @@ -90,6 +92,7 @@ abstract class PolyfilledTestCase extends UtilityMethodTestCase { // PHPCSUtils native helper. use AssertAttributeSame; + use ExpectWithConsecutiveArgs; // PHPUnit Polyfills. use AssertClosedResource; From ddcecc91d8ce3b5e1dc678d2f1a03f89eef55fd5 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 11 Jun 2023 05:02:01 +0200 Subject: [PATCH 11/13] Tests/AbstractArrayDeclarationSniffTest: implement use of the `ExpectWithConsecutiveArgs` helper --- .../AbstractArrayDeclarationSniffTest.php | 228 ++++++++---------- 1 file changed, 96 insertions(+), 132 deletions(-) diff --git a/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php b/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php index d832162e..5cb8098b 100644 --- a/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php +++ b/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php @@ -136,29 +136,25 @@ public function testSingleLineShortArrayNoKeysNoTrailingComma() $this->identicalTo($target + 5) ); - $mockObj->expects($this->exactly(2)) - ->method('processNoKey') - ->withConsecutive( - [$this->identicalTo(self::$phpcsFile), $this->equalTo($target + 1), $this->equalTo(1)], - [$this->identicalTo(self::$phpcsFile), $this->equalTo($target + 3), $this->equalTo(2)] - ); + $this->setExpectationWithConsecutiveArgs( + $mockObj, + $this->exactly(2), + 'processNoKey', + [ + [self::$phpcsFile, $target + 1, 1], + [self::$phpcsFile, $target + 3, 2], + ] + ); - $mockObj->expects($this->exactly(2)) - ->method('processValue') - ->withConsecutive( - [ - $this->identicalTo(self::$phpcsFile), - $this->equalTo($target + 1), - $this->equalTo($target + 1), - $this->equalTo(1), - ], - [ - $this->identicalTo(self::$phpcsFile), - $this->equalTo($target + 3), - $this->equalTo($target + 4), - $this->equalTo(2), - ] - ); + $this->setExpectationWithConsecutiveArgs( + $mockObj, + $this->exactly(2), + 'processValue', + [ + [self::$phpcsFile, $target + 1, $target + 1, 1], + [self::$phpcsFile, $target + 3, $target + 4, 2], + ] + ); $mockObj->expects($this->once()) ->method('processComma') @@ -203,67 +199,48 @@ public function testMultiLineLongArrayKeysTrailingComma() $this->identicalTo($target + 35) ); - $mockObj->expects($this->exactly(3)) - ->method('processKey') - ->withConsecutive( - [ - $this->identicalTo(self::$phpcsFile), - $this->equalTo($target + 2), - $this->equalTo($target + 5), - $this->equalTo(1), - ], - [ - $this->identicalTo(self::$phpcsFile), - $this->equalTo($target + 10), - $this->equalTo($target + 13), - $this->equalTo(2), - ], - [ - $this->identicalTo(self::$phpcsFile), - $this->equalTo($target + 18), - $this->equalTo($target + 21), - $this->equalTo(3), - ] - ); - - $mockObj->expects($this->exactly(3)) - ->method('processArrow') - ->withConsecutive( - [$this->identicalTo(self::$phpcsFile), $this->equalTo($target + 6), $this->equalTo(1)], - [$this->identicalTo(self::$phpcsFile), $this->equalTo($target + 14), $this->equalTo(2)], - [$this->identicalTo(self::$phpcsFile), $this->equalTo($target + 22), $this->equalTo(3)] - ); + $this->setExpectationWithConsecutiveArgs( + $mockObj, + $this->exactly(3), + 'processKey', + [ + [self::$phpcsFile, $target + 2, $target + 5, 1], + [self::$phpcsFile, $target + 10, $target + 13, 2], + [self::$phpcsFile, $target + 18, $target + 21, 3], + ] + ); - $mockObj->expects($this->exactly(3)) - ->method('processValue') - ->withConsecutive( - [ - $this->identicalTo(self::$phpcsFile), - $this->equalTo($target + 7), - $this->equalTo($target + 8), - $this->equalTo(1), - ], - [ - $this->identicalTo(self::$phpcsFile), - $this->equalTo($target + 15), - $this->equalTo($target + 16), - $this->equalTo(2), - ], - [ - $this->identicalTo(self::$phpcsFile), - $this->equalTo($target + 23), - $this->equalTo($target + 24), - $this->equalTo(3), - ] - ) - ->will($this->onConsecutiveCalls(null, null, true)); // Testing short-circuiting the loop. + $this->setExpectationWithConsecutiveArgs( + $mockObj, + $this->exactly(3), + 'processArrow', + [ + [self::$phpcsFile, $target + 6, 1], + [self::$phpcsFile, $target + 14, 2], + [self::$phpcsFile, $target + 22, 3], + ] + ); - $mockObj->expects($this->exactly(2)) - ->method('processComma') - ->withConsecutive( - [$this->identicalTo(self::$phpcsFile), $this->equalTo($target + 9), $this->equalTo(1)], - [$this->identicalTo(self::$phpcsFile), $this->equalTo($target + 17), $this->equalTo(2)] - ); + $this->setExpectationWithConsecutiveArgs( + $mockObj, + $this->exactly(3), + 'processValue', + [ + [self::$phpcsFile, $target + 7, $target + 8, 1], + [self::$phpcsFile, $target + 15, $target + 16, 2], + [self::$phpcsFile, $target + 23, $target + 24, 3], + ] + )->will($this->onConsecutiveCalls(null, null, true)); // Testing short-circuiting the loop. + + $this->setExpectationWithConsecutiveArgs( + $mockObj, + $this->exactly(2), + 'processComma', + [ + [self::$phpcsFile, $target + 9, 1], + [self::$phpcsFile, $target + 17, 2], + ] + ); $mockObj->process(self::$phpcsFile, $target); @@ -300,22 +277,15 @@ public function testMultiLineShortArrayMixedKeysNoKeys() $this->identicalTo($target + 22) ); - $mockObj->expects($this->exactly(2)) - ->method('processKey') - ->withConsecutive( - [ - $this->identicalTo(self::$phpcsFile), - $this->equalTo($target + 1), - $this->equalTo($target + 4), - $this->equalTo(1), - ], - [ - $this->identicalTo(self::$phpcsFile), - $this->equalTo($target + 13), - $this->equalTo($target + 16), - $this->equalTo(3), - ] - ); + $this->setExpectationWithConsecutiveArgs( + $mockObj, + $this->exactly(2), + 'processKey', + [ + [self::$phpcsFile, $target + 1, $target + 4, 1], + [self::$phpcsFile, $target + 13, $target + 16, 3], + ] + ); $mockObj->expects($this->once()) ->method('processNoKey') @@ -325,43 +295,37 @@ public function testMultiLineShortArrayMixedKeysNoKeys() $this->identicalTo(2) ); - $mockObj->expects($this->exactly(2)) - ->method('processArrow') - ->withConsecutive( - [$this->identicalTo(self::$phpcsFile), $this->equalTo($target + 5), $this->equalTo(1)], - [$this->identicalTo(self::$phpcsFile), $this->equalTo($target + 17), $this->equalTo(3)] - ); + $this->setExpectationWithConsecutiveArgs( + $mockObj, + $this->exactly(2), + 'processArrow', + [ + [self::$phpcsFile, $target + 5, 1], + [self::$phpcsFile, $target + 17, 3], + ] + ); - $mockObj->expects($this->exactly(3)) - ->method('processValue') - ->withConsecutive( - [ - $this->identicalTo(self::$phpcsFile), - $this->equalTo($target + 6), - $this->equalTo($target + 7), - $this->equalTo(1), - ], - [ - $this->identicalTo(self::$phpcsFile), - $this->equalTo($target + 9), - $this->equalTo($target + 11), - $this->equalTo(2), - ], - [ - $this->identicalTo(self::$phpcsFile), - $this->equalTo($target + 18), - $this->equalTo($target + 19), - $this->equalTo(3), - ] - ); + $this->setExpectationWithConsecutiveArgs( + $mockObj, + $this->exactly(3), + 'processValue', + [ + [self::$phpcsFile, $target + 6, $target + 7, 1], + [self::$phpcsFile, $target + 9, $target + 11, 2], + [self::$phpcsFile, $target + 18, $target + 19, 3], + ] + ); - $mockObj->expects($this->exactly(3)) - ->method('processComma') - ->withConsecutive( - [$this->identicalTo(self::$phpcsFile), $this->equalTo($target + 8), $this->equalTo(1)], - [$this->identicalTo(self::$phpcsFile), $this->equalTo($target + 12), $this->equalTo(2)], - [$this->identicalTo(self::$phpcsFile), $this->equalTo($target + 20), $this->equalTo(3)] - ); + $this->setExpectationWithConsecutiveArgs( + $mockObj, + $this->exactly(3), + 'processComma', + [ + [self::$phpcsFile, $target + 8, 1], + [self::$phpcsFile, $target + 12, 2], + [self::$phpcsFile, $target + 20, 3], + ] + ); $mockObj->process(self::$phpcsFile, $target); From 6653cdd95619d43eea49a3dcc23e15e6f3742be5 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 7 Jun 2023 01:24:11 +0200 Subject: [PATCH 12/13] Tests/AbstractArrayDeclarationSniffTest: work around for `MockBuilder::setMethods()` removal Please note: * The `getMockBuilder()` class is also deprecated now, so replacing with another method call on the `MockBuilder` class will only work in the short/medium term and in a future iteration, this will have to be refactored again. * Also the `getMockForAbstractClass method is also deprecated and expected to be removed in PHPUnit 12. Refs: * sebastianbergmann/phpunit 3687#issuecomment-492537584 * sebastianbergmann/phpunit 3770 * sebastianbergmann/phpunit 3769 * sebastianbergmann/phpunit 4775 --- .../AbstractArrayDeclarationSniffTest.php | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php b/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php index 5cb8098b..a6b32bc4 100644 --- a/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php +++ b/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php @@ -51,9 +51,7 @@ public function testShortList() { $target = $this->getTargetToken('/* testShortList */', Collections::arrayOpenTokensBC()); - $mockObj = $this->getMockBuilder('\PHPCSUtils\AbstractSniffs\AbstractArrayDeclarationSniff') - ->setMethods($this->methodsToMock) - ->getMockForAbstractClass(); + $mockObj = $this->getMockedClassUnderTest(); $mockObj->expects($this->never()) ->method('processOpenClose'); @@ -86,9 +84,7 @@ public function testEmptyArray() { $target = $this->getTargetToken('/* testEmptyArray */', Collections::arrayOpenTokensBC()); - $mockObj = $this->getMockBuilder('\PHPCSUtils\AbstractSniffs\AbstractArrayDeclarationSniff') - ->setMethods($this->methodsToMock) - ->getMockForAbstractClass(); + $mockObj = $this->getMockedClassUnderTest(); $mockObj->expects($this->once()) ->method('processOpenClose'); @@ -124,9 +120,7 @@ public function testSingleLineShortArrayNoKeysNoTrailingComma() Collections::arrayOpenTokensBC() ); - $mockObj = $this->getMockBuilder('\PHPCSUtils\AbstractSniffs\AbstractArrayDeclarationSniff') - ->setMethods($this->methodsToMock) - ->getMockForAbstractClass(); + $mockObj = $this->getMockedClassUnderTest(); $mockObj->expects($this->once()) ->method('processOpenClose') @@ -187,9 +181,7 @@ public function testMultiLineLongArrayKeysTrailingComma() Collections::arrayOpenTokensBC() ); - $mockObj = $this->getMockBuilder('\PHPCSUtils\AbstractSniffs\AbstractArrayDeclarationSniff') - ->setMethods($this->methodsToMock) - ->getMockForAbstractClass(); + $mockObj = $this->getMockedClassUnderTest(); $mockObj->expects($this->once()) ->method('processOpenClose') @@ -265,9 +257,7 @@ public function testMultiLineShortArrayMixedKeysNoKeys() Collections::arrayOpenTokensBC() ); - $mockObj = $this->getMockBuilder('\PHPCSUtils\AbstractSniffs\AbstractArrayDeclarationSniff') - ->setMethods($this->methodsToMock) - ->getMockForAbstractClass(); + $mockObj = $this->getMockedClassUnderTest(); $mockObj->expects($this->once()) ->method('processOpenClose') @@ -346,9 +336,7 @@ public function testEmptyArrayItem() { $target = $this->getTargetToken('/* testEmptyArrayItem */', Collections::arrayOpenTokensBC()); - $mockObj = $this->getMockBuilder('\PHPCSUtils\AbstractSniffs\AbstractArrayDeclarationSniff') - ->setMethods($this->methodsToMock) - ->getMockForAbstractClass(); + $mockObj = $this->getMockedClassUnderTest(); $mockObj->expects($this->once()) ->method('processOpenClose'); @@ -377,9 +365,7 @@ public function testShortCircuitOnProcessOpenClose() { $target = $this->getTargetToken('/* testShortCircuit */', Collections::arrayOpenTokensBC()); - $mockObj = $this->getMockBuilder('\PHPCSUtils\AbstractSniffs\AbstractArrayDeclarationSniff') - ->setMethods($this->methodsToMock) - ->getMockForAbstractClass(); + $mockObj = $this->getMockedClassUnderTest(); $mockObj->expects($this->once()) ->method('processOpenClose') @@ -412,9 +398,7 @@ public function testShortCircuitOnProcessKey() { $target = $this->getTargetToken('/* testShortCircuit */', Collections::arrayOpenTokensBC()); - $mockObj = $this->getMockBuilder('\PHPCSUtils\AbstractSniffs\AbstractArrayDeclarationSniff') - ->setMethods($this->methodsToMock) - ->getMockForAbstractClass(); + $mockObj = $this->getMockedClassUnderTest(); $mockObj->expects($this->once()) ->method('processOpenClose'); @@ -447,9 +431,7 @@ public function testShortCircuitOnProcessNoKey() { $target = $this->getTargetToken('/* testShortCircuit */', Collections::arrayOpenTokensBC()); - $mockObj = $this->getMockBuilder('\PHPCSUtils\AbstractSniffs\AbstractArrayDeclarationSniff') - ->setMethods($this->methodsToMock) - ->getMockForAbstractClass(); + $mockObj = $this->getMockedClassUnderTest(); $mockObj->expects($this->once()) ->method('processOpenClose'); @@ -482,9 +464,7 @@ public function testShortCircuitOnProcessArrow() { $target = $this->getTargetToken('/* testShortCircuit */', Collections::arrayOpenTokensBC()); - $mockObj = $this->getMockBuilder('\PHPCSUtils\AbstractSniffs\AbstractArrayDeclarationSniff') - ->setMethods($this->methodsToMock) - ->getMockForAbstractClass(); + $mockObj = $this->getMockedClassUnderTest(); $mockObj->expects($this->once()) ->method('processOpenClose'); @@ -517,9 +497,7 @@ public function testShortCircuitOnProcessValue() { $target = $this->getTargetToken('/* testShortCircuit */', Collections::arrayOpenTokensBC()); - $mockObj = $this->getMockBuilder('\PHPCSUtils\AbstractSniffs\AbstractArrayDeclarationSniff') - ->setMethods($this->methodsToMock) - ->getMockForAbstractClass(); + $mockObj = $this->getMockedClassUnderTest(); $mockObj->expects($this->once()) ->method('processOpenClose'); @@ -552,9 +530,7 @@ public function testShortCircuitOnProcessComma() { $target = $this->getTargetToken('/* testShortCircuit */', Collections::arrayOpenTokensBC()); - $mockObj = $this->getMockBuilder('\PHPCSUtils\AbstractSniffs\AbstractArrayDeclarationSniff') - ->setMethods($this->methodsToMock) - ->getMockForAbstractClass(); + $mockObj = $this->getMockedClassUnderTest(); $mockObj->expects($this->once()) ->method('processOpenClose'); @@ -587,9 +563,7 @@ public function testBowOutOnUnfinishedArray() { $target = $this->getTargetToken('/* testLiveCoding */', Collections::arrayOpenTokensBC()); - $mockObj = $this->getMockBuilder('\PHPCSUtils\AbstractSniffs\AbstractArrayDeclarationSniff') - ->setMethods($this->methodsToMock) - ->getMockForAbstractClass(); + $mockObj = $this->getMockedClassUnderTest(); $mockObj->expects($this->never()) ->method('processOpenClose'); @@ -611,4 +585,30 @@ public function testBowOutOnUnfinishedArray() $mockObj->process(self::$phpcsFile, $target); } + + /** + * Helper method to retrieve a mock object for the abstract class. + * + * The `setMethods()` method was silently deprecated in PHPUnit 9 and removed in PHPUnit 10. + * + * Note: direct access to the `getMockBuilder()` method is soft deprecated as of PHPUnit 10, + * and expected to be hard deprecated in PHPUnit 11 and removed in PHPUnit 12. + * Dealing with that is something for a later iteration of the test suite. + * + * @return \PHPUnit\Framework\MockObject\MockObject + */ + private function getMockedClassUnderTest() + { + $mockedObj = $this->getMockBuilder('\PHPCSUtils\AbstractSniffs\AbstractArrayDeclarationSniff'); + + if (\method_exists($mockedObj, 'onlyMethods')) { + // PHPUnit 8+. + return $mockedObj->onlyMethods($this->methodsToMock) + ->getMockForAbstractClass(); + } + + // PHPUnit < 8. + return $mockedObj->setMethods($this->methodsToMock) + ->getMockForAbstractClass(); + } } From 1914d5fe238d0c2c191f71a773d4bc48d00e89a7 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 11 Jun 2023 21:43:52 +0200 Subject: [PATCH 13/13] PHPUnit: add separate configuration for PHPUnit 10 PHPUnit 10 makes significant changes to the configuration file. While there is a `--migrate-configuration` option available in PHPUnit, that doesn't get us a well enough converted configuration file, so instead use a separate `phpunit10.xml.dist` file for running the tests on PHPUnit 10 with an optimal configuration. Includes * Adding separate scripts to the `composer.json` file to make this more obvious for contributors. * Updating the GH Actions workflows to take the new configuration file into account when appropriate. * Selectively not using the `--repeat` option, which was [removed without replacement](https://github.com/sebastianbergmann/phpunit/issues/5174) in PHPUnit 10. --- .github/workflows/quicktest.yml | 22 +++++++++- .github/workflows/test.yml | 41 +++++++++++++----- composer.json | 9 ++++ phpunit10.xml.dist | 75 +++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+), 13 deletions(-) create mode 100644 phpunit10.xml.dist diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml index 9e29ce9a..511f26d8 100644 --- a/.github/workflows/quicktest.yml +++ b/.github/workflows/quicktest.yml @@ -80,14 +80,32 @@ jobs: if: matrix.phpcs_version == 'dev-master' run: composer lint-lt72 + - name: Grab PHPUnit version + id: phpunit_version + # yamllint disable-line rule:line-length + run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT + + - name: Determine PHPUnit config file to use + id: phpunit_config + run: | + if [ "${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}" == "true" ]; then + echo 'FILE=phpunit10.xml.dist' >> $GITHUB_OUTPUT + echo 'EXTRA_ARGS=' >> $GITHUB_OUTPUT + else + echo 'FILE=phpunit.xml.dist' >> $GITHUB_OUTPUT + echo 'EXTRA_ARGS= --repeat 2' >> $GITHUB_OUTPUT + fi + - name: Run the unit tests without caching - run: vendor/bin/phpunit --no-coverage + run: vendor/bin/phpunit -c ${{ steps.phpunit_config.outputs.FILE }} --no-coverage env: PHPCS_VERSION: ${{ matrix.phpcs_version }} PHPCSUTILS_USE_CACHE: false - name: Run the unit tests with caching - run: vendor/bin/phpunit --testsuite PHPCSUtils --no-coverage --repeat 2 + run: > + vendor/bin/phpunit -c ${{ steps.phpunit_config.outputs.FILE }} + --testsuite PHPCSUtils --no-coverage ${{ steps.phpunit_config.outputs.EXTRA_ARGS }} env: PHPCS_VERSION: ${{ matrix.phpcs_version }} PHPCSUTILS_USE_CACHE: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dbcc316f..40422292 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -201,16 +201,34 @@ jobs: if: ${{ matrix.phpcs_version == 'lowest' }} run: composer update squizlabs/php_codesniffer --prefer-lowest --no-scripts --no-interaction + - name: Grab PHPUnit version + id: phpunit_version + # yamllint disable-line rule:line-length + run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT + + - name: Determine PHPUnit config file to use + id: phpunit_config + run: | + if [ "${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}" == "true" ]; then + echo 'FILE=phpunit10.xml.dist' >> $GITHUB_OUTPUT + echo 'EXTRA_ARGS=' >> $GITHUB_OUTPUT + else + echo 'FILE=phpunit.xml.dist' >> $GITHUB_OUTPUT + echo 'EXTRA_ARGS= --repeat 2' >> $GITHUB_OUTPUT + fi + - name: Run the unit tests without caching (non-risky) if: ${{ matrix.risky == false }} - run: vendor/bin/phpunit --no-coverage + run: vendor/bin/phpunit -c ${{ steps.phpunit_config.outputs.FILE }} --no-coverage env: PHPCS_VERSION: ${{ matrix.phpcs_version == '4.0.x-dev' && '4.0.0' || matrix.phpcs_version }} PHPCSUTILS_USE_CACHE: false - name: Run the unit tests with caching (non-risky) if: ${{ matrix.risky == false }} - run: vendor/bin/phpunit --testsuite PHPCSUtils --no-coverage --repeat 2 + run: > + vendor/bin/phpunit -c ${{ steps.phpunit_config.outputs.FILE }} + --testsuite PHPCSUtils --no-coverage ${{ steps.phpunit_config.outputs.EXTRA_ARGS }} env: PHPCS_VERSION: ${{ matrix.phpcs_version == '4.0.x-dev' && '4.0.0' || matrix.phpcs_version }} PHPCSUTILS_USE_CACHE: true @@ -220,7 +238,7 @@ jobs: - name: Run the unit tests (risky, comparewithPHPCS) if: ${{ matrix.risky && matrix.phpcs_version == 'dev-master' }} # "nothing" is excluded to force PHPUnit to ignore the settings in phpunit.xml.dist. - run: vendor/bin/phpunit --no-coverage --group compareWithPHPCS --exclude-group nothing + run: vendor/bin/phpunit -c ${{ steps.phpunit_config.outputs.FILE }} --no-coverage --group compareWithPHPCS --exclude-group nothing env: PHPCS_VERSION: ${{ matrix.phpcs_version == '4.0.x-dev' && '4.0.0' || matrix.phpcs_version }} @@ -228,7 +246,7 @@ jobs: - name: Run the unit tests (risky, xtra) if: ${{ matrix.risky }} # "nothing" is excluded to force PHPUnit to ignore the settings in phpunit.xml.dist. - run: vendor/bin/phpunit --no-coverage --group xtra --exclude-group nothing + run: vendor/bin/phpunit -c ${{ steps.phpunit_config.outputs.FILE }} --no-coverage --group xtra --exclude-group nothing env: PHPCS_VERSION: ${{ matrix.phpcs_version == '4.0.x-dev' && '4.0.0' || matrix.phpcs_version }} @@ -312,20 +330,21 @@ jobs: # As of PHPUnit 9.3.4, a cache warming option is available. # Using that option prevents issues with PHP-Parser backfilling PHP tokens when PHPCS does not (yet), # which would otherwise cause tests to fail on tokens being available when they shouldn't be. + # As coverage is only run on high/low PHP, the high PHP version will use PHPUnit 10, so just check for that. - name: "Warm the PHPUnit cache (PHPUnit 9.3+)" - if: ${{ steps.phpunit_version.outputs.VERSION >= '9.3' }} - run: vendor/bin/phpunit --coverage-cache ./build/phpunit-cache --warm-coverage-cache + if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }} + run: vendor/bin/phpunit -c phpunit10.xml.dist --coverage-cache ./build/phpunit-cache --warm-coverage-cache - - name: "Run the unit tests without caching with code coverage (PHPUnit < 9.3)" - if: ${{ steps.phpunit_version.outputs.VERSION < '9.3' }} + - name: "Run the unit tests without caching with code coverage (PHPUnit < 10)" + if: ${{ ! startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }} run: vendor/bin/phpunit env: PHPCS_VERSION: ${{ matrix.phpcs_version }} PHPCSUTILS_USE_CACHE: false - - name: "Run the unit tests without caching with code coverage (PHPUnit 9.3+)" - if: ${{ steps.phpunit_version.outputs.VERSION >= '9.3' }} - run: vendor/bin/phpunit --coverage-cache ./build/phpunit-cache + - name: "Run the unit tests without caching with code coverage (PHPUnit 10+)" + if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }} + run: vendor/bin/phpunit -c phpunit10.xml.dist --coverage-cache ./build/phpunit-cache env: PHPCS_VERSION: ${{ matrix.phpcs_version }} PHPCSUTILS_USE_CACHE: false diff --git a/composer.json b/composer.json index 04f124b9..8c0e8d45 100644 --- a/composer.json +++ b/composer.json @@ -66,11 +66,20 @@ "test": [ "@php ./vendor/phpunit/phpunit/phpunit --no-coverage" ], + "test10": [ + "@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist --no-coverage" + ], "coverage": [ "@php ./vendor/phpunit/phpunit/phpunit" ], + "coverage10": [ + "@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist" + ], "coverage-local": [ "@php ./vendor/phpunit/phpunit/phpunit --coverage-html ./build/coverage-html" + ], + "coverage-local10": [ + "@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist --coverage-html ./build/coverage-html" ] }, "config": { diff --git a/phpunit10.xml.dist b/phpunit10.xml.dist new file mode 100644 index 00000000..d6f05c43 --- /dev/null +++ b/phpunit10.xml.dist @@ -0,0 +1,75 @@ + + + + + + ./Tests/Internal/Cache/GetClearTest.php + ./Tests/Internal/Cache/SetTest.php + ./Tests/Internal/NoFileCache/GetClearTest.php + ./Tests/Internal/NoFileCache/SetTest.php + + + ./Tests/Utils/Namespaces/NamespaceTypeTest.php + + + ./Tests/ + + Tests/Internal/Cache/GetClearTest.php + Tests/Internal/Cache/SetTest.php + Tests/Internal/NoFileCache/GetClearTest.php + Tests/Internal/NoFileCache/SetTest.php + + Tests/Utils/Namespaces/NamespaceTypeTest.php + + + + + + compareWithPHPCS + + xtra + + + + + + + ./PHPCSUtils/ + + + + + + + + + + +