Skip to content

Commit 3766b82

Browse files
Merge branch '6.1' into 6.2
* 6.1: [Console] Correctly overwrite progressbars with different line count per step [DependencyInjection] Fix deduplicating service instances in circular graphs [Form] Make `ButtonType` handle `form_attr` option [PhpUnitBridge] Use verbose deprecation output for quiet types only when it reaches the threshold [CssSelector] Fix escape patterns
2 parents dd43019 + 5d53817 commit 3766b82

File tree

4 files changed

+164
-5
lines changed

4 files changed

+164
-5
lines changed

DeprecationErrorHandler.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public function shutdown()
203203
// store failing status
204204
$isFailing = !$configuration->tolerates($this->deprecationGroups);
205205

206-
$this->displayDeprecations($groups, $configuration, $isFailing);
206+
$this->displayDeprecations($groups, $configuration);
207207

208208
$this->resetDeprecationGroups();
209209

@@ -216,7 +216,7 @@ public function shutdown()
216216
}
217217

218218
$isFailingAtShutdown = !$configuration->tolerates($this->deprecationGroups);
219-
$this->displayDeprecations($groups, $configuration, $isFailingAtShutdown);
219+
$this->displayDeprecations($groups, $configuration);
220220

221221
if ($configuration->isGeneratingBaseline()) {
222222
$configuration->writeBaseline();
@@ -292,11 +292,10 @@ private static function colorize($str, $red)
292292
/**
293293
* @param string[] $groups
294294
* @param Configuration $configuration
295-
* @param bool $isFailing
296295
*
297296
* @throws \InvalidArgumentException
298297
*/
299-
private function displayDeprecations($groups, $configuration, $isFailing)
298+
private function displayDeprecations($groups, $configuration)
300299
{
301300
$cmp = function ($a, $b) {
302301
return $b->count() - $a->count();
@@ -323,7 +322,8 @@ private function displayDeprecations($groups, $configuration, $isFailing)
323322
fwrite($handle, "\n".self::colorize($deprecationGroupMessage, 'legacy' !== $group && 'indirect' !== $group)."\n");
324323
}
325324

326-
if ('legacy' !== $group && !$configuration->verboseOutput($group) && !$isFailing) {
325+
// Skip the verbose output if the group is quiet and not failing according to its threshold:
326+
if ('legacy' !== $group && !$configuration->verboseOutput($group) && $configuration->toleratesForGroup($group, $this->deprecationGroups)) {
327327
continue;
328328
}
329329
$notices = $this->deprecationGroups[$group]->notices();

DeprecationErrorHandler/Configuration.php

+26
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,32 @@ public function isIgnoredDeprecation(Deprecation $deprecation): bool
203203
return (bool) $result;
204204
}
205205

206+
/**
207+
* @param array<string,DeprecationGroup> $deprecationGroups
208+
*
209+
* @return bool true if the threshold is not reached for the deprecation type nor for the total
210+
*/
211+
public function toleratesForGroup(string $groupName, array $deprecationGroups): bool
212+
{
213+
$grandTotal = 0;
214+
215+
foreach ($deprecationGroups as $type => $group) {
216+
if ('legacy' !== $type) {
217+
$grandTotal += $group->count();
218+
}
219+
}
220+
221+
if ($grandTotal > $this->thresholds['total']) {
222+
return false;
223+
}
224+
225+
if (\in_array($groupName, ['self', 'direct', 'indirect'], true) && $deprecationGroups[$groupName]->count() > $this->thresholds[$groupName]) {
226+
return false;
227+
}
228+
229+
return true;
230+
}
231+
206232
/**
207233
* @return bool
208234
*/

Tests/DeprecationErrorHandler/ConfigurationTest.php

+97
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,103 @@ public function testOutputIsNotVerboseInWeakMode()
234234
$this->assertFalse($configuration->verboseOutput('other'));
235235
}
236236

237+
/**
238+
* @dataProvider provideDataForToleratesForGroup
239+
*/
240+
public function testToleratesForIndividualGroups(string $deprecationsHelper, array $deprecationsPerType, array $expected)
241+
{
242+
$configuration = Configuration::fromUrlEncodedString($deprecationsHelper);
243+
244+
$groups = $this->buildGroups($deprecationsPerType);
245+
246+
foreach ($expected as $groupName => $tolerates) {
247+
$this->assertSame($tolerates, $configuration->toleratesForGroup($groupName, $groups), sprintf('Deprecation type "%s" is %s', $groupName, $tolerates ? 'tolerated' : 'not tolerated'));
248+
}
249+
}
250+
251+
public function provideDataForToleratesForGroup() {
252+
253+
yield 'total threshold not reached' => ['max[total]=1', [
254+
'unsilenced' => 0,
255+
'self' => 0,
256+
'legacy' => 1, // Legacy group is ignored in total threshold
257+
'other' => 0,
258+
'direct' => 1,
259+
'indirect' => 0,
260+
], [
261+
'unsilenced' => true,
262+
'self' => true,
263+
'legacy' => true,
264+
'other' => true,
265+
'direct' => true,
266+
'indirect' => true,
267+
]];
268+
269+
yield 'total threshold reached' => ['max[total]=1', [
270+
'unsilenced' => 0,
271+
'self' => 0,
272+
'legacy' => 1,
273+
'other' => 0,
274+
'direct' => 1,
275+
'indirect' => 1,
276+
], [
277+
'unsilenced' => false,
278+
'self' => false,
279+
'legacy' => false,
280+
'other' => false,
281+
'direct' => false,
282+
'indirect' => false,
283+
]];
284+
285+
yield 'direct threshold reached' => ['max[total]=99&max[direct]=0', [
286+
'unsilenced' => 0,
287+
'self' => 0,
288+
'legacy' => 1,
289+
'other' => 0,
290+
'direct' => 1,
291+
'indirect' => 1,
292+
], [
293+
'unsilenced' => true,
294+
'self' => true,
295+
'legacy' => true,
296+
'other' => true,
297+
'direct' => false,
298+
'indirect' => true,
299+
]];
300+
301+
yield 'indirect & self threshold reached' => ['max[total]=99&max[direct]=0&max[self]=0', [
302+
'unsilenced' => 0,
303+
'self' => 1,
304+
'legacy' => 1,
305+
'other' => 1,
306+
'direct' => 1,
307+
'indirect' => 1,
308+
], [
309+
'unsilenced' => true,
310+
'self' => false,
311+
'legacy' => true,
312+
'other' => true,
313+
'direct' => false,
314+
'indirect' => true,
315+
]];
316+
317+
yield 'indirect & self threshold not reached' => ['max[total]=99&max[direct]=2&max[self]=2', [
318+
'unsilenced' => 0,
319+
'self' => 1,
320+
'legacy' => 1,
321+
'other' => 1,
322+
'direct' => 1,
323+
'indirect' => 1,
324+
], [
325+
'unsilenced' => true,
326+
'self' => true,
327+
'legacy' => true,
328+
'other' => true,
329+
'direct' => true,
330+
'indirect' => true,
331+
]];
332+
}
333+
237334
private function buildGroups($counts)
238335
{
239336
$groups = [];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
Test DeprecationErrorHandler quiet on everything but self/direct deprecations
3+
--FILE--
4+
<?php
5+
6+
$k = 'SYMFONY_DEPRECATIONS_HELPER';
7+
putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[self]=0&max[direct]=0&quiet[]=unsilenced&quiet[]=indirect&quiet[]=other');
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 (2)
28+
29+
1x: root deprecation
30+
31+
1x: silenced bar deprecation
32+
1x in FooTestCase::testNonLegacyBar
33+
34+
Remaining indirect deprecation notices (1)
35+
36+
Legacy deprecation notices (2)

0 commit comments

Comments
 (0)