Skip to content

Commit 8c6dd3b

Browse files
committed
Add per-group verbosity
1 parent c408d19 commit 8c6dd3b

File tree

5 files changed

+99
-16
lines changed

5 files changed

+99
-16
lines changed

src/Symfony/Bridge/PhpUnit/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* ignore verbosity settings when the build fails because of deprecations
8+
* added per-group verbosity
89

910
5.0.0
1011
-----

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ private function displayDeprecations($groups, $configuration, $isFailing)
292292
'legacy' !== $group && 'indirect' !== $group
293293
), "\n";
294294

295-
if (!$configuration->verboseOutput() && !$isFailing) {
295+
if ('legacy' !== $group && !$configuration->verboseOutput($group) && !$isFailing) {
296296
continue;
297297
}
298298
$notices = $this->deprecationGroups[$group]->notices();

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

+33-13
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ class Configuration
3232
private $enabled = true;
3333

3434
/**
35-
* @var bool
35+
* @var bool[]
3636
*/
37-
private $verboseOutput = true;
37+
private $verboseOutput;
3838

3939
/**
4040
* @param int[] $thresholds A hash associating groups to thresholds
41-
* @param string $regex Will be matched against messages, to decide
42-
* whether to display a stack trace
43-
* @param bool $verboseOutput
41+
* @param string $regex Will be matched against messages,
42+
* to decide whether to display a stack trace
43+
* @param bool[] $verboseOutput Keyed by groups
4444
*/
45-
private function __construct(array $thresholds = [], $regex = '', $verboseOutput = true)
45+
private function __construct(array $thresholds = [], $regex = '', $verboseOutput = [])
4646
{
4747
$groups = ['total', 'indirect', 'direct', 'self'];
4848

@@ -72,7 +72,15 @@ private function __construct(array $thresholds = [], $regex = '', $verboseOutput
7272
}
7373
}
7474
$this->regex = $regex;
75-
$this->verboseOutput = $verboseOutput;
75+
76+
$this->verboseOutput = array_fill_keys(['unsilenced', 'direct', 'indirect', 'self', 'other'], false);
77+
78+
foreach ($verboseOutput as $group => $status) {
79+
if (!isset($this->verboseOutput[$group])) {
80+
throw new \InvalidArgumentException(sprintf('Unsupported verbosity group "%s", expected one of "%s"', $group, implode('", "', array_keys($this->verboseOutput))));
81+
}
82+
$this->verboseOutput[$group] = (bool) $status;
83+
}
7684
}
7785

7886
/**
@@ -132,9 +140,9 @@ public function isInRegexMode()
132140
/**
133141
* @return bool
134142
*/
135-
public function verboseOutput()
143+
public function verboseOutput($group)
136144
{
137-
return $this->verboseOutput;
145+
return $this->verboseOutput[$group];
138146
}
139147

140148
/**
@@ -156,9 +164,16 @@ public static function fromUrlEncodedString($serializedConfiguration)
156164
return self::inDisabledMode();
157165
}
158166

159-
$verboseOutput = true;
160-
if (isset($normalizedConfiguration['verbose'])) {
161-
$verboseOutput = (bool) $normalizedConfiguration['verbose'];
167+
$verboseOutput = [];
168+
if (!isset($normalizedConfiguration['verbose'])) {
169+
$normalizedConfiguration['verbose'] = true;
170+
}
171+
if (\is_array($normalizedConfiguration['verbose'])) {
172+
$verboseOutput = $normalizedConfiguration['verbose'];
173+
} else {
174+
foreach (['unsilenced', 'direct', 'indirect', 'self', 'other'] as $group) {
175+
$verboseOutput[$group] = (bool) $normalizedConfiguration['verbose'];
176+
}
162177
}
163178

164179
return new self(
@@ -192,7 +207,12 @@ public static function inStrictMode()
192207
*/
193208
public static function inWeakMode()
194209
{
195-
return new self([], '', false);
210+
$verboseOutput = [];
211+
foreach (['unsilenced', 'direct', 'indirect', 'self', 'other'] as $group) {
212+
$verboseOutput[$group] = false;
213+
}
214+
215+
return new self([], '', $verboseOutput);
196216
}
197217

198218
/**

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

+27-2
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,38 @@ public function testItCanBeDisabled()
185185
public function testItCanBeShushed()
186186
{
187187
$configuration = Configuration::fromUrlEncodedString('verbose');
188-
$this->assertFalse($configuration->verboseOutput());
188+
$this->assertFalse($configuration->verboseOutput('unsilenced'));
189+
$this->assertFalse($configuration->verboseOutput('direct'));
190+
$this->assertFalse($configuration->verboseOutput('indirect'));
191+
$this->assertFalse($configuration->verboseOutput('self'));
192+
$this->assertFalse($configuration->verboseOutput('other'));
193+
}
194+
195+
public function testItCanBePartiallyShushed()
196+
{
197+
$configuration = Configuration::fromUrlEncodedString('verbose[direct]=1&verbose[self]=1');
198+
$this->assertFalse($configuration->verboseOutput('unsilenced'));
199+
$this->assertTrue($configuration->verboseOutput('direct'));
200+
$this->assertFalse($configuration->verboseOutput('indirect'));
201+
$this->assertTrue($configuration->verboseOutput('self'));
202+
$this->assertFalse($configuration->verboseOutput('other'));
203+
}
204+
205+
public function testItThrowsOnUnknownVerbosityGroup()
206+
{
207+
$this->expectException(\InvalidArgumentException::class);
208+
$this->expectExceptionMessage('made-up');
209+
Configuration::fromUrlEncodedString('verbose[made-up]=0');
189210
}
190211

191212
public function testOutputIsNotVerboseInWeakMode()
192213
{
193214
$configuration = Configuration::inWeakMode();
194-
$this->assertFalse($configuration->verboseOutput());
215+
$this->assertFalse($configuration->verboseOutput('unsilenced'));
216+
$this->assertFalse($configuration->verboseOutput('direct'));
217+
$this->assertFalse($configuration->verboseOutput('indirect'));
218+
$this->assertFalse($configuration->verboseOutput('self'));
219+
$this->assertFalse($configuration->verboseOutput('other'));
195220
}
196221

197222
private function buildGroups($counts)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
Test DeprecationErrorHandler quiet on everything but indirect deprecations
3+
--FILE--
4+
<?php
5+
6+
$k = 'SYMFONY_DEPRECATIONS_HELPER';
7+
putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[self]=0&verbose[indirect]=1');
8+
putenv('ANSICON');
9+
putenv('ConEmuANSI');
10+
putenv('TERM');
11+
12+
$vendor = __DIR__;
13+
while (!file_exists($vendor.'/vendor')) {
14+
$vendor = dirname($vendor);
15+
}
16+
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
17+
require PHPUNIT_COMPOSER_INSTALL;
18+
require_once __DIR__.'/../../bootstrap.php';
19+
require __DIR__.'/fake_vendor/autoload.php';
20+
require __DIR__.'/fake_vendor/acme/lib/deprecation_riddled.php';
21+
require __DIR__.'/fake_vendor/acme/outdated-lib/outdated_file.php';
22+
23+
?>
24+
--EXPECTF--
25+
Unsilenced deprecation notices (3)
26+
27+
Remaining direct deprecation notices (1)
28+
29+
Remaining indirect deprecation notices (1)
30+
31+
1x: deprecatedApi is deprecated! You should stop relying on it!
32+
1x in SomeService::deprecatedApi from acme\lib
33+
34+
Legacy deprecation notices (2)
35+
36+
Other deprecation notices (1)
37+

0 commit comments

Comments
 (0)