[PHPUnitBridge] deprecations not enabled anymore when disabled=0

Allow to pass 0 or 1 to "disabled" to be consistent with "verbose" key behavior
This commit is contained in:
Laurent VOULLEMIER 2020-08-31 22:38:31 +02:00
parent 141ce4c78c
commit 6908e3d156
4 changed files with 65 additions and 16 deletions

View File

@ -49,8 +49,9 @@ class DeprecationErrorHandler
* Registers and configures the deprecation handler. * Registers and configures the deprecation handler.
* *
* The mode is a query string with options: * 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 * - "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 * - "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" * status code; it's an array with keys "total", "self", "direct" and "indirect"
* *

View File

@ -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(); return self::inDisabledMode();
} }
$verboseOutput = []; $verboseOutput = [];
if (!isset($normalizedConfiguration['verbose'])) {
$normalizedConfiguration['verbose'] = true;
}
foreach (['unsilenced', 'direct', 'indirect', 'self', 'other'] as $group) { 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) { foreach ($normalizedConfiguration['quiet'] as $shushedGroup) {
$verboseOutput[$shushedGroup] = false; $verboseOutput[$shushedGroup] = false;
} }
} }
return new self( return new self($normalizedConfiguration['max'], '', $verboseOutput);
isset($normalizedConfiguration['max']) ? $normalizedConfiguration['max'] : [],
'',
$verboseOutput
);
} }
/** /**

View File

@ -176,10 +176,22 @@ class ConfigurationTest extends TestCase
$this->assertTrue($configuration->shouldDisplayStackTrace('interesting')); $this->assertTrue($configuration->shouldDisplayStackTrace('interesting'));
} }
public function testItCanBeDisabled() public function provideItCanBeDisabled(): array
{ {
$configuration = Configuration::fromUrlEncodedString('disabled'); return [
$this->assertFalse($configuration->isEnabled()); ['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() public function testItCanBeShushed()

View File

@ -0,0 +1,37 @@
--TEST--
Test DeprecationErrorHandler in default mode
--FILE--
<?php
$k = 'SYMFONY_DEPRECATIONS_HELPER';
putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'disabled=1');
putenv($k);
putenv('ANSICON');
putenv('ConEmuANSI');
putenv('TERM');
$vendor = __DIR__;
while (!file_exists($vendor.'/vendor')) {
$vendor = dirname($vendor);
}
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
require PHPUNIT_COMPOSER_INSTALL;
require_once __DIR__.'/../../bootstrap.php';
@trigger_error('root deprecation', E_USER_DEPRECATED);
eval(<<<'EOPHP'
namespace PHPUnit\Util;
class Test
{
public static function getGroups()
{
return array();
}
}
EOPHP
);
?>
--EXPECTF--