Browse Source

DX: check deprecations exactly (#7742)

Co-authored-by: Kuba Werłos <9282069+kubawerlos@users.noreply.github.com>
Dariusz Rumiński 1 year ago
parent
commit
48a62f094b

+ 1 - 0
tests/AutoReview/DescribeCommandTest.php

@@ -38,6 +38,7 @@ final class DescribeCommandTest extends TestCase
     {
         // @TODO 4.0 Remove this expectation
         $this->expectDeprecation('Rule set "@PER" is deprecated. Use "@PER-CS" instead.');
+        $this->expectDeprecation('Rule set "@PER:risky" is deprecated. Use "@PER-CS:risky" instead.');
 
         $command = new DescribeCommand($factory);
 

+ 1 - 0
tests/Console/Command/DescribeCommandTest.php

@@ -55,6 +55,7 @@ final class DescribeCommandTest extends TestCase
     {
         // @TODO 4.0 Remove this expectation
         $this->expectDeprecation('Rule set "@PER" is deprecated. Use "@PER-CS" instead.');
+        $this->expectDeprecation('Rule set "@PER:risky" is deprecated. Use "@PER-CS:risky" instead.');
 
         $actual = $this->execute(null !== $fixer ? $fixer->getName() : 'Foo/bar', $decorated, $fixer)->getDisplay(true);
 

+ 1 - 0
tests/Console/ConfigurationResolverTest.php

@@ -1222,6 +1222,7 @@ For more info about updating see: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/b
                 ? 'No replacement available'
                 : sprintf('Use %s instead', Utils::naturalLanguageJoin($successors))
         ));
+
         $config = new Config();
         $config->setRules([$ruleSet => true]);
         $config->setRiskyAllowed(true);

+ 9 - 3
tests/TestCase.php

@@ -35,12 +35,16 @@ abstract class TestCase extends BaseTestCase
     protected function tearDown(): void
     {
         if (null !== $this->previouslyDefinedErrorHandler) {
-            foreach ($this->expectedDeprecations as $expectedDeprecation) {
-                self::assertContains($expectedDeprecation, $this->actualDeprecations);
-            }
+            $this->actualDeprecations = array_unique($this->actualDeprecations);
+            sort($this->actualDeprecations);
+            $this->expectedDeprecations = array_unique($this->expectedDeprecations);
+            sort($this->expectedDeprecations);
+            self::assertSame($this->expectedDeprecations, $this->actualDeprecations);
 
             restore_error_handler();
         }
+
+        parent::tearDown();
     }
 
     final public function testNotDefiningConstructor(): void
@@ -54,6 +58,8 @@ abstract class TestCase extends BaseTestCase
     }
 
     /**
+     * Mark test to expect given deprecation. Order or repetition count of expected vs actual deprecation usage can vary, but result sets must be identical.
+     *
      * @TODO change access to protected and pass the parameter when PHPUnit 9 support is dropped
      */
     public function expectDeprecation(/* string $message */): void