Skip to content

Commit 5324e5b

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: Update twig.html.twig [2.7] [FrameworkBundle] minor fix tests added by symfony#17569 fixed CS fixed CS documented the $url parameter better [Form] add test for ArrayChoiceList handling null [Form] fix edge cases with choice placeholder register commands from kernel when accessing list Update FileSystem
2 parents 095ebbe + 24cdae7 commit 5324e5b

File tree

18 files changed

+267
-39
lines changed

18 files changed

+267
-39
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
{%- endblock choice_widget_expanded -%}
5353

5454
{%- block choice_widget_collapsed -%}
55-
{%- if required and placeholder is none and not placeholder_in_choices and not multiple -%}
55+
{%- if required and placeholder is none and not placeholder_in_choices and not multiple and (attr.size is not defined or attr.size <= 1) -%}
5656
{% set required = false %}
5757
{%- endif -%}
5858
<select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>

src/Symfony/Bundle/FrameworkBundle/Console/Application.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ public function doRun(InputInterface $input, OutputInterface $output)
6969
{
7070
$this->kernel->boot();
7171

72-
if (!$this->commandsRegistered) {
73-
$this->registerCommands();
74-
75-
$this->commandsRegistered = true;
76-
}
77-
7872
$container = $this->kernel->getContainer();
7973

8074
foreach ($this->all() as $command) {
@@ -98,8 +92,36 @@ public function doRun(InputInterface $input, OutputInterface $output)
9892
return parent::doRun($input, $output);
9993
}
10094

95+
/**
96+
* {@inheritdoc}
97+
*/
98+
public function get($name)
99+
{
100+
$this->registerCommands();
101+
102+
return parent::get($name);
103+
}
104+
105+
/**
106+
* {@inheritdoc}
107+
*/
108+
public function all($namespace = null)
109+
{
110+
$this->registerCommands();
111+
112+
return parent::all($namespace);
113+
}
114+
101115
protected function registerCommands()
102116
{
117+
if ($this->commandsRegistered) {
118+
return;
119+
}
120+
121+
$this->commandsRegistered = true;
122+
123+
$this->kernel->boot();
124+
103125
$container = $this->kernel->getContainer();
104126

105127
foreach ($this->kernel->getBundles() as $bundle) {

src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_collapsed.html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<select
2-
<?php if ($required && null === $placeholder && $placeholder_in_choices === false && $multiple === false):
2+
<?php if ($required && null === $placeholder && $placeholder_in_choices === false && $multiple === false && (!isset($attr['size']) || $attr['size'] <= 1)):
33
$required = false;
44
endif; ?>
55
<?php echo $view['form']->block($form, 'widget_attributes', array(

src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php

Lines changed: 83 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Console;
1313

14-
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1514
use Symfony\Bundle\FrameworkBundle\Console\Application;
15+
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
16+
use Symfony\Component\Console\Command\Command;
1617
use Symfony\Component\Console\Input\ArrayInput;
1718
use Symfony\Component\Console\Output\NullOutput;
1819
use Symfony\Component\Console\Tester\ApplicationTester;
@@ -23,7 +24,7 @@ public function testBundleInterfaceImplementation()
2324
{
2425
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
2526

26-
$kernel = $this->getKernel(array($bundle));
27+
$kernel = $this->getKernel(array($bundle), true);
2728

2829
$application = new Application($kernel);
2930
$application->doRun(new ArrayInput(array('list')), new NullOutput());
@@ -34,10 +35,73 @@ public function testBundleCommandsAreRegistered()
3435
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
3536
$bundle->expects($this->once())->method('registerCommands');
3637

37-
$kernel = $this->getKernel(array($bundle));
38+
$kernel = $this->getKernel(array($bundle), true);
3839

3940
$application = new Application($kernel);
4041
$application->doRun(new ArrayInput(array('list')), new NullOutput());
42+
43+
// Calling twice: registration should only be done once.
44+
$application->doRun(new ArrayInput(array('list')), new NullOutput());
45+
}
46+
47+
public function testBundleCommandsAreRetrievable()
48+
{
49+
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
50+
$bundle->expects($this->once())->method('registerCommands');
51+
52+
$kernel = $this->getKernel(array($bundle));
53+
54+
$application = new Application($kernel);
55+
$application->all();
56+
57+
// Calling twice: registration should only be done once.
58+
$application->all();
59+
}
60+
61+
public function testBundleSingleCommandIsRetrievable()
62+
{
63+
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
64+
$bundle->expects($this->once())->method('registerCommands');
65+
66+
$kernel = $this->getKernel(array($bundle));
67+
68+
$application = new Application($kernel);
69+
70+
$command = new Command('example');
71+
$application->add($command);
72+
73+
$this->assertSame($command, $application->get('example'));
74+
}
75+
76+
public function testBundleCommandCanBeFound()
77+
{
78+
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
79+
$bundle->expects($this->once())->method('registerCommands');
80+
81+
$kernel = $this->getKernel(array($bundle));
82+
83+
$application = new Application($kernel);
84+
85+
$command = new Command('example');
86+
$application->add($command);
87+
88+
$this->assertSame($command, $application->find('example'));
89+
}
90+
91+
public function testBundleCommandCanBeFoundByAlias()
92+
{
93+
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
94+
$bundle->expects($this->once())->method('registerCommands');
95+
96+
$kernel = $this->getKernel(array($bundle));
97+
98+
$application = new Application($kernel);
99+
100+
$command = new Command('example');
101+
$command->setAliases(array('alias'));
102+
$application->add($command);
103+
104+
$this->assertSame($command, $application->find('alias'));
41105
}
42106

43107
public function testBundleCommandsHaveRightContainer()
@@ -46,7 +110,7 @@ public function testBundleCommandsHaveRightContainer()
46110
$command->setCode(function () {});
47111
$command->expects($this->exactly(2))->method('setContainer');
48112

49-
$application = new Application($this->getKernel(array()));
113+
$application = new Application($this->getKernel(array(), true));
50114
$application->setAutoExit(false);
51115
$application->setCatchExceptions(false);
52116
$application->add($command);
@@ -59,21 +123,23 @@ public function testBundleCommandsHaveRightContainer()
59123
$tester->run(array('command' => 'foo'));
60124
}
61125

62-
private function getKernel(array $bundles)
126+
private function getKernel(array $bundles, $useDispatcher = false)
63127
{
64-
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
65-
$dispatcher
66-
->expects($this->atLeastOnce())
67-
->method('dispatch')
68-
;
69-
70128
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
71-
$container
72-
->expects($this->atLeastOnce())
73-
->method('get')
74-
->with($this->equalTo('event_dispatcher'))
75-
->will($this->returnValue($dispatcher))
76-
;
129+
130+
if ($useDispatcher) {
131+
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
132+
$dispatcher
133+
->expects($this->atLeastOnce())
134+
->method('dispatch')
135+
;
136+
$container
137+
->expects($this->atLeastOnce())
138+
->method('get')
139+
->with($this->equalTo('event_dispatcher'))
140+
->will($this->returnValue($dispatcher));
141+
}
142+
77143
$container
78144
->expects($this->once())
79145
->method('hasParameter')

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/twig.html.twig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,26 @@
3131
{% endblock %}
3232

3333
{% block menu %}
34+
<<<<<<< HEAD
3435
<span class="label">
3536
<span class="icon">{{ include('@WebProfiler/Icon/twig.svg') }}</span>
3637
<strong>Twig</strong>
38+
=======
39+
<span class="label">
40+
<span class="icon">
41+
<svg width="17pt" height="24pt" viewBox="0 0 21 28" version="1.1" xmlns="http://www.w3.org/2000/svg">
42+
<path fill="#3f4040" d=" M 1.12 4.11 C 7.37 3.95 13.63 3.95 19.88 4.11 C 20.12 10.37 20.13 16.63 19.88 22.89 C 13.63 23.05 7.37 23.05 1.12 22.89 C 0.87 16.63 0.88 10.37 1.12 4.11 Z" />
43+
<path fill="#dddddd" d=" M 1.87 4.87 C 7.62 4.64 13.38 4.64 19.13 4.87 C 19.36 10.62 19.36 16.38 19.13 22.13 C 13.38 22.36 7.62 22.36 1.87 22.13 C 1.64 16.38 1.64 10.62 1.87 4.87 Z" />
44+
<path fill="#3f4040" d=" M 3.99 7.05 C 8.33 6.95 12.67 6.95 17.01 7.05 C 17.01 7.77 17.01 9.23 17.01 9.95 C 12.67 10.05 8.33 10.05 3.99 9.95 C 3.99 9.23 3.99 7.77 3.99 7.05 Z" />
45+
<path fill="#3f4040" d=" M 4.00 11.99 C 4.75 11.99 6.25 11.99 6.99 11.99 C 6.99 14.66 6.99 17.34 7.00 20.01 C 6.25 20.01 4.75 20.01 4.00 20.01 C 4.01 17.34 4.01 14.66 4.00 11.99 Z" />
46+
<path fill="#3f4040" d=" M 8.99 11.99 C 11.66 12.01 14.33 12.01 17.01 11.99 C 16.99 14.66 16.99 17.34 17.01 20.01 C 14.34 19.99 11.67 19.99 9.00 20.01 C 9.01 17.33 9.01 14.66 8.99 11.99 Z" />
47+
</svg>
48+
</span>
49+
<strong>Twig</strong>
50+
<span class="count">
51+
<span>{{ collector.templatecount }}</span>
52+
<span>{{ '%0.0f ms'|format(collector.time) }}</span>
53+
>>>>>>> 2.7
3754
</span>
3855
{% endblock %}
3956

src/Symfony/Component/Console/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ public function has($name)
430430
public function getNamespaces()
431431
{
432432
$namespaces = array();
433-
foreach ($this->commands as $command) {
433+
foreach ($this->all() as $command) {
434434
$namespaces = array_merge($namespaces, $this->extractAllNamespaces($command->getName()));
435435

436436
foreach ($command->getAliases() as $alias) {

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ public function mkdir($dirs, $mode = 0777)
115115
public function exists($files)
116116
{
117117
foreach ($this->toIterator($files) as $file) {
118+
if ('\\' === DIRECTORY_SEPARATOR && strlen($file) > 258) {
119+
throw new IOException('Could not check if file exist because path length exceeds 258 characters.', 0, null, $file);
120+
}
121+
118122
if (!file_exists($file)) {
119123
return false;
120124
}
@@ -154,7 +158,7 @@ public function remove($files)
154158
$files = iterator_to_array($this->toIterator($files));
155159
$files = array_reverse($files);
156160
foreach ($files as $file) {
157-
if (!file_exists($file) && !is_link($file)) {
161+
if (!$this->exists($file) && !is_link($file)) {
158162
continue;
159163
}
160164

@@ -268,7 +272,7 @@ public function chgrp($files, $group, $recursive = false)
268272
public function rename($origin, $target, $overwrite = false)
269273
{
270274
// we check that target does not exist
271-
if (!$overwrite && is_readable($target)) {
275+
if (!$overwrite && $this->isReadable($target)) {
272276
throw new IOException(sprintf('Cannot rename because the target "%s" already exists.', $target), 0, null, $target);
273277
}
274278

@@ -277,6 +281,22 @@ public function rename($origin, $target, $overwrite = false)
277281
}
278282
}
279283

284+
/**
285+
* Tells whether a file exists and is readable.
286+
*
287+
* @param string $filename Path to the file.
288+
*
289+
* @throws IOException When windows path is longer than 258 characters
290+
*/
291+
private function isReadable($filename)
292+
{
293+
if ('\\' === DIRECTORY_SEPARATOR && strlen($filename) > 258) {
294+
throw new IOException('Could not check if file is readable because path length exceeds 258 characters.', 0, null, $filename);
295+
}
296+
297+
return is_readable($filename);
298+
}
299+
280300
/**
281301
* Creates a symbolic link or copy a directory.
282302
*

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,28 @@ public function testFilesExists()
358358
$this->assertTrue($this->filesystem->exists($basePath.'folder'));
359359
}
360360

361+
/**
362+
* @expectedException \Symfony\Component\Filesystem\Exception\IOException
363+
*/
364+
public function testFilesExistsFails()
365+
{
366+
if ('\\' !== DIRECTORY_SEPARATOR) {
367+
$this->markTestSkipped('Test covers edge case on Windows only.');
368+
}
369+
370+
$basePath = $this->workspace.'\\directory\\';
371+
372+
$oldPath = getcwd();
373+
mkdir($basePath);
374+
chdir($basePath);
375+
$file = str_repeat('T', 259 - strlen($basePath));
376+
$path = $basePath.$file;
377+
exec('TYPE NUL >>'.$file); // equivalent of touch, we can not use the php touch() here because it suffers from the same limitation
378+
self::$longPathNamesWindows[] = $path; // save this so we can clean up later
379+
chdir($oldPath);
380+
$this->filesystem->exists($path);
381+
}
382+
361383
public function testFilesExistsTraversableObjectOfFilesAndDirectories()
362384
{
363385
$basePath = $this->workspace.DIRECTORY_SEPARATOR;

src/Symfony/Component/Filesystem/Tests/FilesystemTestCase.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class FilesystemTestCase extends \PHPUnit_Framework_TestCase
1717
{
1818
private $umask;
1919

20+
static protected $longPathNamesWindows = array();
21+
2022
/**
2123
* @var \Symfony\Component\Filesystem\Filesystem
2224
*/
@@ -31,6 +33,12 @@ class FilesystemTestCase extends \PHPUnit_Framework_TestCase
3133

3234
public static function setUpBeforeClass()
3335
{
36+
if (!empty(self::$longPathNamesWindows)) {
37+
foreach (self::$longPathNamesWindows as $path) {
38+
exec('DEL '.$path);
39+
}
40+
}
41+
3442
if ('\\' === DIRECTORY_SEPARATOR && null === self::$symlinkOnWindows) {
3543
$target = tempnam(sys_get_temp_dir(), 'sl');
3644
$link = sys_get_temp_dir().'/sl'.microtime(true).mt_rand();

src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ private static function addChoiceViewGroupedBy($groupBy, $choice, $value, $label
246246

247247
$groupLabel = (string) $groupLabel;
248248

249-
// Initialize the group views if necessary. Unnnecessarily built group
249+
// Initialize the group views if necessary. Unnecessarily built group
250250
// views will be cleaned up at the end of createView()
251251
if (!isset($preferredViews[$groupLabel])) {
252252
$preferredViews[$groupLabel] = new ChoiceGroupView($groupLabel);

0 commit comments

Comments
 (0)