Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public function __construct()
* 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"
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,30 +166,29 @@ public static function fromUrlEncodedString($serializedConfiguration)
}
}

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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,22 @@ public function testItCanTellWhetherToDisplayAStackTrace()
$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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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--