Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ee020a2

Browse filesBrowse files
Merge branch '5.4' into 6.0
* 5.4: [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 72e2151 + 6b3efff commit ee020a2
Copy full SHA for ee020a2

File tree

Expand file treeCollapse file tree

15 files changed

+338
-57
lines changed
Filter options
Expand file treeCollapse file tree

15 files changed

+338
-57
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public function shutdown()
200200
// store failing status
201201
$isFailing = !$configuration->tolerates($this->deprecationGroups);
202202

203-
$this->displayDeprecations($groups, $configuration, $isFailing);
203+
$this->displayDeprecations($groups, $configuration);
204204

205205
$this->resetDeprecationGroups();
206206

@@ -213,7 +213,7 @@ public function shutdown()
213213
}
214214

215215
$isFailingAtShutdown = !$configuration->tolerates($this->deprecationGroups);
216-
$this->displayDeprecations($groups, $configuration, $isFailingAtShutdown);
216+
$this->displayDeprecations($groups, $configuration);
217217

218218
if ($configuration->isGeneratingBaseline()) {
219219
$configuration->writeBaseline();
@@ -289,11 +289,10 @@ private static function colorize($str, $red)
289289
/**
290290
* @param string[] $groups
291291
* @param Configuration $configuration
292-
* @param bool $isFailing
293292
*
294293
* @throws \InvalidArgumentException
295294
*/
296-
private function displayDeprecations($groups, $configuration, $isFailing)
295+
private function displayDeprecations($groups, $configuration)
297296
{
298297
$cmp = function ($a, $b) {
299298
return $b->count() - $a->count();
@@ -320,7 +319,8 @@ private function displayDeprecations($groups, $configuration, $isFailing)
320319
fwrite($handle, "\n".self::colorize($deprecationGroupMessage, 'legacy' !== $group && 'indirect' !== $group)."\n");
321320
}
322321

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

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Configuration.php
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,32 @@ public function tolerates(array $deprecationGroups)
165165
return true;
166166
}
167167

168+
/**
169+
* @param array<string,DeprecationGroup> $deprecationGroups
170+
*
171+
* @return bool true if the threshold is not reached for the deprecation type nor for the total
172+
*/
173+
public function toleratesForGroup(string $groupName, array $deprecationGroups): bool
174+
{
175+
$grandTotal = 0;
176+
177+
foreach ($deprecationGroups as $type => $group) {
178+
if ('legacy' !== $type) {
179+
$grandTotal += $group->count();
180+
}
181+
}
182+
183+
if ($grandTotal > $this->thresholds['total']) {
184+
return false;
185+
}
186+
187+
if (\in_array($groupName, ['self', 'direct', 'indirect'], true) && $deprecationGroups[$groupName]->count() > $this->thresholds[$groupName]) {
188+
return false;
189+
}
190+
191+
return true;
192+
}
193+
168194
/**
169195
* @return bool
170196
*/

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php
+97Lines 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 = [];
+36Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Helper/ProgressBar.php
+6-11Lines 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;
@@ -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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php
+25-3Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/CssSelector/Parser/Tokenizer/TokenizerPatterns.php
+4-4Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/CssSelector/Tests/Parser/ParserTest.php
+10Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.