Browse Source

Enable testing with PHPUnit 9.x

- Replace setUp/tearDown.
- Refactor propery-accessing static methods.
- Fix fabbot.io notices.
- Bumps timeout for small tests.
- Update composer.json.

Co-authored-by: Alexey Kopytko <alexey@kopytko.com>
Alexey Kopytko 4 years ago
parent
commit
4dee7ec33c

+ 1 - 0
.composer-require-checker.json

@@ -1,5 +1,6 @@
 {
     "symbol-whitelist" : [
+        "LegacyPHPUnit\\TestCase",
         "PhpCsFixer\\PhpunitConstraintIsIdenticalString\\Constraint\\IsIdenticalString",
         "PhpCsFixer\\Tests\\Test\\Constraint\\SameStringsConstraint",
         "PhpCsFixer\\Tests\\Test\\IsIdenticalConstraint",

+ 2 - 1
composer.json

@@ -40,9 +40,10 @@
         "php-cs-fixer/accessible-object": "^1.0",
         "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.2",
         "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.2.1",
-        "phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.1",
+        "phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.13 || ^9.4.4 <9.5",
         "phpunitgoodpractices/polyfill": "^1.5",
         "phpunitgoodpractices/traits": "^1.9.1",
+        "sanmai/phpunit-legacy-adapter": "^6.4 || ^8.2.1",
         "symfony/phpunit-bridge": "^5.1",
         "symfony/yaml": "^3.0 || ^4.0 || ^5.0"
     },

+ 2 - 0
phpstan.neon

@@ -14,6 +14,8 @@ parameters:
         - '/^Return typehint of method PhpCsFixer\\Tests\\Test\\.+::createIsIdenticalStringConstraint\(\) has invalid type PHPUnit_Framework_Constraint_IsIdentical\.$/'
         - '/^Class (Symfony\\Contracts\\EventDispatcher\\Event|Symfony\\Component\\EventDispatcher\\Event) not found.$/'
         - '/^Constant T_NAME_(RELATIVE|FULLY_QUALIFIED|QUALIFIED) not found\.$/'
+        - '/Instantiated class .*TraversableContains is abstract/'
+        - '/assertInstanceOf\(\) expects class-string.*, string given/'
         -
             message: '/^Unsafe usage of new static\(\)\.$/'
             path: src/Config.php

+ 1 - 0
phpunit.xml.dist

@@ -18,6 +18,7 @@
     enforceTimeLimit="true"
     processIsolation="false"
     stopOnFailure="false"
+    timeoutForSmallTests="2"
     verbose="true"
 >
     <testsuites>

+ 4 - 4
tests/AbstractFunctionReferenceFixerTest.php

@@ -24,18 +24,18 @@ final class AbstractFunctionReferenceFixerTest extends TestCase
 {
     private $fixer;
 
-    protected function setUp()
+    protected function doSetUp()
     {
         $this->fixer = new FunctionReferenceTestFixer();
 
-        parent::setUp();
+        parent::doSetUp();
     }
 
-    protected function tearDown()
+    protected function doTearDown()
     {
         $this->fixer = null;
 
-        parent::tearDown();
+        parent::doTearDown();
     }
 
     /**

+ 18 - 5
tests/AutoReview/CiConfigurationTest.php

@@ -74,12 +74,27 @@ final class CiConfigurationTest extends TestCase
         }
     }
 
-    private static function assertUpcomingPhpVersionIsCoveredByCiJob($lastSupportedVersion, array $ciVersions)
+    private static function ensureTraversableContainsIsAvailable()
     {
         if (!class_exists(TraversableContains::class)) {
             static::markTestSkipped('TraversableContains not available.');
         }
 
+        try {
+            new TraversableContains('');
+        } catch (\Error $e) {
+            if (false === strpos($e->getMessage(), 'Cannot instantiate abstract class')) {
+                throw $e;
+            }
+
+            static::markTestSkipped('TraversableContains not available.');
+        }
+    }
+
+    private static function assertUpcomingPhpVersionIsCoveredByCiJob($lastSupportedVersion, array $ciVersions)
+    {
+        self::ensureTraversableContainsIsAvailable();
+
         static::assertThat($ciVersions, static::logicalOr(
             // if `$lastsupportedVersion` is already a snapshot version
             new TraversableContains(sprintf('%.1fsnapshot', $lastSupportedVersion)),
@@ -100,9 +115,7 @@ final class CiConfigurationTest extends TestCase
             static::assertContains($expectedVersion, $ciVersions);
         }
 
-        if (!class_exists(TraversableContains::class)) {
-            static::markTestSkipped('TraversableContains not available.');
-        }
+        self::ensureTraversableContainsIsAvailable();
 
         static::assertThat($ciVersions, static::logicalOr(
             new TraversableContains($lastSupportedVersion),
@@ -117,7 +130,7 @@ final class CiConfigurationTest extends TestCase
         });
 
         return array_map(function ($job) {
-            return (string) $job['php'];
+            return \is_string($job['php']) ? $job['php'] : sprintf('%.1f', $job['php']);
         }, $jobs);
     }
 

+ 1 - 1
tests/AutoReview/ProjectCodeTest.php

@@ -262,7 +262,7 @@ final class ProjectCodeTest extends TestCase
 
         foreach ($publicMethods as $method) {
             static::assertMatchesRegularExpression(
-                '/^(test|expect|provide|setUpBeforeClass$|tearDownAfterClass$)/',
+                '/^(test|expect|provide|doSetUpBeforeClass$|doTearDownAfterClass$)/',
                 $method->getName(),
                 sprintf('Public method "%s::%s" is not properly named.', $reflectionClass->getName(), $method->getName())
             );

+ 2 - 2
tests/Cache/FileHandlerTest.php

@@ -27,9 +27,9 @@ use PhpCsFixer\Tests\TestCase;
  */
 final class FileHandlerTest extends TestCase
 {
-    protected function tearDown()
+    protected function doTearDown()
     {
-        parent::tearDown();
+        parent::doTearDown();
 
         $file = $this->getFile();
 

+ 4 - 4
tests/Console/Command/SelfUpdateCommandTest.php

@@ -36,9 +36,9 @@ final class SelfUpdateCommandTest extends TestCase
      */
     private $root;
 
-    protected function setUp()
+    protected function doSetUp()
     {
-        parent::setUp();
+        parent::doSetUp();
 
         $this->root = vfsStream::setup();
 
@@ -48,9 +48,9 @@ final class SelfUpdateCommandTest extends TestCase
         file_put_contents("{$this->root->url()}/{$this->getNewMajorVersion()}.phar", 'New major version of PHP CS Fixer.');
     }
 
-    protected function tearDown()
+    protected function doTearDown()
     {
-        parent::tearDown();
+        parent::doTearDown();
 
         $this->root = null;
 

+ 2 - 2
tests/FileReaderTest.php

@@ -25,9 +25,9 @@ use PhpCsFixer\Tests\Fixtures\Test\FileReaderTest\StdinFakeStream;
  */
 final class FileReaderTest extends TestCase
 {
-    public static function tearDownAfterClass()
+    public static function doTearDownAfterClass()
     {
-        parent::tearDownAfterClass();
+        parent::doTearDownAfterClass();
 
         // testReadStdinCaches registers a stream wrapper for php so we can mock
         // php://stdin. Restore the original stream wrapper after this class so

Some files were not shown because too many files changed in this diff