diff --git a/core/tests/Drupal/Tests/SkippedDeprecationTest.php b/core/tests/Drupal/Tests/SkippedDeprecationTest.php index f8028d275a..c6a08254d7 100644 --- a/core/tests/Drupal/Tests/SkippedDeprecationTest.php +++ b/core/tests/Drupal/Tests/SkippedDeprecationTest.php @@ -2,8 +2,6 @@ namespace Drupal\Tests; -use PHPUnit\Framework\Error\Warning; - /** * @group Test */ @@ -35,17 +33,21 @@ public function testSkippingDeprecationsAgain() { * @see Drupal\Tests\Traits\PHPUnit8Warnings */ public function testSkippingPhpUnit8Warnings() { + + // Ensure the deprecation helper is enabled regardless of the configured + // setting. $original_setting = getenv('SYMFONY_DEPRECATIONS_HELPER'); + putenv('SYMFONY_DEPRECATIONS_HELPER=disabled'); // When the deprecation helper is disabled, both a warning that core fails // and a deprecation warning that core passes should be silenced. - putenv('SYMFONY_DEPRECATIONS_HELPER=disabled'); - $this->addWarning('Warning for \\Drupal\\Tests\\Traits\\PHPUnit8Warnings::$coreFailingWarnings'); $this->addWarning('Warning for \\Drupal\\Tests\\Traits\\PHPUnit8Warnings::$corePassingDeprecationsWarnings'); - $this->addToAssertionCount(1); + + // Restore the configured deprecation handling. putenv("SYMFONY_DEPRECATIONS_HELPER=$original_setting"); + } /** @@ -54,22 +56,19 @@ public function testSkippingPhpUnit8Warnings() { * @see Drupal\Tests\Traits\PHPUnit8Warnings */ public function testNotSkippingPhpUnit8Warnings() { - $original_setting = getenv('SYMFONY_DEPRECATIONS_HELPER'); // Ensure the deprecation helper is enabled regardless of the configured // setting. + $original_setting = getenv('SYMFONY_DEPRECATIONS_HELPER'); putenv('SYMFONY_DEPRECATIONS_HELPER=max[total]=0'); // The warning that core fails should still be silenced. $this->addWarning('Warning for \\Drupal\\Tests\\Traits\\PHPUnit8Warnings::$coreFailingWarnings'); - - // The warning that core does not fail should be flagged. - // @todo This doesn't work. - // $this->addWarning('Warning for \\Drupal\\Tests\\Traits\\PHPUnit8Warnings::$corePassingDeprecationsWarnings'); - // $this->expectException(Warning::class); $this->addToAssertionCount(1); + // Restore the configured deprecation handling. putenv("SYMFONY_DEPRECATIONS_HELPER=$original_setting"); + } }