diff --git a/composer.json b/composer.json index 9de761e07b..a42168dc5f 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "ext-xmlwriter": "*" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + "phpunit/phpunit": "^8.0 || ^9.3.4" }, "bin": [ "bin/phpcbf", diff --git a/tests/AllTests.php b/tests/AllTests.php index 4fa41d9d9c..0002ab7daa 100644 --- a/tests/AllTests.php +++ b/tests/AllTests.php @@ -11,23 +11,7 @@ require_once 'Core/AllTests.php'; require_once 'Standards/AllSniffs.php'; - -// PHPUnit 7 made the TestSuite run() method incompatible with -// older PHPUnit versions due to return type hints, so maintain -// two different suite objects. -$phpunit7 = false; -if (class_exists('\PHPUnit\Runner\Version') === true) { - $version = \PHPUnit\Runner\Version::id(); - if (version_compare($version, '7.0', '>=') === true) { - $phpunit7 = true; - } -} - -if ($phpunit7 === true) { - include_once 'TestSuite7.php'; -} else { - include_once 'TestSuite.php'; -} +require_once 'TestSuite.php'; class PHP_CodeSniffer_AllTests { diff --git a/tests/Core/AbstractMethodUnitTest.php b/tests/Core/AbstractMethodUnitTest.php index c4c86c3e4e..e806a07622 100644 --- a/tests/Core/AbstractMethodUnitTest.php +++ b/tests/Core/AbstractMethodUnitTest.php @@ -42,11 +42,9 @@ abstract class AbstractMethodUnitTest extends TestCase * The test case file for a unit test class has to be in the same directory * directory and use the same file name as the test class, using the .inc extension. * - * @beforeClass - * * @return void */ - public static function initializeFile() + public static function setUpBeforeClass(): void { $_SERVER['argv'] = []; $config = new ConfigDouble(); @@ -67,20 +65,15 @@ public static function initializeFile() self::$phpcsFile = new DummyFile($contents, $ruleset, $config); self::$phpcsFile->parse(); - }//end initializeFile() + }//end setUpBeforeClass() /** * Clean up after finished test by resetting all static properties on the class to their default values. * - * Note: This is a PHPUnit cross-version compatible {@see \PHPUnit\Framework\TestCase::tearDownAfterClass()} - * method. - * - * @afterClass - * * @return void */ - public static function reset() + public static function tearDownAfterClass(): void { // Explicitly trigger __destruct() on the ConfigDouble to reset the Config statics. // The explicit method call prevents potential stray test-local references to the $config object @@ -93,7 +86,7 @@ public static function reset() self::$tabWidth = 4; self::$phpcsFile = null; - }//end reset() + }//end tearDownAfterClass() /** @@ -246,16 +239,8 @@ public static function getTargetTokenFromFile(File $phpcsFile, $commentString, $ */ public function expectRunTimeException($message) { - $exception = 'PHP_CodeSniffer\Exceptions\RuntimeException'; - - if (method_exists($this, 'expectException') === true) { - // PHPUnit 5+. - $this->expectException($exception); - $this->expectExceptionMessage($message); - } else { - // PHPUnit 4. - $this->setExpectedException($exception, $message); - } + $this->expectException('PHP_CodeSniffer\Exceptions\RuntimeException'); + $this->expectExceptionMessage($message); }//end expectRunTimeException() diff --git a/tests/Core/Autoloader/DetermineLoadedClassTest.php b/tests/Core/Autoloader/DetermineLoadedClassTest.php index e719c7eb74..c2dffde79d 100644 --- a/tests/Core/Autoloader/DetermineLoadedClassTest.php +++ b/tests/Core/Autoloader/DetermineLoadedClassTest.php @@ -24,15 +24,13 @@ final class DetermineLoadedClassTest extends TestCase /** * Load the test files. * - * @beforeClass - * * @return void */ - public static function includeFixture() + public static function setUpBeforeClass(): void { include __DIR__.'/TestFiles/Sub/C.inc'; - }//end includeFixture() + }//end setUpBeforeClass() /** diff --git a/tests/Core/Config/AbstractRealConfigTestCase.php b/tests/Core/Config/AbstractRealConfigTestCase.php index 6f5cd88443..e1a7975d4d 100644 --- a/tests/Core/Config/AbstractRealConfigTestCase.php +++ b/tests/Core/Config/AbstractRealConfigTestCase.php @@ -20,11 +20,9 @@ abstract class AbstractRealConfigTestCase extends TestCase /** * Set static properties in the Config class to prevent tests influencing each other. * - * @before - * * @return void */ - protected function setConfigStatics() + protected function setUp(): void { // Set to the property's default value to clear out potentially set values from other tests. self::setStaticConfigProperty('overriddenDefaults', []); @@ -35,32 +33,28 @@ protected function setConfigStatics() self::setStaticConfigProperty('configData', []); self::setStaticConfigProperty('configDataFile', ''); - }//end setConfigStatics() + }//end setUp() /** * Clean up after each finished test. * - * @after - * * @return void */ - protected function clearArgv() + protected function tearDown(): void { $_SERVER['argv'] = []; - }//end clearArgv() + }//end tearDown() /** * Reset the static properties in the Config class to their true defaults to prevent this class * from influencing other tests. * - * @afterClass - * * @return void */ - public static function resetConfigToDefaults() + public static function tearDownAfterClass(): void { self::setStaticConfigProperty('overriddenDefaults', []); self::setStaticConfigProperty('executablePaths', []); @@ -68,7 +62,7 @@ public static function resetConfigToDefaults() self::setStaticConfigProperty('configDataFile', null); $_SERVER['argv'] = []; - }//end resetConfigToDefaults() + }//end tearDownAfterClass() /** diff --git a/tests/Core/Config/GeneratorArgTest.php b/tests/Core/Config/GeneratorArgTest.php index 5def5f68f8..16135549f1 100644 --- a/tests/Core/Config/GeneratorArgTest.php +++ b/tests/Core/Config/GeneratorArgTest.php @@ -112,14 +112,8 @@ public function testInvalidGenerator($generatorName) $exception = 'PHP_CodeSniffer\Exceptions\DeepExitException'; $message = 'ERROR: "'.$generatorName.'" is not a valid generator. The following generators are supported: Text, HTML and Markdown.'; - if (method_exists($this, 'expectException') === true) { - // PHPUnit 5+. - $this->expectException($exception); - $this->expectExceptionMessage($message); - } else { - // PHPUnit 4. - $this->setExpectedException($exception, $message); - } + $this->expectException($exception); + $this->expectExceptionMessage($message); new ConfigDouble(["--generator={$generatorName}"]); diff --git a/tests/Core/Config/ReportWidthTest.php b/tests/Core/Config/ReportWidthTest.php index 28b996228d..71e20a9549 100644 --- a/tests/Core/Config/ReportWidthTest.php +++ b/tests/Core/Config/ReportWidthTest.php @@ -34,7 +34,7 @@ public function testReportWidthDefault() $config = new Config(['--standard=PSR1']); // Can't test the exact value as "auto" will resolve differently depending on the machine running the tests. - $this->assertTrue(is_int($config->reportWidth), 'Report width is not an integer'); + $this->assertIsInt($config->reportWidth, 'Report width is not an integer'); $this->assertGreaterThan(0, $config->reportWidth, 'Report width is not greater than 0'); }//end testReportWidthDefault() @@ -60,7 +60,7 @@ public function testReportWidthWillBeSetFromAutoWhenNotFoundInConfFile() $config = new Config(['--standard=PSR1']); // Can't test the exact value as "auto" will resolve differently depending on the machine running the tests. - $this->assertTrue(is_int($config->reportWidth), 'Report width is not an integer'); + $this->assertIsInt($config->reportWidth, 'Report width is not an integer'); $this->assertGreaterThan(0, $config->reportWidth, 'Report width is not greater than 0'); }//end testReportWidthWillBeSetFromAutoWhenNotFoundInConfFile() @@ -181,7 +181,7 @@ public function testReportWidthInputHandlingForAuto() $config->reportWidth = 'auto'; // Can't test the exact value as "auto" will resolve differently depending on the machine running the tests. - $this->assertTrue(is_int($config->reportWidth), 'Report width is not an integer'); + $this->assertIsInt($config->reportWidth, 'Report width is not an integer'); $this->assertGreaterThan(0, $config->reportWidth, 'Report width is not greater than 0'); }//end testReportWidthInputHandlingForAuto() diff --git a/tests/Core/Config/SniffsExcludeArgsTest.php b/tests/Core/Config/SniffsExcludeArgsTest.php index 59aabecc19..26bc7ebeb2 100644 --- a/tests/Core/Config/SniffsExcludeArgsTest.php +++ b/tests/Core/Config/SniffsExcludeArgsTest.php @@ -50,14 +50,8 @@ public function testInvalid($argument, $value, $errors, $suggestion) $message .= 'Run "phpcs --help" for usage information'.PHP_EOL; $message .= PHP_EOL; - if (method_exists($this, 'expectException') === true) { - // PHPUnit 5+. - $this->expectException($exception); - $this->expectExceptionMessage($message); - } else { - // PHPUnit 4. - $this->setExpectedException($exception, $message); - } + $this->expectException($exception); + $this->expectExceptionMessage($message); new ConfigDouble(["--$argument=$value"]); diff --git a/tests/Core/File/GetConditionTest.php b/tests/Core/File/GetConditionTest.php index 1f9d9a3454..c53a280b3a 100644 --- a/tests/Core/File/GetConditionTest.php +++ b/tests/Core/File/GetConditionTest.php @@ -123,11 +123,9 @@ final class GetConditionTest extends AbstractMethodUnitTest * Retrieves the test tokens and marker token stack pointer positions * only once and caches them as they won't change between the tests anyway. * - * @before - * * @return void */ - protected function setUpCaches() + protected function setUp(): void { if (empty(self::$testTokens) === true) { foreach (self::$testTargets as $targetToken => $marker) { @@ -141,7 +139,7 @@ protected function setUpCaches() } } - }//end setUpCaches() + }//end setUp() /** diff --git a/tests/Core/Filters/AbstractFilterTestCase.php b/tests/Core/Filters/AbstractFilterTestCase.php index 1087a22623..f95a51c0c7 100644 --- a/tests/Core/Filters/AbstractFilterTestCase.php +++ b/tests/Core/Filters/AbstractFilterTestCase.php @@ -39,29 +39,22 @@ abstract class AbstractFilterTestCase extends TestCase /** * Initialize the config and ruleset objects. * - * @beforeClass - * * @return void */ - public static function initializeConfigAndRuleset() + public static function setUpBeforeClass(): void { self::$config = new ConfigDouble(); self::$ruleset = new Ruleset(self::$config); - }//end initializeConfigAndRuleset() + }//end setUpBeforeClass() /** * Clean up after finished test by resetting all static properties on the Config class to their default values. * - * Note: This is a PHPUnit cross-version compatible {@see \PHPUnit\Framework\TestCase::tearDownAfterClass()} - * method. - * - * @afterClass - * * @return void */ - public static function reset() + public static function tearDownAfterClass(): void { // Explicitly trigger __destruct() on the ConfigDouble to reset the Config statics. // The explicit method call prevents potential stray test-local references to the $config object @@ -71,7 +64,7 @@ public static function reset() self::$config->__destruct(); } - }//end reset() + }//end tearDownAfterClass() /** @@ -96,24 +89,15 @@ protected function getMockedClass($className, array $constructorArgs=[], $method { $mockedObj = $this->getMockBuilder($className); - if (method_exists($mockedObj, 'onlyMethods') === true) { - // PHPUnit 8+. - if (is_array($methodsToMock) === true) { - return $mockedObj - ->setConstructorArgs($constructorArgs) - ->onlyMethods($methodsToMock) - ->getMock(); - } - - return $mockedObj->getMock() - ->setConstructorArgs($constructorArgs); + if (is_array($methodsToMock) === true) { + return $mockedObj + ->setConstructorArgs($constructorArgs) + ->onlyMethods($methodsToMock) + ->getMock(); } - // PHPUnit < 8. - return $mockedObj - ->setConstructorArgs($constructorArgs) - ->setMethods($methodsToMock) - ->getMock(); + return $mockedObj->getMock() + ->setConstructorArgs($constructorArgs); }//end getMockedClass() diff --git a/tests/Core/Filters/Filter/AcceptTest.php b/tests/Core/Filters/Filter/AcceptTest.php index d4da0a248c..f0723c134b 100644 --- a/tests/Core/Filters/Filter/AcceptTest.php +++ b/tests/Core/Filters/Filter/AcceptTest.php @@ -28,17 +28,15 @@ final class AcceptTest extends AbstractFilterTestCase /** * Initialize the config and ruleset objects based on the `AcceptTest.xml` ruleset file. * - * @beforeClass - * * @return void */ - public static function initializeConfigAndRuleset() + public static function setUpBeforeClass(): void { $standard = __DIR__.'/'.basename(__FILE__, '.php').'.xml'; self::$config = new ConfigDouble(["--standard=$standard", '--ignore=*/somethingelse/*']); self::$ruleset = new Ruleset(self::$config); - }//end initializeConfigAndRuleset() + }//end setUpBeforeClass() /** diff --git a/tests/Core/Fixer/GenerateDiffTest.php b/tests/Core/Fixer/GenerateDiffTest.php index b7902bbe61..940584e52f 100644 --- a/tests/Core/Fixer/GenerateDiffTest.php +++ b/tests/Core/Fixer/GenerateDiffTest.php @@ -46,11 +46,9 @@ final class GenerateDiffTest extends TestCase * prevent doing tab replacement when parsing the file. This is to allow for testing a * diff with tabs vs spaces (which wouldn't yield a diff if tabs had already been replaced). * - * @beforeClass - * * @return void */ - public static function initializeFile() + public static function setUpBeforeClass(): void { $config = new ConfigDouble(); $ruleset = new Ruleset($config); @@ -59,7 +57,7 @@ public static function initializeFile() self::$phpcsFile->parse(); self::$phpcsFile->fixer->startFile(self::$phpcsFile); - }//end initializeFile() + }//end setUpBeforeClass() /** diff --git a/tests/Core/Generators/GeneratorTest.php b/tests/Core/Generators/GeneratorTest.php index 8fb0ee2516..fb237b3a39 100644 --- a/tests/Core/Generators/GeneratorTest.php +++ b/tests/Core/Generators/GeneratorTest.php @@ -106,24 +106,13 @@ public function testGeneratingInvalidDocsResultsInException() $ruleset = new Ruleset($config); if (PHP_VERSION_ID >= 80000) { - $exception = 'TypeError'; - $message = 'processSniff(): Argument #1 ($doc) must be of type DOMNode, null given'; - } else if (PHP_VERSION_ID >= 70000) { - $exception = 'TypeError'; - $message = 'processSniff() must be an instance of DOMNode, null given'; + $message = 'processSniff(): Argument #1 ($doc) must be of type DOMNode, null given'; } else { - $exception = 'PHPUnit_Framework_Error'; - $message = 'processSniff() must be an instance of DOMNode, null given'; + $message = 'processSniff() must be an instance of DOMNode, null given'; } - if (method_exists($this, 'expectExceptionMessage') === true) { - // PHPUnit 5.2.0+. - $this->expectException($exception); - $this->expectExceptionMessage($message); - } else { - // Ancient PHPUnit. - $this->setExpectedException($exception, $message); - } + $this->expectException('TypeError'); + $this->expectExceptionMessage($message); $generator = new MockGenerator($ruleset); $generator->generate(); diff --git a/tests/Core/Ruleset/AbstractRulesetTestCase.php b/tests/Core/Ruleset/AbstractRulesetTestCase.php index 41c6394431..5b944bd25e 100644 --- a/tests/Core/Ruleset/AbstractRulesetTestCase.php +++ b/tests/Core/Ruleset/AbstractRulesetTestCase.php @@ -75,14 +75,8 @@ protected function assertXObjectNotHasProperty($propertyName, $object, $message= */ protected function expectRuntimeExceptionMessage($message) { - if (method_exists($this, 'expectException') === true) { - // PHPUnit 5+. - $this->expectException(self::RUNTIME_EXCEPTION); - $this->expectExceptionMessage($message); - } else { - // PHPUnit 4. - $this->setExpectedException(self::RUNTIME_EXCEPTION, $message); - } + $this->expectException(self::RUNTIME_EXCEPTION); + $this->expectExceptionMessage($message); }//end expectRuntimeExceptionMessage() @@ -100,13 +94,10 @@ protected function expectRuntimeExceptionRegex($regex) if (method_exists($this, 'expectExceptionMessageMatches') === true) { $this->expectException(self::RUNTIME_EXCEPTION); $this->expectExceptionMessageMatches($regex); - } else if (method_exists($this, 'expectExceptionMessageRegExp') === true) { + } else { // PHPUnit < 8.4.0. $this->expectException(self::RUNTIME_EXCEPTION); $this->expectExceptionMessageRegExp($regex); - } else { - // PHPUnit < 5.2.0. - $this->setExpectedExceptionRegExp(self::RUNTIME_EXCEPTION, $regex); } }//end expectRuntimeExceptionRegex() diff --git a/tests/Core/Ruleset/ExpandRulesetReferenceHomePathTest.php b/tests/Core/Ruleset/ExpandRulesetReferenceHomePathTest.php index 10a4dd9813..80fa9e0a03 100644 --- a/tests/Core/Ruleset/ExpandRulesetReferenceHomePathTest.php +++ b/tests/Core/Ruleset/ExpandRulesetReferenceHomePathTest.php @@ -32,25 +32,21 @@ final class ExpandRulesetReferenceHomePathTest extends AbstractRulesetTestCase /** * Store the user's home path. * - * @beforeClass - * * @return void */ - public static function storeHomePath() + public static function setUpBeforeClass(): void { self::$homepath = getenv('HOME'); - }//end storeHomePath() + }//end setUpBeforeClass() /** * Restore the user's home path environment variable in case the test changed it or created it. * - * @afterClass - * * @return void */ - public static function restoreHomePath() + public static function tearDownAfterClass(): void { if (is_string(self::$homepath) === true) { putenv('HOME='.self::$homepath); @@ -59,22 +55,20 @@ public static function restoreHomePath() putenv('HOME'); } - }//end restoreHomePath() + }//end tearDownAfterClass() /** * Set the home path to an alternative location. * - * @before - * * @return void */ - protected function setHomePath() + protected function setUp(): void { $fakeHomePath = __DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'FakeHomePath'; putenv("HOME=$fakeHomePath"); - }//end setHomePath() + }//end setUp() /** diff --git a/tests/Core/Ruleset/GetIgnorePatternsTest.php b/tests/Core/Ruleset/GetIgnorePatternsTest.php index ae6b8bea50..23fe0532c9 100644 --- a/tests/Core/Ruleset/GetIgnorePatternsTest.php +++ b/tests/Core/Ruleset/GetIgnorePatternsTest.php @@ -32,18 +32,16 @@ final class GetIgnorePatternsTest extends TestCase /** * Initialize the config and ruleset objects for this test. * - * @beforeClass - * * @return void */ - public static function initializeConfigAndRuleset() + public static function setUpBeforeClass(): void { // Set up the ruleset. $standard = __DIR__."/GetIgnorePatternsTest.xml"; $config = new ConfigDouble(["--standard=$standard"]); self::$ruleset = new Ruleset($config); - }//end initializeConfigAndRuleset() + }//end setUpBeforeClass() /** diff --git a/tests/Core/Ruleset/GetIncludePatternsTest.php b/tests/Core/Ruleset/GetIncludePatternsTest.php index a38401b614..b67c189e11 100644 --- a/tests/Core/Ruleset/GetIncludePatternsTest.php +++ b/tests/Core/Ruleset/GetIncludePatternsTest.php @@ -32,18 +32,16 @@ final class GetIncludePatternsTest extends TestCase /** * Initialize the config and ruleset objects for this test. * - * @beforeClass - * * @return void */ - public static function initializeConfigAndRuleset() + public static function setUpBeforeClass(): void { // Set up the ruleset. $standard = __DIR__."/GetIncludePatternsTest.xml"; $config = new ConfigDouble(["--standard=$standard"]); self::$ruleset = new Ruleset($config); - }//end initializeConfigAndRuleset() + }//end setUpBeforeClass() /** diff --git a/tests/Core/Ruleset/PopulateTokenListenersTest.php b/tests/Core/Ruleset/PopulateTokenListenersTest.php index db494b9590..68a30e3a4b 100644 --- a/tests/Core/Ruleset/PopulateTokenListenersTest.php +++ b/tests/Core/Ruleset/PopulateTokenListenersTest.php @@ -35,11 +35,9 @@ final class PopulateTokenListenersTest extends AbstractRulesetTestCase /** * Initialize the config and ruleset objects for this test only once (but do allow recording code coverage). * - * @before - * * @return void */ - protected function initializeConfigAndRuleset() + protected function setUp(): void { if (isset(self::$ruleset) === false) { // Set up the ruleset. @@ -48,7 +46,7 @@ protected function initializeConfigAndRuleset() self::$ruleset = new Ruleset($config); } - }//end initializeConfigAndRuleset() + }//end setUp() /** @@ -85,7 +83,7 @@ public function testSniffWithRegisterMethodReturningEmptyArrayIsSilentlyIgnored( $target = 'Fixtures\\TestStandard\\Sniffs\\ValidSniffs\\RegisterEmptyArraySniff'; foreach (self::$ruleset->tokenListeners as $token => $listeners) { - $this->assertTrue(is_array($listeners), 'No listeners registered for token'.Tokens::tokenName($token)); + $this->assertIsArray($listeners, 'No listeners registered for token'.Tokens::tokenName($token)); $this->assertArrayNotHasKey( $target, $listeners, @@ -174,7 +172,7 @@ public function testRegistersWhenADeprecatedSniffIsLoaded() // Only verify there is one deprecated sniff registered. // There are other tests which test the deprecated sniff handling in more detail. - $this->assertTrue(is_array($actualValue)); + $this->assertIsArray($actualValue); $this->assertCount(1, $actualValue); }//end testRegistersWhenADeprecatedSniffIsLoaded() @@ -263,7 +261,7 @@ public static function dataTriggersPropertySettingWhenPropertiesProvided() public function testSetsClassAndSourceIndexes() { foreach (self::$ruleset->tokenListeners as $token => $listeners) { - $this->assertTrue(is_array($listeners), 'No listeners registered for token'.Tokens::tokenName($token)); + $this->assertIsArray($listeners, 'No listeners registered for token'.Tokens::tokenName($token)); foreach ($listeners as $className => $details) { $this->assertArrayHasKey( @@ -284,8 +282,8 @@ public function testSetsClassAndSourceIndexes() sprintf('"source" key missing for sniff class %s for token %s', $className, Tokens::tokenName($token)) ); - $this->assertTrue( - is_string($details['source']), + $this->assertIsString( + $details['source'], sprintf('Value for "source" key is not a string for token %s', Tokens::tokenName($token)) ); @@ -312,7 +310,7 @@ public function testSetsIncludePatternsToEmptyArrayByDefault() $exclude = 'PHP_CodeSniffer\\Standards\\Generic\\Sniffs\\NamingConventions\\UpperCaseConstantNameSniff'; foreach (self::$ruleset->tokenListeners as $token => $listeners) { - $this->assertTrue(is_array($listeners), 'No listeners registered for token'.Tokens::tokenName($token)); + $this->assertIsArray($listeners, 'No listeners registered for token'.Tokens::tokenName($token)); foreach ($listeners as $className => $details) { if ($className === $exclude) { @@ -347,7 +345,7 @@ public function testSetsIgnorePatternsToEmptyArrayByDefault() $exclude = 'PHP_CodeSniffer\\Standards\\PSR1\\Sniffs\\Files\\SideEffectsSniff'; foreach (self::$ruleset->tokenListeners as $token => $listeners) { - $this->assertTrue(is_array($listeners), 'No listeners registered for token'.Tokens::tokenName($token)); + $this->assertIsArray($listeners, 'No listeners registered for token'.Tokens::tokenName($token)); foreach ($listeners as $className => $details) { if ($className === $exclude) { diff --git a/tests/Core/Ruleset/ProcessRuleShouldProcessElementTest.php b/tests/Core/Ruleset/ProcessRuleShouldProcessElementTest.php index c6c9e2160b..2ec67a9e46 100644 --- a/tests/Core/Ruleset/ProcessRuleShouldProcessElementTest.php +++ b/tests/Core/Ruleset/ProcessRuleShouldProcessElementTest.php @@ -33,11 +33,9 @@ final class ProcessRuleShouldProcessElementTest extends AbstractRulesetTestCase /** * Initialize the config and ruleset objects for this test. * - * @before - * * @return void */ - protected function initializeConfigAndRuleset() + protected function setUp(): void { if (isset(self::$ruleset) === false) { // Set up the ruleset. @@ -46,7 +44,7 @@ protected function initializeConfigAndRuleset() self::$ruleset = new Ruleset($config); } - }//end initializeConfigAndRuleset() + }//end setUp() /** @@ -618,7 +616,7 @@ private function verifyShouldProcessElement($expected) private function assertHasRulesetDirective($sniffCode, $key) { $this->assertArrayHasKey($sniffCode, self::$ruleset->ruleset, "Sniff $sniffCode not registered"); - $this->assertTrue(is_array(self::$ruleset->ruleset[$sniffCode]), "Sniff $sniffCode is not an array"); + $this->assertIsArray(self::$ruleset->ruleset[$sniffCode], "Sniff $sniffCode is not an array"); $this->assertArrayHasKey($key, self::$ruleset->ruleset[$sniffCode], "Directive $key not registered for sniff $sniffCode"); }//end assertHasRulesetDirective() diff --git a/tests/Core/Ruleset/ProcessRulesetShouldProcessElementTest.php b/tests/Core/Ruleset/ProcessRulesetShouldProcessElementTest.php index 1f0780c44b..59ab1d675e 100644 --- a/tests/Core/Ruleset/ProcessRulesetShouldProcessElementTest.php +++ b/tests/Core/Ruleset/ProcessRulesetShouldProcessElementTest.php @@ -52,11 +52,9 @@ final class ProcessRulesetShouldProcessElementTest extends TestCase /** * Store the original ini values to allow for restoring them after the tests. * - * @beforeClass - * * @return void */ - public static function saveOriginalIniValues() + public static function setUpBeforeClass(): void { foreach (self::$originalIniValues as $name => $null) { $value = ini_get($name); @@ -65,17 +63,15 @@ public static function saveOriginalIniValues() } } - }//end saveOriginalIniValues() + }//end setUpBeforeClass() /** * Initialize the config and ruleset objects for this test only once (but do allow recording code coverage). * - * @before - * * @return void */ - protected function initializeConfigAndRuleset() + protected function setUp(): void { if (isset(self::$ruleset) === false) { // Set up the ruleset. @@ -84,17 +80,15 @@ protected function initializeConfigAndRuleset() self::$ruleset = new Ruleset(self::$config); } - }//end initializeConfigAndRuleset() + }//end setUp() /** * Destroy the Config object and restore the ini values after the tests. * - * @afterClass - * * @return void */ - public static function restoreOriginalValues() + public static function tearDownAfterClass(): void { // Explicitly trigger __destruct() on the ConfigDouble to reset the Config statics. // The explicit method call prevents potential stray test-local references to the $config object @@ -112,7 +106,7 @@ public static function restoreOriginalValues() ini_set($name, $value); } - }//end restoreOriginalValues() + }//end tearDownAfterClass() /** diff --git a/tests/Core/Ruleset/ProcessRulesetTest.php b/tests/Core/Ruleset/ProcessRulesetTest.php index 3ef1f67688..2e5f705bde 100644 --- a/tests/Core/Ruleset/ProcessRulesetTest.php +++ b/tests/Core/Ruleset/ProcessRulesetTest.php @@ -159,13 +159,13 @@ public function testIncludeSingleErrorCode() $sniffCode = 'Generic.PHP.RequireStrictTypes'; $this->assertArrayHasKey($sniffCode, $ruleset->ruleset, "Sniff $sniffCode not registered"); - $this->assertTrue(is_array($ruleset->ruleset[$sniffCode]), "Sniff $sniffCode is not an array"); + $this->assertIsArray($ruleset->ruleset[$sniffCode], "Sniff $sniffCode is not an array"); $this->assertArrayHasKey($key, $ruleset->ruleset[$sniffCode], "Directive $key not registered for sniff $sniffCode"); $this->assertSame(0, $ruleset->ruleset[$sniffCode][$key], "$key has unexpected value for sniff $sniffCode"); $sniffCode = 'Generic.PHP.RequireStrictTypes.MissingDeclaration'; $this->assertArrayHasKey($sniffCode, $ruleset->ruleset, "Sniff $sniffCode not registered"); - $this->assertTrue(is_array($ruleset->ruleset[$sniffCode]), "Sniff $sniffCode is not an array"); + $this->assertIsArray($ruleset->ruleset[$sniffCode], "Sniff $sniffCode is not an array"); $this->assertArrayHasKey($key, $ruleset->ruleset[$sniffCode], "Directive $key not registered for sniff $sniffCode"); $this->assertSame(5, $ruleset->ruleset[$sniffCode][$key], "$key has unexpected value for sniff $sniffCode"); @@ -187,19 +187,19 @@ public function testErrorCodeIncludeAfterExclude() $sniffCode = 'PEAR.Files.IncludingFile'; $this->assertArrayHasKey($sniffCode, $ruleset->ruleset, "Sniff $sniffCode not registered"); - $this->assertTrue(is_array($ruleset->ruleset[$sniffCode]), "Sniff $sniffCode is not an array"); + $this->assertIsArray($ruleset->ruleset[$sniffCode], "Sniff $sniffCode is not an array"); $this->assertArrayHasKey($key, $ruleset->ruleset[$sniffCode], "Directive $key not registered for sniff $sniffCode"); $this->assertSame(0, $ruleset->ruleset[$sniffCode][$key], "$key has unexpected value for sniff $sniffCode"); $sniffCode = 'PEAR.Files.IncludingFile.BracketsNotRequired'; $this->assertArrayHasKey($sniffCode, $ruleset->ruleset, "Sniff $sniffCode not registered"); - $this->assertTrue(is_array($ruleset->ruleset[$sniffCode]), "Sniff $sniffCode is not an array"); + $this->assertIsArray($ruleset->ruleset[$sniffCode], "Sniff $sniffCode is not an array"); $this->assertArrayHasKey($key, $ruleset->ruleset[$sniffCode], "Directive $key not registered for sniff $sniffCode"); $this->assertSame(5, $ruleset->ruleset[$sniffCode][$key], "$key has unexpected value for sniff $sniffCode"); $sniffCode = 'PEAR.Files.IncludingFile.UseRequire'; $this->assertArrayHasKey($sniffCode, $ruleset->ruleset, "Sniff $sniffCode not registered"); - $this->assertTrue(is_array($ruleset->ruleset[$sniffCode]), "Sniff $sniffCode is not an array"); + $this->assertIsArray($ruleset->ruleset[$sniffCode], "Sniff $sniffCode is not an array"); $this->assertArrayHasKey($key, $ruleset->ruleset[$sniffCode], "Directive $key not registered for sniff $sniffCode"); $this->assertSame(5, $ruleset->ruleset[$sniffCode][$key], "$key has unexpected value for sniff $sniffCode"); diff --git a/tests/Core/Ruleset/RegisterSniffsRemovedTokenizersTest.php b/tests/Core/Ruleset/RegisterSniffsRemovedTokenizersTest.php index 4d12bf43f7..9ffd0a6404 100644 --- a/tests/Core/Ruleset/RegisterSniffsRemovedTokenizersTest.php +++ b/tests/Core/Ruleset/RegisterSniffsRemovedTokenizersTest.php @@ -32,17 +32,15 @@ final class RegisterSniffsRemovedTokenizersTest extends AbstractRulesetTestCase /** * Initialize the config and ruleset objects for this test. * - * @beforeClass - * * @return void */ - public static function initializeConfig() + public static function setUpBeforeClass(): void { // Set up the ruleset. $standard = __DIR__.'/RegisterSniffsRemovedTokenizersTest.xml'; self::$config = new ConfigDouble(["--standard=$standard"]); - }//end initializeConfig() + }//end setUpBeforeClass() /** diff --git a/tests/Core/Ruleset/RegisterSniffsTest.php b/tests/Core/Ruleset/RegisterSniffsTest.php index 1ed3ee1821..37fe2b500d 100644 --- a/tests/Core/Ruleset/RegisterSniffsTest.php +++ b/tests/Core/Ruleset/RegisterSniffsTest.php @@ -62,11 +62,9 @@ final class RegisterSniffsTest extends TestCase /** * Initialize the config and ruleset objects which will be used for some of these tests. * - * @beforeClass - * * @return void */ - public static function initializeConfigAndRuleset() + public static function setUpBeforeClass(): void { // Set up the ruleset. $config = new ConfigDouble(['--standard=PSR1']); @@ -85,7 +83,7 @@ public static function initializeConfigAndRuleset() self::$psr1SniffAbsolutePaths = self::relativeToAbsoluteSniffFiles($standardsDir, self::$psr1SniffFiles); - }//end initializeConfigAndRuleset() + }//end setUpBeforeClass() /** @@ -113,16 +111,14 @@ public static function relativeToAbsoluteSniffFiles($baseDir, $relativePaths) /** * Clear out the Ruleset::$sniffs property. * - * @before - * * @return void */ - protected function clearOutSniffs() + protected function setUp(): void { // Clear out the Ruleset::$sniffs property. self::$ruleset->sniffs = []; - }//end clearOutSniffs() + }//end setUp() /** diff --git a/tests/Core/Ruleset/RuleInclusionAbsoluteLinuxTest.php b/tests/Core/Ruleset/RuleInclusionAbsoluteLinuxTest.php index 6eb0d1a208..80eb4b7ae9 100644 --- a/tests/Core/Ruleset/RuleInclusionAbsoluteLinuxTest.php +++ b/tests/Core/Ruleset/RuleInclusionAbsoluteLinuxTest.php @@ -46,11 +46,9 @@ final class RuleInclusionAbsoluteLinuxTest extends TestCase /** * Initialize the config and ruleset objects. * - * @before - * * @return void */ - protected function initializeConfigAndRuleset() + protected function setUp(): void { $this->standard = __DIR__.'/'.basename(__FILE__, '.php').'.xml'; $repoRootDir = dirname(dirname(dirname(__DIR__))); @@ -74,21 +72,19 @@ protected function initializeConfigAndRuleset() $config = new ConfigDouble(["--standard={$this->standard}"]); $this->ruleset = new Ruleset($config); - }//end initializeConfigAndRuleset() + }//end setUp() /** * Reset ruleset file. * - * @after - * * @return void */ - protected function resetRuleset() + protected function tearDown(): void { file_put_contents($this->standard, $this->contents); - }//end resetRuleset() + }//end tearDown() /** diff --git a/tests/Core/Ruleset/RuleInclusionAbsoluteWindowsTest.php b/tests/Core/Ruleset/RuleInclusionAbsoluteWindowsTest.php index fc5d654885..73647cad0c 100644 --- a/tests/Core/Ruleset/RuleInclusionAbsoluteWindowsTest.php +++ b/tests/Core/Ruleset/RuleInclusionAbsoluteWindowsTest.php @@ -17,7 +17,7 @@ * Tests for the \PHP_CodeSniffer\Ruleset class using a Windows-style absolute path to include a sniff. * * @covers \PHP_CodeSniffer\Ruleset - * @requires OS ^WIN.*. + * @requires OSFAMILY Windows * @group Windows */ final class RuleInclusionAbsoluteWindowsTest extends TestCase @@ -48,11 +48,9 @@ final class RuleInclusionAbsoluteWindowsTest extends TestCase /** * Initialize the config and ruleset objects. * - * @before - * * @return void */ - protected function initializeConfigAndRuleset() + protected function setUp(): void { $this->standard = __DIR__.'/'.basename(__FILE__, '.php').'.xml'; $repoRootDir = dirname(dirname(dirname(__DIR__))); @@ -71,21 +69,19 @@ protected function initializeConfigAndRuleset() $config = new ConfigDouble(["--standard={$this->standard}"]); $this->ruleset = new Ruleset($config); - }//end initializeConfigAndRuleset() + }//end setUp() /** * Reset ruleset file. * - * @after - * * @return void */ - protected function resetRuleset() + protected function tearDown(): void { file_put_contents($this->standard, $this->contents); - }//end resetRuleset() + }//end tearDown() /** diff --git a/tests/Core/Ruleset/RuleInclusionTest.php b/tests/Core/Ruleset/RuleInclusionTest.php index d91a6c2590..9c31d1b79a 100644 --- a/tests/Core/Ruleset/RuleInclusionTest.php +++ b/tests/Core/Ruleset/RuleInclusionTest.php @@ -46,11 +46,9 @@ final class RuleInclusionTest extends AbstractRulesetTestCase /** * Initialize the config and ruleset objects based on the `RuleInclusionTest.xml` ruleset file. * - * @before - * * @return void */ - protected function initializeConfigAndRuleset() + protected function setUp(): void { if (self::$standard === '') { $standard = __DIR__.'/'.basename(__FILE__, '.php').'.xml'; @@ -78,21 +76,19 @@ protected function initializeConfigAndRuleset() self::$ruleset = new Ruleset($config); }//end if - }//end initializeConfigAndRuleset() + }//end setUp() /** * Reset ruleset file. * - * @after - * * @return void */ - public function resetRuleset() + public function tearDown(): void { file_put_contents(self::$standard, self::$contents); - }//end resetRuleset() + }//end tearDown() /** diff --git a/tests/Core/Runner/PrintProgressTest.php b/tests/Core/Runner/PrintProgressTest.php index 93535417e0..82ab98fa7d 100644 --- a/tests/Core/Runner/PrintProgressTest.php +++ b/tests/Core/Runner/PrintProgressTest.php @@ -54,11 +54,9 @@ final class PrintProgressTest extends TestCase /** * Create some re-usable objects for use in the tests. * - * @beforeClass - * * @return void */ - public static function initializeConfigRulesetRunner() + public static function setUpBeforeClass(): void { self::$config = new ConfigDouble(['-p']); self::$config->standards = ['Generic']; @@ -73,32 +71,28 @@ public static function initializeConfigRulesetRunner() self::$fileWithoutErrorsOrWarnings = new DummyFile($content, self::$ruleset, self::$config); self::$fileWithoutErrorsOrWarnings->process(); - }//end initializeConfigRulesetRunner() + }//end setUpBeforeClass() /** * Reset some flags between tests. * - * @after - * * @return void */ - protected function resetObjectFlags() + protected function tearDown(): void { self::$config->showProgress = true; self::$fileWithoutErrorsOrWarnings->ignored = false; - }//end resetObjectFlags() + }//end tearDown() /** * Destroy the Config object after the test to reset statics. * - * @afterClass - * * @return void */ - public static function reset() + public static function tearDownAfterClass(): void { // Explicitly trigger __destruct() on the ConfigDouble to reset the Config statics. // The explicit method call prevents potential stray test-local references to the $config object @@ -106,7 +100,7 @@ public static function reset() // automagically triggered when this object is destroyed, but we can't definitively rely on that). self::$config->__destruct(); - }//end reset() + }//end tearDownAfterClass() /** diff --git a/tests/Core/Sniffs/AbstractArraySniffTest.php b/tests/Core/Sniffs/AbstractArraySniffTest.php index 993603a53b..d5a6f501e6 100644 --- a/tests/Core/Sniffs/AbstractArraySniffTest.php +++ b/tests/Core/Sniffs/AbstractArraySniffTest.php @@ -36,16 +36,14 @@ final class AbstractArraySniffTest extends AbstractMethodUnitTest * The test case file for a unit test class has to be in the same directory * directory and use the same file name as the test class, using the .inc extension. * - * @beforeClass - * * @return void */ - public static function initializeFile() + public static function setUpBeforeClass(): void { self::$sniff = new AbstractArraySniffTestable(); - parent::initializeFile(); + parent::setUpBeforeClass(); - }//end initializeFile() + }//end setUpBeforeClass() /** diff --git a/tests/Core/Tokenizers/AbstractTokenizerTestCase.php b/tests/Core/Tokenizers/AbstractTokenizerTestCase.php index ac9f8e3e9f..4c1fb1a8a3 100644 --- a/tests/Core/Tokenizers/AbstractTokenizerTestCase.php +++ b/tests/Core/Tokenizers/AbstractTokenizerTestCase.php @@ -45,11 +45,9 @@ abstract class AbstractTokenizerTestCase extends TestCase * The test case file for a unit test class has to be in the same directory * directory and use the same file name as the test class, using the .inc extension. * - * @before - * * @return void */ - protected function initializeFile() + protected function setUp(): void { if (isset($this->phpcsFile) === false) { $_SERVER['argv'] = []; @@ -73,7 +71,7 @@ protected function initializeFile() $this->phpcsFile->parse(); }//end if - }//end initializeFile() + }//end setUp() /** diff --git a/tests/Core/Tokenizers/PHP/GotoLabelTest.php b/tests/Core/Tokenizers/PHP/GotoLabelTest.php index 09bb6fe2fd..93be957e13 100644 --- a/tests/Core/Tokenizers/PHP/GotoLabelTest.php +++ b/tests/Core/Tokenizers/PHP/GotoLabelTest.php @@ -36,7 +36,7 @@ public function testGotoStatement($testMarker, $testContent) $label = $this->getTargetToken($testMarker, T_STRING); - $this->assertTrue(is_int($label)); + $this->assertIsInt($label); $this->assertSame($testContent, $tokens[$label]['content']); }//end testGotoStatement() @@ -89,7 +89,7 @@ public function testGotoDeclaration($testMarker, $testContent) $label = $this->getTargetToken($testMarker, T_GOTO_LABEL); - $this->assertTrue(is_int($label)); + $this->assertIsInt($label); $this->assertSame($testContent, $tokens[$label]['content']); }//end testGotoDeclaration() diff --git a/tests/Core/Tokenizers/PHP/OtherContextSensitiveKeywordsTest.php b/tests/Core/Tokenizers/PHP/OtherContextSensitiveKeywordsTest.php index 35c8997148..d49fcfaa16 100644 --- a/tests/Core/Tokenizers/PHP/OtherContextSensitiveKeywordsTest.php +++ b/tests/Core/Tokenizers/PHP/OtherContextSensitiveKeywordsTest.php @@ -25,15 +25,13 @@ final class OtherContextSensitiveKeywordsTest extends AbstractTokenizerTestCase * Clear the "resolved tokens" cache before running this test as otherwise the code * under test may not be run during the test. * - * @beforeClass - * * @return void */ - public static function clearTokenCache() + public static function setUpBeforeClass(): void { parent::clearResolvedTokensCache(); - }//end clearTokenCache() + }//end setUpBeforeClass() /** diff --git a/tests/Core/Tokenizers/PHP/ResolveSimpleTokenTest.php b/tests/Core/Tokenizers/PHP/ResolveSimpleTokenTest.php index 06a130c249..84ac47f5e1 100644 --- a/tests/Core/Tokenizers/PHP/ResolveSimpleTokenTest.php +++ b/tests/Core/Tokenizers/PHP/ResolveSimpleTokenTest.php @@ -25,15 +25,13 @@ final class ResolveSimpleTokenTest extends AbstractTokenizerTestCase * Clear the "resolved tokens" cache before running this test as otherwise the code * under test may not be run during the test. * - * @beforeClass - * * @return void */ - public static function clearTokenCache() + public static function setUpBeforeClass(): void { parent::clearResolvedTokensCache(); - }//end clearTokenCache() + }//end setUpBeforeClass() /** diff --git a/tests/Core/Tokenizers/Tokenizer/ReplaceTabsInTokenMiscTest.php b/tests/Core/Tokenizers/Tokenizer/ReplaceTabsInTokenMiscTest.php index f4bd711a6f..18b9ac548c 100644 --- a/tests/Core/Tokenizers/Tokenizer/ReplaceTabsInTokenMiscTest.php +++ b/tests/Core/Tokenizers/Tokenizer/ReplaceTabsInTokenMiscTest.php @@ -44,7 +44,7 @@ public function testTabWidthNotSet() $target = $phpcsFile->findNext(T_WHITESPACE, 0); // Verify initial state. - $this->assertTrue(is_int($target), 'Target token was not found'); + $this->assertIsInt($target, 'Target token was not found'); $this->assertSame(' ', $tokens[$target]['content'], 'Content after initial parsing does not contain tabs'); $this->assertSame(2, $tokens[$target]['length'], 'Length after initial parsing is not as expected'); $this->assertArrayNotHasKey('orig_content', $tokens[$target], "Key 'orig_content' found in the initial token array."); @@ -82,7 +82,7 @@ public function testLengthSettingRespectsEncoding() $tokens = $phpcsFile->getTokens(); $target = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, 0); - $this->assertTrue(is_int($target), 'Target token was not found'); + $this->assertIsInt($target, 'Target token was not found'); $this->assertSame("'пасха пасха'", $tokens[$target]['content'], 'Content is not as expected'); $this->assertSame(17, $tokens[$target]['length'], 'Length is not as expected'); $this->assertArrayHasKey('orig_content', $tokens[$target], "Key 'orig_content' not found in the token array."); @@ -114,7 +114,7 @@ public function testLengthSettingFallsBackToBytesWhenTextContainsIllegalChars() $tokens = $phpcsFile->getTokens(); $target = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, 0); - $this->assertTrue(is_int($target), 'Target token was not found'); + $this->assertIsInt($target, 'Target token was not found'); $this->assertSame(11, $tokens[$target]['length'], 'Length is not as expected'); $this->assertArrayHasKey('orig_content', $tokens[$target], "Key 'orig_content' not found in the token array."); diff --git a/tests/Core/Tokenizers/Tokenizer/ReplaceTabsInTokenTestCase.php b/tests/Core/Tokenizers/Tokenizer/ReplaceTabsInTokenTestCase.php index 93964e1607..883c0779ee 100644 --- a/tests/Core/Tokenizers/Tokenizer/ReplaceTabsInTokenTestCase.php +++ b/tests/Core/Tokenizers/Tokenizer/ReplaceTabsInTokenTestCase.php @@ -31,13 +31,11 @@ abstract class ReplaceTabsInTokenTestCase extends AbstractTokenizerTestCase /** * Make a copy the test case file we want to use for this test (as the file will be used by multiple tests). * - * @beforeClass - * * @return void * * @throws \Exception In case the base test case file would not be available. */ - public static function copyCaseFile() + public static function setUpBeforeClass(): void { $relativeCN = str_replace(__NAMESPACE__.'\\', '', get_called_class()); self::$caseFileName = __DIR__.DIRECTORY_SEPARATOR.$relativeCN.'.inc'; @@ -51,21 +49,19 @@ public static function copyCaseFile() throw new Exception(sprintf('Failed to copy test case file "ReplaceTabsInTokenTest.inc" to %s', self::$caseFileName)); } - }//end copyCaseFile() + }//end setUpBeforeClass() /** * Delete the copied test case file after use. * - * @afterClass - * * @return void */ - public static function deleteCaseFile() + public static function tearDownAfterClass(): void { @unlink(self::$caseFileName); - }//end deleteCaseFile() + }//end tearDownAfterClass() /** diff --git a/tests/Core/Util/Common/GetSniffCodeTest.php b/tests/Core/Util/Common/GetSniffCodeTest.php index 4b4083dedf..a2e92a923f 100644 --- a/tests/Core/Util/Common/GetSniffCodeTest.php +++ b/tests/Core/Util/Common/GetSniffCodeTest.php @@ -35,14 +35,8 @@ public function testGetSniffCodeThrowsExceptionOnInvalidInput($input) $exception = 'InvalidArgumentException'; $message = 'The $sniffClass parameter must be a non-empty string'; - if (method_exists($this, 'expectException') === true) { - // PHPUnit 5+. - $this->expectException($exception); - $this->expectExceptionMessage($message); - } else { - // PHPUnit 4. - $this->setExpectedException($exception, $message); - } + $this->expectException($exception); + $this->expectExceptionMessage($message); Common::getSniffCode($input); @@ -81,14 +75,8 @@ public function testGetSniffCodeThrowsExceptionOnInputWhichIsNotASniffTestClass( $exception = 'InvalidArgumentException'; $message = 'The $sniffClass parameter was not passed a fully qualified sniff(test) class name. Received:'; - if (method_exists($this, 'expectException') === true) { - // PHPUnit 5+. - $this->expectException($exception); - $this->expectExceptionMessage($message); - } else { - // PHPUnit 4. - $this->setExpectedException($exception, $message); - } + $this->expectException($exception); + $this->expectExceptionMessage($message); Common::getSniffCode($input); diff --git a/tests/Core/Util/Common/PrepareForOutputTest.php b/tests/Core/Util/Common/PrepareForOutputTest.php index 8eb2fc22f9..3f4d595a4b 100644 --- a/tests/Core/Util/Common/PrepareForOutputTest.php +++ b/tests/Core/Util/Common/PrepareForOutputTest.php @@ -49,7 +49,7 @@ public function testPrepareForOutput($content, $exclude, $expected, $expectedWin * @param string $expected Expected function output (unused in this test). * @param string $expectedWin Expected function output on Windows. * - * @requires OS ^WIN.*. + * @requires OSFAMILY Windows * @dataProvider dataPrepareForOutput * * @return void diff --git a/tests/Core/Util/Help/HelpTest.php b/tests/Core/Util/Help/HelpTest.php index b3d51a5c78..8249b3d2a9 100644 --- a/tests/Core/Util/Help/HelpTest.php +++ b/tests/Core/Util/Help/HelpTest.php @@ -150,14 +150,8 @@ public function testConstructorInvalidArgumentException() $exception = 'InvalidArgumentException'; $message = 'The $shortOptions parameter must be a string'; - if (method_exists($this, 'expectException') === true) { - // PHPUnit 5+. - $this->expectException($exception); - $this->expectExceptionMessage($message); - } else { - // PHPUnit 4. - $this->setExpectedException($exception, $message); - } + $this->expectException($exception); + $this->expectExceptionMessage($message); new Help(new ConfigDouble(), [], []); diff --git a/tests/Core/Util/MessageCollector/MessageCollectorTest.php b/tests/Core/Util/MessageCollector/MessageCollectorTest.php index faa98ca415..0f69967784 100644 --- a/tests/Core/Util/MessageCollector/MessageCollectorTest.php +++ b/tests/Core/Util/MessageCollector/MessageCollectorTest.php @@ -33,14 +33,9 @@ public function testAddingNonStringMessageResultsInException($message) { $exception = 'InvalidArgumentException'; $exceptionMsg = 'The $message should be of type string. Received: '; - if (method_exists($this, 'expectException') === true) { - // PHPUnit 5+. - $this->expectException($exception); - $this->expectExceptionMessage($exceptionMsg); - } else { - // PHPUnit 4. - $this->setExpectedException($exception, $exceptionMsg); - } + + $this->expectException($exception); + $this->expectExceptionMessage($exceptionMsg); $msgCollector = new MessageCollector(); $msgCollector->add($message); @@ -80,14 +75,9 @@ public function testAddingMessageWithUnsupportedMessageTypeResultsInException($t { $exception = 'InvalidArgumentException'; $exceptionMsg = 'The message $type should be one of the predefined MessageCollector constants. Received: '; - if (method_exists($this, 'expectException') === true) { - // PHPUnit 5+. - $this->expectException($exception); - $this->expectExceptionMessage($exceptionMsg); - } else { - // PHPUnit 4. - $this->setExpectedException($exception, $exceptionMsg); - } + + $this->expectException($exception); + $this->expectExceptionMessage($exceptionMsg); $msgCollector = new MessageCollector(); $msgCollector->add('Message', $type); @@ -309,14 +299,9 @@ public static function dataDisplayingNonBlockingMessages() public function testDisplayingBlockingErrors($messages, $expected) { $exception = 'PHP_CodeSniffer\Exceptions\RuntimeException'; - if (method_exists($this, 'expectException') === true) { - // PHPUnit 5+. - $this->expectException($exception); - $this->expectExceptionMessage($expected); - } else { - // PHPUnit 4. - $this->setExpectedException($exception, $expected); - } + + $this->expectException($exception); + $this->expectExceptionMessage($expected); $msgCollector = new MessageCollector(); $this->createErrorCache($msgCollector, $messages); diff --git a/tests/Core/Util/Timing/TimingTest.php b/tests/Core/Util/Timing/TimingTest.php index f5ef115643..a8cf2d04e4 100644 --- a/tests/Core/Util/Timing/TimingTest.php +++ b/tests/Core/Util/Timing/TimingTest.php @@ -51,7 +51,7 @@ public function testGetDurationWithStartReturnsMilliseconds() usleep(1500); $duration = Timing::getDuration(); - $this->assertTrue(is_float($duration)); + $this->assertIsFloat($duration); $this->assertGreaterThan(1, $duration); $this->assertLessThan(15, $duration); diff --git a/tests/Standards/AbstractSniffUnitTest.php b/tests/Standards/AbstractSniffUnitTest.php index ccd90c513c..a62374cf55 100644 --- a/tests/Standards/AbstractSniffUnitTest.php +++ b/tests/Standards/AbstractSniffUnitTest.php @@ -51,17 +51,15 @@ abstract class AbstractSniffUnitTest extends TestCase /** * Sets up this unit test. * - * @before - * * @return void */ - protected function setUpPrerequisites() + protected function setUp(): void { $class = get_class($this); $this->standardsDir = $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$class]; $this->testsDir = $GLOBALS['PHP_CODESNIFFER_TEST_DIRS'][$class]; - }//end setUpPrerequisites() + }//end setUp() /** diff --git a/tests/TestSuite.php b/tests/TestSuite.php index 4598a85623..ad0947c58f 100644 --- a/tests/TestSuite.php +++ b/tests/TestSuite.php @@ -19,11 +19,11 @@ class TestSuite extends PHPUnit_TestSuite /** * Runs the tests and collects their result in a TestResult. * - * @param \PHPUnit\Framework\TestResult $result A test result. + * @param \PHPUnit\Framework\TestResult|null $result A test result. * * @return \PHPUnit\Framework\TestResult */ - public function run(TestResult $result=null) + public function run(?TestResult $result=null): TestResult { $result = parent::run($result); printPHPCodeSnifferTestOutput(); diff --git a/tests/TestSuite7.php b/tests/TestSuite7.php deleted file mode 100644 index ad0947c58f..0000000000 --- a/tests/TestSuite7.php +++ /dev/null @@ -1,35 +0,0 @@ - - * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - */ - -namespace PHP_CodeSniffer\Tests; - -use PHPUnit\Framework\TestResult; -use PHPUnit\Framework\TestSuite as PHPUnit_TestSuite; - -class TestSuite extends PHPUnit_TestSuite -{ - - - /** - * Runs the tests and collects their result in a TestResult. - * - * @param \PHPUnit\Framework\TestResult|null $result A test result. - * - * @return \PHPUnit\Framework\TestResult - */ - public function run(?TestResult $result=null): TestResult - { - $result = parent::run($result); - printPHPCodeSnifferTestOutput(); - return $result; - - }//end run() - - -}//end class diff --git a/tests/bootstrap.php b/tests/bootstrap.php index e8ebdbbdd0..f90d98c49f 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -42,23 +42,6 @@ $tokens = new \PHP_CodeSniffer\Util\Tokens(); -// Compatibility for PHPUnit < 6 and PHPUnit 6+. -if (class_exists('PHPUnit_Framework_TestSuite') === true && class_exists('PHPUnit\Framework\TestSuite') === false) { - class_alias('PHPUnit_Framework_TestSuite', 'PHPUnit'.'\Framework\TestSuite'); -} - -if (class_exists('PHPUnit_Framework_TestCase') === true && class_exists('PHPUnit\Framework\TestCase') === false) { - class_alias('PHPUnit_Framework_TestCase', 'PHPUnit'.'\Framework\TestCase'); -} - -if (class_exists('PHPUnit_TextUI_TestRunner') === true && class_exists('PHPUnit\TextUI\TestRunner') === false) { - class_alias('PHPUnit_TextUI_TestRunner', 'PHPUnit'.'\TextUI\TestRunner'); -} - -if (class_exists('PHPUnit_Framework_TestResult') === true && class_exists('PHPUnit\Framework\TestResult') === false) { - class_alias('PHPUnit_Framework_TestResult', 'PHPUnit'.'\Framework\TestResult'); -} - /** * A global util function to help print unit test fixing data.