Browse Source

DX: remove `symfony/phpunit-bridge` (#7578)

Kuba Werłos 1 year ago
parent
commit
434113324d

+ 0 - 1
composer.json

@@ -47,7 +47,6 @@
         "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.4",
         "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.4",
         "phpunit/phpunit": "^9.6",
-        "symfony/phpunit-bridge": "^6.3.8 || ^7.0",
         "symfony/yaml": "^5.4 || ^6.0 || ^7.0"
     },
     "suggest": {

+ 0 - 4
phpunit.xml.dist

@@ -42,10 +42,6 @@
         </include>
     </coverage>
 
-    <listeners>
-        <listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
-    </listeners>
-
     <php>
         <ini name="zend.enable_gc" value="0"/>
         <ini name="memory_limit" value="10G"/>

+ 0 - 3
tests/AutoReview/DocumentationTest.php

@@ -22,7 +22,6 @@ use PhpCsFixer\Fixer\FixerInterface;
 use PhpCsFixer\FixerFactory;
 use PhpCsFixer\RuleSet\RuleSets;
 use PhpCsFixer\Tests\TestCase;
-use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
 use Symfony\Component\Finder\Finder;
 
 /**
@@ -35,8 +34,6 @@ use Symfony\Component\Finder\Finder;
  */
 final class DocumentationTest extends TestCase
 {
-    use ExpectDeprecationTrait;
-
     /**
      * @dataProvider provideFixerDocumentationFileIsUpToDateCases
      */

+ 2 - 0
tests/FileRemovalTest.php

@@ -127,6 +127,8 @@ final class FileRemovalTest extends TestCase
      *
      * @runInSeparateProcess
      *
+     * @preserveGlobalState disabled
+     *
      * @doesNotPerformAssertions
      */
     public function testShutdownRemovesObservedFilesSetup(): void

+ 2 - 0
tests/Smoke/InstallViaComposerTest.php

@@ -99,6 +99,8 @@ final class InstallViaComposerTest extends AbstractSmokeTestCase
     protected function tearDown(): void
     {
         $this->fs = null;
+
+        parent::tearDown();
     }
 
     public function testInstallationViaPathIsPossible(): void

+ 42 - 2
tests/TestCase.php

@@ -15,7 +15,6 @@ declare(strict_types=1);
 namespace PhpCsFixer\Tests;
 
 use PHPUnit\Framework\TestCase as BaseTestCase;
-use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
 
 /**
  * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
@@ -24,7 +23,25 @@ use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
  */
 abstract class TestCase extends BaseTestCase
 {
-    use ExpectDeprecationTrait;
+    /** @var null|callable */
+    private $previouslyDefinedErrorHandler;
+
+    /** @var list<string> */
+    private array $expectedDeprecations = [];
+
+    /** @var list<string> */
+    private array $actualDeprecations = [];
+
+    protected function tearDown(): void
+    {
+        if (null !== $this->previouslyDefinedErrorHandler) {
+            foreach ($this->expectedDeprecations as $expectedDeprecation) {
+                self::assertContains($expectedDeprecation, $this->actualDeprecations);
+            }
+
+            restore_error_handler();
+        }
+    }
 
     final public function testNotDefiningConstructor(): void
     {
@@ -35,4 +52,27 @@ abstract class TestCase extends BaseTestCase
             $reflection->getName(),
         );
     }
+
+    /**
+     * @TODO change access to protected and pass the parameter when PHPUnit 9 support is dropped
+     */
+    public function expectDeprecation(/* string $message */): void
+    {
+        $this->expectedDeprecations[] = func_get_arg(0);
+
+        if (null === $this->previouslyDefinedErrorHandler) {
+            $this->previouslyDefinedErrorHandler = set_error_handler(
+                function (
+                    int $code,
+                    string $message
+                ) {
+                    if (E_USER_DEPRECATED === $code || E_DEPRECATED === $code) {
+                        $this->actualDeprecations[] = $message;
+                    }
+
+                    return true;
+                }
+            );
+        }
+    }
 }

+ 2 - 0
tests/UtilsTest.php

@@ -44,6 +44,8 @@ final class UtilsTest extends TestCase
     protected function tearDown(): void
     {
         putenv("PHP_CS_FIXER_FUTURE_MODE={$this->originalValueOfFutureMode}");
+
+        parent::tearDown();
     }
 
     /**