Skip to content

Commit ca06651

Browse files
Merge branch '4.4' into 5.2
* 4.4: [Console] ProgressBar clears too many lines on update [FrameworkBundle] Exclude unreadable files when executing About command [Bridge\Twig] Add 'form-control-range' for range input type Be explicit about transparent background color of links in toolbar [Translation] fix test case name [Cache] Fix wrong namespace in test [DependencyInjection] Fix return type
2 parents 8113f10 + a78fb18 commit ca06651

File tree

13 files changed

+220
-16
lines changed

13 files changed

+220
-16
lines changed

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,28 @@
134134
{% endblock %}
135135

136136
{% block form_widget_simple -%}
137-
{% if type is not defined or type != 'hidden' %}
138-
{%- set attr = attr|merge({class: (attr.class|default('') ~ (type|default('') == 'file' ? ' custom-file-input' : ' form-control'))|trim}) -%}
139-
{% endif %}
137+
{%- if type is not defined or type != 'hidden' -%}
138+
{%- set className = ' form-control' -%}
139+
{%- if type|default('') == 'file' -%}
140+
{%- set className = ' custom-file-input' -%}
141+
{%- elseif type|default('') == 'range' -%}
142+
{%- set className = ' form-control-range' -%}
143+
{%- endif -%}
144+
{%- set attr = attr|merge({class: (attr.class|default('') ~ className)|trim}) -%}
145+
{%- endif -%}
140146
{%- if type is defined and (type == 'range' or type == 'color') %}
141147
{# Attribute "required" is not supported #}
142148
{%- set required = false -%}
143149
{% endif %}
144150
{{- parent() -}}
145151
{%- endblock form_widget_simple %}
146152

147-
{%- block widget_attributes -%}
148-
{%- if not valid %}
153+
{% block widget_attributes -%}
154+
{%- if not valid -%}
149155
{% set attr = attr|merge({class: (attr.class|default('') ~ ' is-invalid')|trim}) %}
150-
{% endif -%}
156+
{%- endif -%}
151157
{{ parent() }}
152-
{%- endblock widget_attributes -%}
158+
{%- endblock widget_attributes %}
153159

154160
{% block button_widget -%}
155161
{%- set attr = attr|merge({class: (attr.class|default('btn-secondary') ~ ' btn')|trim}) -%}

src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap4LayoutTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
2020
use Symfony\Component\Form\Extension\Core\Type\PercentType;
2121
use Symfony\Component\Form\Extension\Core\Type\RadioType;
22+
use Symfony\Component\Form\Extension\Core\Type\RangeType;
2223
use Symfony\Component\Form\Extension\Core\Type\TextType;
2324
use Symfony\Component\Form\FormError;
2425

@@ -1227,6 +1228,41 @@ public function testPercentCustomSymbol()
12271228
[contains(.., "‱")]
12281229
]
12291230
]
1231+
'
1232+
);
1233+
}
1234+
1235+
public function testRange()
1236+
{
1237+
$form = $this->factory->createNamed('name', RangeType::class, 42, ['attr' => ['min' => 5]]);
1238+
1239+
$this->assertWidgetMatchesXpath(
1240+
$form->createView(),
1241+
['attr' => ['class' => 'my&class']],
1242+
'/input
1243+
[@type="range"]
1244+
[@name="name"]
1245+
[@value="42"]
1246+
[@min="5"]
1247+
[@class="my&class form-control-range"]
1248+
'
1249+
);
1250+
}
1251+
1252+
public function testRangeWithMinMaxValues()
1253+
{
1254+
$form = $this->factory->createNamed('name', RangeType::class, 42, ['attr' => ['min' => 5, 'max' => 57]]);
1255+
1256+
$this->assertWidgetMatchesXpath(
1257+
$form->createView(),
1258+
['attr' => ['class' => 'my&class']],
1259+
'/input
1260+
[@type="range"]
1261+
[@name="name"]
1262+
[@value="42"]
1263+
[@min="5"]
1264+
[@max="57"]
1265+
[@class="my&class form-control-range"]
12301266
'
12311267
);
12321268
}

src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ private static function formatFileSize(string $path): string
113113
} else {
114114
$size = 0;
115115
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS | \RecursiveDirectoryIterator::FOLLOW_SYMLINKS)) as $file) {
116-
$size += $file->getSize();
116+
if ($file->isReadable()) {
117+
$size += $file->getSize();
118+
}
117119
}
118120
}
119121

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Command\AboutCommand;
13+
14+
use Symfony\Bundle\FrameworkBundle\Command\AboutCommand;
15+
use Symfony\Bundle\FrameworkBundle\Console\Application;
16+
use Symfony\Bundle\FrameworkBundle\Tests\Command\AboutCommand\Fixture\TestAppKernel;
17+
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
18+
use Symfony\Component\Console\Tester\CommandTester;
19+
use Symfony\Component\Filesystem\Exception\IOException;
20+
use Symfony\Component\Filesystem\Filesystem;
21+
22+
class AboutCommandTest extends TestCase
23+
{
24+
/** @var Filesystem */
25+
private $fs;
26+
27+
protected function setUp(): void
28+
{
29+
$this->fs = new Filesystem();
30+
}
31+
32+
public function testAboutWithReadableFiles()
33+
{
34+
$kernel = new TestAppKernel('test', true);
35+
$this->fs->mkdir($kernel->getProjectDir());
36+
37+
$this->fs->dumpFile($kernel->getCacheDir().'/readable_file', 'The file content.');
38+
$this->fs->chmod($kernel->getCacheDir().'/readable_file', 0777);
39+
40+
$tester = $this->createCommandTester($kernel);
41+
$ret = $tester->execute([]);
42+
43+
$this->assertSame(0, $ret);
44+
$this->assertStringContainsString('Cache directory', $tester->getDisplay());
45+
$this->assertStringContainsString('Log directory', $tester->getDisplay());
46+
47+
$this->fs->chmod($kernel->getCacheDir().'/readable_file', 0777);
48+
49+
try {
50+
$this->fs->remove($kernel->getProjectDir());
51+
} catch (IOException $e) {
52+
}
53+
}
54+
55+
public function testAboutWithUnreadableFiles()
56+
{
57+
$kernel = new TestAppKernel('test', true);
58+
$this->fs->mkdir($kernel->getProjectDir());
59+
60+
// skip test on Windows; PHP can't easily set file as unreadable on Windows
61+
if ('\\' === \DIRECTORY_SEPARATOR) {
62+
$this->markTestSkipped('This test cannot run on Windows.');
63+
}
64+
65+
$this->fs->dumpFile($kernel->getCacheDir().'/unreadable_file', 'The file content.');
66+
$this->fs->chmod($kernel->getCacheDir().'/unreadable_file', 0222);
67+
68+
$tester = $this->createCommandTester($kernel);
69+
$ret = $tester->execute([]);
70+
71+
$this->assertSame(0, $ret);
72+
$this->assertStringContainsString('Cache directory', $tester->getDisplay());
73+
$this->assertStringContainsString('Log directory', $tester->getDisplay());
74+
75+
$this->fs->chmod($kernel->getCacheDir().'/unreadable_file', 0777);
76+
77+
try {
78+
$this->fs->remove($kernel->getProjectDir());
79+
} catch (IOException $e) {
80+
}
81+
}
82+
83+
private function createCommandTester(TestAppKernel $kernel): CommandTester
84+
{
85+
$application = new Application($kernel);
86+
$application->add(new AboutCommand());
87+
88+
return new CommandTester($application->find('about'));
89+
}
90+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Command\AboutCommand\Fixture;
13+
14+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
15+
use Symfony\Component\Config\Loader\LoaderInterface;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\HttpKernel\Kernel;
18+
19+
class TestAppKernel extends Kernel
20+
{
21+
public function registerBundles(): iterable
22+
{
23+
return [
24+
new FrameworkBundle(),
25+
];
26+
}
27+
28+
public function getProjectDir(): string
29+
{
30+
return __DIR__.'/test';
31+
}
32+
33+
public function registerContainerConfiguration(LoaderInterface $loader)
34+
{
35+
}
36+
37+
protected function build(ContainerBuilder $container)
38+
{
39+
}
40+
}

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,7 @@ protected function createContainerFromFile($file, $data = [], $resetCompilerPass
16961696
$container->getCompilerPassConfig()->setAfterRemovingPasses([]);
16971697
}
16981698
$container->getCompilerPassConfig()->setBeforeOptimizationPasses([new LoggerPass()]);
1699-
$container->getCompilerPassConfig()->setBeforeRemovingPasses([new AddConstraintValidatorsPass(), new TranslatorPass('translator.default', 'translation.reader')]);
1699+
$container->getCompilerPassConfig()->setBeforeRemovingPasses([new AddConstraintValidatorsPass(), new TranslatorPass()]);
17001700
$container->getCompilerPassConfig()->setAfterRemovingPasses([new AddAnnotationsCachedReaderPass()]);
17011701

17021702
if (!$compile) {

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
.sf-toolbar-block > a:hover {
106106
display: block;
107107
text-decoration: none;
108+
background-color: transparent;
108109
color: inherit;
109110
}
110111

@@ -243,6 +244,7 @@ div.sf-toolbar .sf-toolbar-block a:hover {
243244
padding: 0 10px;
244245
}
245246
.sf-toolbar-block-request .sf-toolbar-info-piece a {
247+
background-color: transparent;
246248
text-decoration: none;
247249
}
248250
.sf-toolbar-block-request .sf-toolbar-info-piece a:hover {

src/Symfony/Component/Cache/Tests/DataCollector/CacheDataCollectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Cache\Tests\Marshaller;
12+
namespace Symfony\Component\Cache\Tests\DataCollector;
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Cache\Adapter\TraceableAdapter;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ private function overwrite(string $message): void
462462
if ($this->overwrite) {
463463
if (null !== $this->previousMessage) {
464464
if ($this->output instanceof ConsoleSectionOutput) {
465-
$lines = floor(Helper::strlen($message) / $this->terminal->getWidth()) + $this->formatLineCount + 1;
465+
$lines = floor(Helper::strlenWithoutDecoration($this->output->getFormatter(), $message) / $this->terminal->getWidth()) + $this->formatLineCount + 1;
466466
$this->output->clear($lines);
467467
} else {
468468
if ($this->formatLineCount > 0) {

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,31 @@ public function testOverwriteWithSectionOutput()
343343
);
344344
}
345345

346+
public function testOverwriteWithAnsiSectionOutput()
347+
{
348+
// output has 43 visible characters plus 2 invisible ANSI characters
349+
putenv('COLUMNS=43');
350+
$sections = [];
351+
$stream = $this->getOutputStream(true);
352+
$output = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
353+
354+
$bar = new ProgressBar($output, 50, 0);
355+
$bar->setFormat(" \033[44;37m%current%/%max%\033[0m [%bar%] %percent:3s%%");
356+
$bar->start();
357+
$bar->display();
358+
$bar->advance();
359+
$bar->advance();
360+
361+
rewind($output->getStream());
362+
$this->assertSame(
363+
" \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,
366+
stream_get_contents($output->getStream())
367+
);
368+
putenv('COLUMNS=120');
369+
}
370+
346371
public function testOverwriteMultipleProgressBarsWithSectionOutputs()
347372
{
348373
$sections = [];

src/Symfony/Component/Translation/Tests/DependencyInjection/TranslationPassTest.php renamed to src/Symfony/Component/Translation/Tests/DependencyInjection/TranslatorPassTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Symfony\Component\DependencyInjection\Reference;
1919
use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
2020

21-
class TranslationPassTest extends TestCase
21+
class TranslatorPassTest extends TestCase
2222
{
2323
public function testValidCollector()
2424
{
@@ -35,7 +35,7 @@ public function testValidCollector()
3535
$container->setDefinition('translation.reader', $reader);
3636
$container->setDefinition('translation.xliff_loader', $loader);
3737

38-
$pass = new TranslatorPass('translator.default', 'translation.reader');
38+
$pass = new TranslatorPass();
3939
$pass->process($container);
4040

4141
$expectedReader = (new Definition())
@@ -72,7 +72,7 @@ public function testValidCommandsViewPathsArgument()
7272
;
7373
$container->setParameter('twig.default_path', 'templates');
7474

75-
$pass = new TranslatorPass('translator.default');
75+
$pass = new TranslatorPass();
7676
$pass->process($container);
7777

7878
$expectedViewPaths = ['other/templates', 'tpl'];
@@ -113,7 +113,7 @@ public function testCommandsViewPathsArgumentsAreIgnoredWithOldServiceDefinition
113113
;
114114
$container->setParameter('twig.default_path', 'templates');
115115

116-
$pass = new TranslatorPass('translator.default');
116+
$pass = new TranslatorPass();
117117
$pass->process($container);
118118

119119
$this->assertSame('templates', $debugCommand->getArgument(4));

src/Symfony/Contracts/Service/ServiceSubscriberInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ interface ServiceSubscriberInterface
4747
* * ['?Psr\Log\LoggerInterface'] is a shortcut for
4848
* * ['Psr\Log\LoggerInterface' => '?Psr\Log\LoggerInterface']
4949
*
50-
* @return array The required service types, optionally keyed by service names
50+
* @return string[] The required service types, optionally keyed by service names
5151
*/
5252
public static function getSubscribedServices();
5353
}

src/Symfony/Contracts/Service/ServiceSubscriberTrait.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ trait ServiceSubscriberTrait
2424
/** @var ContainerInterface */
2525
protected $container;
2626

27+
/**
28+
* {@inheritdoc}
29+
*/
2730
public static function getSubscribedServices(): array
2831
{
2932
static $services;

0 commit comments

Comments
 (0)