Skip to content

Commit 6c4454b

Browse files
committed
feature #38017 [PHPUnitBridge] deprecations not disabled anymore when disabled=0 (l-vo)
This PR was merged into the 5.2-dev branch. Discussion ---------- [PHPUnitBridge] deprecations not disabled anymore when disabled=0 | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | | Tickets | | License | MIT | Doc PR | According to the [docs](https://symfony.com/doc/current/components/phpunit_bridge.html#disabling-the-deprecation-helper), `disabled=1` turns off deprecations mode on phpunit-bridge. It's not totally true since deprecations are disabled as soon as `disabled` key is present in `SYMFONY_DEPRECATIONS_HELPER`. So if `disabled=0` deprecations are still disabled. Instead of updating the doc, this PR suggest to make `disabled` behavior consistent with `verbose` behavior, so: - `disabled` => deprecations disabled - `disabled=0` => deprecations enabled - `disabled=1` => deprecations disabled Commits ------- 6908e3d156 [PHPUnitBridge] deprecations not enabled anymore when disabled=0
2 parents 07ca5b4 + 1e2cf16 commit 6c4454b

File tree

4 files changed

+65
-16
lines changed

4 files changed

+65
-16
lines changed

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
*

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
/**

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)