Skip to content

Commit

Permalink
DX: check deprecations exactly - order or count of expectation vs act…
Browse files Browse the repository at this point in the history
…ual usage can vary, but result sets must be identical
  • Loading branch information
keradus committed Jan 15, 2024
1 parent 36fcb86 commit ee24a33
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ abstract class TestCase extends BaseTestCase
protected function tearDown(): void
{
if (null !== $this->previouslyDefinedErrorHandler) {
$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 @@ -52,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 All @@ -66,8 +74,6 @@ function (
) {
if (E_USER_DEPRECATED === $code || E_DEPRECATED === $code) {
$this->actualDeprecations[] = $message;
$this->actualDeprecations = array_unique($this->actualDeprecations);
sort($this->actualDeprecations);
}

return true;
Expand Down

0 comments on commit ee24a33

Please sign in to comment.