From 268f66f4171f98157f9999b2dd2cc545a30341fd Mon Sep 17 00:00:00 2001 From: Volodymyr Shelmuk Date: Mon, 18 Mar 2024 09:13:35 +0200 Subject: [PATCH] tests: improve AttributesOutputFilter unit test --- .../AttributesOutputFilterTest.php | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/Unit/OutputFilter/AttributesOutputFilterTest.php b/tests/phpunit/Unit/OutputFilter/AttributesOutputFilterTest.php index 896e8f7..f8957c0 100644 --- a/tests/phpunit/Unit/OutputFilter/AttributesOutputFilterTest.php +++ b/tests/phpunit/Unit/OutputFilter/AttributesOutputFilterTest.php @@ -20,9 +20,25 @@ class AttributesOutputFilterTest extends AbstractTestCase { + /** + * phpcs:disable WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_error_reporting + * phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_error_reporting + * phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler + */ public function testIfTagProcessorIsUnavailable(): void { - $this->expectDeprecation(); + $currentErrorReporting = error_reporting(); + error_reporting($currentErrorReporting | \E_USER_DEPRECATED); + $errorMessages = []; + + set_error_handler( + static function (int $code, string $msg) use (&$errorMessages): bool { + $errorMessages[] = $msg; + return true; + }, + \E_USER_DEPRECATED + ); + $testee = new AttributesOutputFilter(); $stub = \Mockery::mock(Asset::class); @@ -34,5 +50,12 @@ public function testIfTagProcessorIsUnavailable(): void static::assertInstanceOf(AssetOutputFilter::class, $testee); static::assertSame($input, $testee($input, $stub)); + static::assertSame( + 'Adding attributes is not supported for WordPress < 6.2', + $errorMessages[0] + ); + + error_reporting($currentErrorReporting); + // phpcs:enable } }