Skip to content

Commit

Permalink
MNT Only disable deprecations if they were not previously enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Nov 2, 2022
1 parent e454db6 commit 6e724d2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/php/Dev/DeprecationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ class DeprecationTest extends SapphireTest

private $oldHandler = null;

private bool $noticesWereEnabled = false;

protected function setup(): void
{
// Use custom error handler for two reasons:
// - Filter out errors for deprecated class properities unrelated to this unit test
// - Allow the use of expectDeprecation(), which doesn't work with E_USER_DEPRECATION by default
// https://github.com/laminas/laminas-di/pull/30#issuecomment-927585210
parent::setup();
$this->noticesWereEnabled = Deprecation::get_is_enabled();
$this->oldHandler = set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) {
if ($errno === E_USER_DEPRECATED) {
if (str_contains($errstr, 'SilverStripe\\Dev\\Tests\\DeprecationTest')) {
Expand All @@ -42,7 +45,9 @@ protected function setup(): void

protected function tearDown(): void
{
Deprecation::disable();
if (!$this->noticesWereEnabled) {
Deprecation::disable();
}
set_error_handler($this->oldHandler);
$this->oldHandler = null;
parent::tearDown();
Expand Down

0 comments on commit 6e724d2

Please sign in to comment.