From 6908e3d156a220d5f129adb82473f39aeba89f0c Mon Sep 17 00:00:00 2001 From: Laurent VOULLEMIER Date: Mon, 31 Aug 2020 22:38:31 +0200 Subject: [PATCH] [PHPUnitBridge] deprecations not enabled anymore when disabled=0 Allow to pass 0 or 1 to "disabled" to be consistent with "verbose" key behavior --- .../PhpUnit/DeprecationErrorHandler.php | 3 +- .../DeprecationErrorHandler/Configuration.php | 23 ++++++------ .../ConfigurationTest.php | 18 +++++++-- .../DeprecationErrorHandler/disabled_1.phpt | 37 +++++++++++++++++++ 4 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/disabled_1.phpt diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index ed77d1417b..ed4ee5c8eb 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -49,8 +49,9 @@ class DeprecationErrorHandler * Registers and configures the deprecation handler. * * The mode is a query string with options: - * - "disabled" to disable the deprecation handler + * - "disabled" to enable/disable the deprecation handler * - "verbose" to enable/disable displaying the deprecation report + * - "quiet" to disable displaying the deprecation report only for some groups (i.e. quiet[]=other) * - "max" to configure the number of deprecations to allow before exiting with a non-zero * status code; it's an array with keys "total", "self", "direct" and "indirect" * diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Configuration.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Configuration.php index bc0fe98499..11984df735 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Configuration.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Configuration.php @@ -166,30 +166,29 @@ class Configuration } } - if (isset($normalizedConfiguration['disabled'])) { + $normalizedConfiguration += [ + 'max' => [], + 'disabled' => false, + 'verbose' => true, + 'quiet' => [], + ]; + + if ('' === $normalizedConfiguration['disabled'] || filter_var($normalizedConfiguration['disabled'], FILTER_VALIDATE_BOOLEAN)) { return self::inDisabledMode(); } $verboseOutput = []; - if (!isset($normalizedConfiguration['verbose'])) { - $normalizedConfiguration['verbose'] = true; - } - foreach (['unsilenced', 'direct', 'indirect', 'self', 'other'] as $group) { - $verboseOutput[$group] = (bool) $normalizedConfiguration['verbose']; + $verboseOutput[$group] = filter_var($normalizedConfiguration['verbose'], FILTER_VALIDATE_BOOLEAN); } - if (isset($normalizedConfiguration['quiet']) && \is_array($normalizedConfiguration['quiet'])) { + if (\is_array($normalizedConfiguration['quiet'])) { foreach ($normalizedConfiguration['quiet'] as $shushedGroup) { $verboseOutput[$shushedGroup] = false; } } - return new self( - isset($normalizedConfiguration['max']) ? $normalizedConfiguration['max'] : [], - '', - $verboseOutput - ); + return new self($normalizedConfiguration['max'], '', $verboseOutput); } /** diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php index bb5b3a72d4..86fe88cbbe 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php @@ -176,10 +176,22 @@ class ConfigurationTest extends TestCase $this->assertTrue($configuration->shouldDisplayStackTrace('interesting')); } - public function testItCanBeDisabled() + public function provideItCanBeDisabled(): array { - $configuration = Configuration::fromUrlEncodedString('disabled'); - $this->assertFalse($configuration->isEnabled()); + return [ + ['disabled', false], + ['disabled=1', false], + ['disabled=0', true] + ]; + } + + /** + * @dataProvider provideItCanBeDisabled + */ + public function testItCanBeDisabled(string $encodedString, bool $expectedEnabled) + { + $configuration = Configuration::fromUrlEncodedString($encodedString); + $this->assertSame($expectedEnabled, $configuration->isEnabled()); } public function testItCanBeShushed() diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/disabled_1.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/disabled_1.phpt new file mode 100644 index 0000000000..91ad4a2d70 --- /dev/null +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/disabled_1.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test DeprecationErrorHandler in default mode +--FILE-- + +--EXPECTF-- +