8000 [PHPUnitBridge] deprecations not enabled anymore when disabled=0 · symfony/symfony@6908e3d · GitHub
[go: up one dir, main page]

Skip to content

Commit 6908e3d

Browse files
committed
[PHPUnitBridge] deprecations not enabled anymore when disabled=0
Allow to pass 0 or 1 to "disabled" to be consistent with "verbose" key behavior
1 parent 141ce4c commit 6908e3d

File tree

4 files changed

+65
-16
lines changed

4 files changed

+65
-16
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ public function __construct()
4949
* Registers and configures the deprecation handler.
5050
*
5151
* The mode is a query string with options:
52-
* - "disabled" to disable the deprecation handler
52+
* - "disabled" to enable/disable the deprecation handler
5353
* - "verbose" to enable/disable displaying the deprecation report
54+
* - "quiet" to disable displaying the deprecation report only for some groups (i.e. quiet[]=other)
5455
* - "max" to configure the number of deprecations to allow before exiting with a non-zero
5556
* status code; it's an array with keys "total", "self", "direct" and "indirect"
5657
*

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Configuration.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,30 +166,29 @@ public static function fromUrlEncodedString($serializedConfiguration)
166166
}
167167
}
168168

169-
if (isset($normalizedConfiguration['disabled'])) {
169+
$normalizedConfiguration += [
170+
'max' => [],
171+
'disabled' => false,
172+
'verbose' => true,
173+
'quiet' => [],
174+
];
175+
176+
if ('' === $normalizedConfiguration['disabled'] || filter_var($normalizedConfiguration['disabled'], FILTER_VALIDATE_BOOLEAN)) {
170177
return self::inDisabledMode();
171178
}
172179

173180
$verboseOutput = [];
174-
if (!isset($normalizedConfiguration['verbose'])) {
175-
$normalizedConfiguration['verbose'] = true;
176-
}
177-
178181
foreach (['unsilenced', 'direct', 'indirect', 'self', 'other'] as $group) {
179-
$verboseOutput[$group] = (bool) $normalizedConfiguration['verbose'];
182+
$verboseOutput[$group] = filter_var($normalizedConfiguration['verbose'], FILTER_VALIDATE_BOOLEAN);
180183
}
181184

182-
if (isset($normalizedConfiguration['quiet']) && \is_array($normalizedConfiguration['quiet'])) {
185+
if (\is_array($normalizedConfiguration['quiet'])) {
183186
foreach ($normalizedConfiguration['quiet'] as $shushedGroup) {
184187
$verboseOutput[$shushedGroup] = false;
185188
}
186189
}
187190

188-
return new self(
189-
isset($normalizedConfiguration['max']) ? $normalizedConfiguration['max'] : [],
190-
'',
191-
$verboseOutput
192-
);
191+
return new self($normalizedConfiguration['max'], '', $verboseOutput);
193192
}
194193

195194
/**

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,22 @@ public function testItCanTellWhetherToDisplayAStackTrace()
176176
$this->assertTrue($configuration->shouldDisplayStackTrace('interesting'));
177177
}
178178

179-
public function testItCanBeDisabled()
179+
public function provideItCanBeDisabled(): array
180180
{
181-
$configuration = Configuration::fromUrlEncodedString('disabled');
182-
$this->assertFalse($configuration->isEnabled());
181+
return [
182+
['disabled', false],
183+
['disabled=1', false],
184+
['disabled=0', true]
185+
];
186+
}
187+
188+
/**
189+
* @dataProvider provideItCanBeDisabled
190+
*/
191+
public function testItCanBeDisabled(string $encodedString, bool $expectedEnabled)
192+
{
193+
$configuration = Configuration::fromUrlEncodedString($encodedString);
194+
$this->assertSame($expectedEnabled, $configuration->isEnabled());
183195
}
184196

185197
public function testItCanBeShushed()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
Test DeprecationErrorHandler in default mode
3+
--FILE--
4+
<?php
5+
6+
$k = 'SYMFONY_DEPRECATIONS_HELPER';
7+
putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'disabled=1');
8+
putenv($k);
9+
putenv('ANSICON');
10+
putenv('ConEmuANSI');
11+
putenv('TERM');
12+
13+
$vendor = __DIR__;
14+
while (!file_exists($vendor.'/vendor')) {
15+
$vendor = dirname($vendor);
16+
}
17+
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
18+
require PHPUNIT_COMPOSER_INSTALL;
19+
require_once __DIR__.'/../../bootstrap.php';
20+
21+
@trigger_error('root deprecation', E_USER_DEPRECATED);
22+
23+
eval(<<<'EOPHP'
24+
namespace PHPUnit\Util;
25+
26+
class Test
27+
{
28+
public static function getGroups()
29+
{
30+
return array();
31+
}
32+
}
33+
EOPHP
34+
);
35+
?>
36+
--EXPECTF--
37+

0 commit comments

Comments
 (0)
0