Skip to content

Commit bbd6e92

Browse files
Merge branch '6.0' into 6.1
* 6.0: [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 be82f92 + ee020a2 commit bbd6e92

File tree

15 files changed

+337
-56
lines changed

15 files changed

+337
-56
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 5 additions & 5 deletions
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();

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

Lines changed: 26 additions & 0 deletions
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
*/

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

Lines changed: 97 additions & 0 deletions
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 = [];
Lines changed: 36 additions & 0 deletions
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)

src/Symfony/Component/Console/Helper/ProgressBar.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ final class ProgressBar
5353
private int $startTime;
5454
private int $stepWidth;
5555
private float $percent = 0.0;
56-
private int $formatLineCount;
5756
private array $messages = [];
5857
private bool $overwrite = true;
5958
private Terminal $terminal;
@@ -438,8 +437,6 @@ private function setRealFormat(string $format)
438437
} else {
439438
$this->format = $format;
440439
}
441-
442-
$this->formatLineCount = substr_count($this->format, "\n");
443440
}
444441

445442
/**
@@ -456,7 +453,7 @@ private function overwrite(string $message): void
456453
if ($this->overwrite) {
457454
if (null !== $this->previousMessage) {
458455
if ($this->output instanceof ConsoleSectionOutput) {
459-
$messageLines = explode("\n", $message);
456+
$messageLines = explode("\n", $this->previousMessage);
460457
$lineCount = \count($messageLines);
461458
foreach ($messageLines as $messageLine) {
462459
$messageLineLength = Helper::width(Helper::removeDecoration($this->output->getFormatter(), $messageLine));
@@ -466,13 +463,11 @@ private function overwrite(string $message): void
466463
}
467464
$this->output->clear($lineCount);
468465
} else {
469-
if ('' !== $this->previousMessage) {
470-
// only clear upper lines when last call was not a clear
471-
for ($i = 0; $i < $this->formatLineCount; ++$i) {
472-
$this->cursor->moveToColumn(1);
473-
$this->cursor->clearLine();
474-
$this->cursor->moveUp();
475-
}
466+
$lineCount = substr_count($this->previousMessage, "\n");
467+
for ($i = 0; $i < $lineCount; ++$i) {
468+
$this->cursor->moveToColumn(1);
469+
$this->cursor->clearLine();
470+
$this->cursor->moveUp();
476471
}
477472

478473
$this->cursor->moveToColumn(1);

src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ public function testOverwriteWithAnsiSectionOutput()
361361
rewind($output->getStream());
362362
$this->assertSame(
363363
" \033[44;37m 0/50\033[0m [>---------------------------] 0%".\PHP_EOL.
364-
"\x1b[1A\x1b[0J"." \033[44;37m 1/50\033[0m [>---------------------------] 2%".\PHP_EOL.
365-
"\x1b[1A\x1b[0J"." \033[44;37m 2/50\033[0m [=>--------------------------] 4%".\PHP_EOL,
364+
"\x1b[1A\x1b[0J \033[44;37m 1/50\033[0m [>---------------------------] 2%".\PHP_EOL.
365+
"\x1b[1A\x1b[0J \033[44;37m 2/50\033[0m [=>--------------------------] 4%".\PHP_EOL,
366366
stream_get_contents($output->getStream())
367367
);
368368
putenv('COLUMNS=120');
@@ -397,6 +397,28 @@ public function testOverwriteMultipleProgressBarsWithSectionOutputs()
397397
);
398398
}
399399

400+
public function testOverwritWithNewlinesInMessage()
401+
{
402+
ProgressBar::setFormatDefinition('test', '%current%/%max% [%bar%] %percent:3s%% %message% Fruitcake marzipan toffee. Cupcake gummi bears tart dessert ice cream chupa chups cupcake chocolate bar sesame snaps. Croissant halvah cookie jujubes powder macaroon. Fruitcake bear claw bonbon jelly beans oat cake pie muffin Fruitcake marzipan toffee.');
403+
404+
$bar = new ProgressBar($output = $this->getOutputStream(), 50, 0);
405+
$bar->setFormat('test');
406+
$bar->start();
407+
$bar->display();
408+
$bar->setMessage("Twas brillig, and the slithy toves. Did gyre and gimble in the wabe: All mimsy were the borogoves, And the mome raths outgrabe.\nBeware the Jabberwock, my son! The jaws that bite, the claws that catch! Beware the Jubjub bird, and shun The frumious Bandersnatch!");
409+
$bar->advance();
410+
$bar->setMessage("He took his vorpal sword in hand; Long time the manxome foe he sought— So rested he by the Tumtum tree And stood awhile in thought.\nAnd, as in uffish thought he stood, The Jabberwock, with eyes of flame, Came whiffling through the tulgey wood, And burbled as it came!");
411+
$bar->advance();
412+
413+
rewind($output->getStream());
414+
$this->assertEquals(
415+
" 0/50 [>] 0% %message% Fruitcake marzipan toffee. Cupcake gummi bears tart dessert ice cream chupa chups cupcake chocolate bar sesame snaps. Croissant halvah cookie jujubes powder macaroon. Fruitcake bear claw bonbon jelly beans oat cake pie muffin Fruitcake marzipan toffee.\x1b[1G\x1b[2K 1/50 [>] 2% Twas brillig, and the slithy toves. Did gyre and gimble in the wabe: All mimsy were the borogoves, And the mome raths outgrabe.
416+
Beware the Jabberwock, my son! The jaws that bite, the claws that catch! Beware the Jubjub bird, and shun The frumious Bandersnatch! Fruitcake marzipan toffee. Cupcake gummi bears tart dessert ice cream chupa chups cupcake chocolate bar sesame snaps. Croissant halvah cookie jujubes powder macaroon. Fruitcake bear claw bonbon jelly beans oat cake pie muffin Fruitcake marzipan toffee.\x1b[1G\x1b[2K\x1b[1A\x1b[1G\x1b[2K 2/50 [>] 4% He took his vorpal sword in hand; Long time the manxome foe he sought— So rested he by the Tumtum tree And stood awhile in thought.
417+
And, as in uffish thought he stood, The Jabberwock, with eyes of flame, Came whiffling through the tulgey wood, And burbled as it came! Fruitcake marzipan toffee. Cupcake gummi bears tart dessert ice cream chupa chups cupcake chocolate bar sesame snaps. Croissant halvah cookie jujubes powder macaroon. Fruitcake bear claw bonbon jelly beans oat cake pie muffin Fruitcake marzipan toffee.",
418+
stream_get_contents($output->getStream())
419+
);
420+
}
421+
400422
public function testOverwriteWithSectionOutputWithNewlinesInMessage()
401423
{
402424
$sections = [];
@@ -417,7 +439,7 @@ public function testOverwriteWithSectionOutputWithNewlinesInMessage()
417439
rewind($output->getStream());
418440
$this->assertEquals(
419441
' 0/50 [>] 0% %message% Fruitcake marzipan toffee. Cupcake gummi bears tart dessert ice cream chupa chups cupcake chocolate bar sesame snaps. Croissant halvah cookie jujubes powder macaroon. Fruitcake bear claw bonbon jelly beans oat cake pie muffin Fruitcake marzipan toffee.'.\PHP_EOL.
420-
"\x1b[6A\x1b[0J 1/50 [>] 2% Twas brillig, and the slithy toves. Did gyre and gimble in the wabe: All mimsy were the borogoves, And the mome raths outgrabe.
442+
"\x1b[3A\x1b[0J 1/50 [>] 2% Twas brillig, and the slithy toves. Did gyre and gimble in the wabe: All mimsy were the borogoves, And the mome raths outgrabe.
421443
Beware the Jabberwock, my son! The jaws that bite, the claws that catch! Beware the Jubjub bird, and shun The frumious Bandersnatch! Fruitcake marzipan toffee. Cupcake gummi bears tart dessert ice cream chupa chups cupcake chocolate bar sesame snaps. Croissant halvah cookie jujubes powder macaroon. Fruitcake bear claw bonbon jelly beans oat cake pie muffin Fruitcake marzipan toffee.".\PHP_EOL.
422444
"\x1b[6A\x1b[0J 2/50 [>] 4% He took his vorpal sword in hand; Long time the manxome foe he sought— So rested he by the Tumtum tree And stood awhile in thought.
423445
And, as in uffish thought he stood, The Jabberwock, with eyes of flame, Came whiffling through the tulgey wood, And burbled as it came! Fruitcake marzipan toffee. Cupcake gummi bears tart dessert ice cream chupa chups cupcake chocolate bar sesame snaps. Croissant halvah cookie jujubes powder macaroon. Fruitcake bear claw bonbon jelly beans oat cake pie muffin Fruitcake marzipan toffee.".\PHP_EOL,

src/Symfony/Component/CssSelector/Parser/Tokenizer/TokenizerPatterns.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,22 @@ public function __construct()
4949
$this->identifierPattern = '-?(?:'.$this->nmStartPattern.')(?:'.$this->nmCharPattern.')*';
5050
$this->hashPattern = '#((?:'.$this->nmCharPattern.')+)';
5151
$this->numberPattern = '[+-]?(?:[0-9]*\.[0-9]+|[0-9]+)';
52-
$this->quotedStringPattern = '([^\n\r\f%s]|'.$this->stringEscapePattern.')*';
52+
$this->quotedStringPattern = '([^\n\r\f\\\\%s]|'.$this->stringEscapePattern.')*';
5353
}
5454

5555
public function getNewLineEscapePattern(): string
5656
{
57-
return '~^'.$this->newLineEscapePattern.'~';
57+
return '~'.$this->newLineEscapePattern.'~';
5858
}
5959

6060
public function getSimpleEscapePattern(): string
6161
{
62-
return '~^'.$this->simpleEscapePattern.'~';
62+
return '~'.$this->simpleEscapePattern.'~';
6363
}
6464

6565
public function getUnicodeEscapePattern(): string
6666
{
67-
return '~^'.$this->unicodeEscapePattern.'~i';
67+
return '~'.$this->unicodeEscapePattern.'~i';
6868
}
6969

7070
public function getIdentifierPattern(): string

src/Symfony/Component/CssSelector/Tests/Parser/ParserTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ public function getParserTestData()
138138
['div:not(div.foo)', ['Negation[Element[div]:not(Class[Element[div].foo])]']],
139139
['td ~ th', ['CombinedSelector[Element[td] ~ Element[th]]']],
140140
['.foo[data-bar][data-baz=0]', ["Attribute[Attribute[Class[Element[*].foo][data-bar]][data-baz = '0']]"]],
141+
['div#foo\.bar', ['Hash[Element[div]#foo.bar]']],
142+
['div.w-1\/3', ['Class[Element[div].w-1/3]']],
143+
['#test\:colon', ['Hash[Element[*]#test:colon]']],
144+
[".a\xc1b", ["Class[Element[*].a\xc1b]"]],
145+
// unicode escape: \22 == "
146+
['*[aval="\'\22\'"]', ['Attribute[Element[*][aval = \'\'"\'\']]']],
147+
['*[aval="\'\22 2\'"]', ['Attribute[Element[*][aval = \'\'"2\'\']]']],
148+
// unicode escape: \20 == (space)
149+
['*[aval="\'\20 \'"]', ['Attribute[Element[*][aval = \'\' \'\']]']],
150+
["*[aval=\"'\\20\r\n '\"]", ['Attribute[Element[*][aval = \'\' \'\']]']],
141151
];
142152
}
143153

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy