Skip to content

Commit

Permalink
DX: check deprecations exactly (#7742)
Browse files Browse the repository at this point in the history
Co-authored-by: Kuba Werłos <9282069+kubawerlos@users.noreply.github.com>
  • Loading branch information
keradus and kubawerlos committed Jan 20, 2024
1 parent 0e2de60 commit 48a62f0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions tests/AutoReview/DescribeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function testDescribeCommand(FixerFactory $factory, string $fixerName): v
{
// @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);

Expand Down
1 change: 1 addition & 0 deletions tests/Console/Command/DescribeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function testExecuteOutput(string $expected, bool $expectedIsRegEx, bool
{
// @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);

Expand Down
1 change: 1 addition & 0 deletions tests/Console/ConfigurationResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,7 @@ public function testDeprecatedRuleSetConfigured(string $ruleSet, array $successo
? 'No replacement available'
: sprintf('Use %s instead', Utils::naturalLanguageJoin($successors))
));

$config = new Config();
$config->setRules([$ruleSet => true]);
$config->setRiskyAllowed(true);
Expand Down
12 changes: 9 additions & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,6 +58,8 @@ final public function testNotDefiningConstructor(): void
}

/**
* 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
Expand Down

0 comments on commit 48a62f0

Please sign in to comment.