[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:
parent
141ce4c78c
commit
6908e3d156
@ -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"
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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()
|
||||
|
@ -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--
|
||||
|
Reference in New Issue
Block a user