Skip to content

Commit

Permalink
Allow running tests with PHPUnit 10 and 11
Browse files Browse the repository at this point in the history
PHPUnit 11 emits complaints about the error handlers not being
removed, which is risky, so I had to add a few calls to
restore_error_handler().

This leaves us with PHPUnit deprecations about using @before and @after rather
than the corresponding attributes. I do not think those can be addressed
without a breaking change (adding the attributes is not enough, you have
to remove the annotations).
  • Loading branch information
greg0ire committed Dec 15, 2024
1 parent 3a75ce3 commit bbdf56f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"doctrine/coding-standard": "^9 || ^12",
"phpstan/phpstan": "1.4.10 || 2.0.3",
"phpstan/phpstan-phpunit": "^1.0 || ^2",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5 || ^10.5 || ^11.5",
"psr/log": "^1 || ^2 || ^3"
},
"suggest": {
Expand Down
8 changes: 8 additions & 0 deletions tests/DeprecationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use ReflectionClass;
use ReflectionProperty;

use function restore_error_handler;
use function set_error_handler;

class DeprecationTest extends TestCase
Expand Down Expand Up @@ -79,6 +80,7 @@ public function testDeprecation(): void
);

$this->assertEquals(2, Deprecation::getUniqueTriggeredDeprecationsCount());
restore_error_handler();
}

public function testDeprecationWithoutDeduplication(): void
Expand All @@ -100,6 +102,7 @@ public function testDeprecationWithoutDeduplication(): void
);

$this->assertEquals(1, Deprecation::getUniqueTriggeredDeprecationsCount());
restore_error_handler();

$this->expectErrorHandler(
'this is deprecated foo 2222 (DeprecationTest.php:%d called by TestCase.php:%d, https://github.com/doctrine/deprecations/2222, package doctrine/orm)',
Expand All @@ -116,6 +119,7 @@ public function testDeprecationWithoutDeduplication(): void
);

$this->assertEquals(2, Deprecation::getUniqueTriggeredDeprecationsCount());
restore_error_handler();
}

public function testDisableResetsCounts(): void
Expand Down Expand Up @@ -212,6 +216,7 @@ public function testDeprecationIfCalledFromOutside(): void
Foo::triggerDependencyWithDeprecation();

$this->assertEquals(1, Deprecation::getUniqueTriggeredDeprecationsCount());
restore_error_handler();
}

public function testDeprecationIfCalledFromOutsideNotTriggeringFromInside(): void
Expand Down Expand Up @@ -247,6 +252,7 @@ public function testDeprecationCalledFromOutsideInRoot(): void
RootDeprecation::run();

$this->assertEquals(1, Deprecation::getUniqueTriggeredDeprecationsCount());
restore_error_handler();
}

public function testDeprecationTrackByEnv(): void
Expand Down Expand Up @@ -279,6 +285,7 @@ public function testDeprecationTriggerByEnv(): void

Deprecation::trigger('Foo', __METHOD__, 'message');
$this->assertSame(1, Deprecation::getUniqueTriggeredDeprecationsCount());
restore_error_handler();
}

public function testDeprecationTriggeredFromNativeCode(): void
Expand All @@ -293,5 +300,6 @@ public function testDeprecationTriggeredFromNativeCode(): void

$ref->newInstance();
$this->assertSame(1, Deprecation::getUniqueTriggeredDeprecationsCount());
restore_error_handler();
}
}
6 changes: 6 additions & 0 deletions tests/VerifyDeprecationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use PHPUnit\Framework\TestCase;

use function restore_error_handler;
use function set_error_handler;

class VerifyDeprecationsTest extends TestCase
Expand All @@ -20,6 +21,11 @@ public function setUp(): void
});
}

public function tearDown(): void
{
restore_error_handler();
}

public function testExpectDeprecationWithIdentifier(): void
{
$this->expectDeprecationWithIdentifier('http://example.com');
Expand Down

0 comments on commit bbdf56f

Please sign in to comment.