Skip to content

Commit b959370

Browse files
committed
Merge branch '3.0'
* 3.0: (21 commits) fixed typo fixed typo Fixed a minor XML issue in a translation file Fix merge Fix merge Fix merge Fix merge Update twig.html.twig PhpUnitNoDedicateAssertFixer results disable the assets helper when assets are disabled Improve Norwegian translations [2.7] [FrameworkBundle] minor fix tests added by #17569 Fixed the antialiasing of the toolbar text Simplify markdown for PR template 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 ...
2 parents 811d8d6 + 03fd38f commit b959370

11 files changed

+167
-27
lines changed

Console/Application.php

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

70-
if (!$this->commandsRegistered) {
71-
$this->registerCommands();
72-
73-
$this->commandsRegistered = true;
74-
}
75-
7670
$container = $this->kernel->getContainer();
7771

7872
foreach ($this->all() as $command) {
@@ -86,8 +80,36 @@ public function doRun(InputInterface $input, OutputInterface $output)
8680
return parent::doRun($input, $output);
8781
}
8882

83+
/**
84+
* {@inheritdoc}
85+
*/
86+
public function get($name)
87+
{
88+
$this->registerCommands();
89+
90+
return parent::get($name);
91+
}
92+
93+
/**
94+
* {@inheritdoc}
95+
*/
96+
public function all($namespace = null)
97+
{
98+
$this->registerCommands();
99+
100+
return parent::all($namespace);
101+
}
102+
89103
protected function registerCommands()
90104
{
105+
if ($this->commandsRegistered) {
106+
return;
107+
}
108+
109+
$this->commandsRegistered = true;
110+
111+
$this->kernel->boot();
112+
91113
$container = $this->kernel->getContainer();
92114

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

DependencyInjection/FrameworkExtension.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,11 @@ private function registerTemplatingConfiguration(array $config, $ide, ContainerB
549549
'Symfony\\Bundle\\FrameworkBundle\\Templating\\Loader\\FilesystemLoader',
550550
));
551551

552-
$container->getDefinition('templating.helper.assets')->replaceArgument(0, new Reference('assets.packages'));
552+
if ($container->has('assets.packages')) {
553+
$container->getDefinition('templating.helper.assets')->replaceArgument(0, new Reference('assets.packages'));
554+
} else {
555+
$container->removeDefinition('templating.helper.assets');
556+
}
553557
}
554558
}
555559

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(

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')
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', array(
4+
'templating' => array(
5+
'engines' => array('php', 'twig'),
6+
),
7+
));
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', array(
4+
'assets' => false,
5+
'templating' => array(
6+
'engines' => array('php'),
7+
),
8+
));
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:templating>
10+
<framework:engine>php</framework:engine>
11+
<framework:engine>twig</framework:engine>
12+
</framework:templating>
13+
</framework:config>
14+
</container>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
framework:
2+
templating:
3+
engines: [php, twig]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework:
2+
assets: false
3+
templating:
4+
engines: [php]

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,14 +493,21 @@ public function testAssetHelperWhenAssetsAreEnabled()
493493
$this->assertSame('assets.packages', (string) $packages);
494494
}
495495

496-
public function testAssetHelperWhenTemplatesAreEnabledAndAssetsAreDisabled()
496+
public function testAssetHelperWhenTemplatesAreEnabledAndNoAssetsConfiguration()
497497
{
498-
$container = $this->createContainerFromFile('full');
498+
$container = $this->createContainerFromFile('templating_no_assets');
499499
$packages = $container->getDefinition('templating.helper.assets')->getArgument(0);
500500

501501
$this->assertSame('assets.packages', (string) $packages);
502502
}
503503

504+
public function testAssetsHelperIsRemovedWhenPhpTemplatingEngineIsEnabledAndAssetsAreDisabled()
505+
{
506+
$container = $this->createContainerFromFile('templating_php_assets_disabled');
507+
508+
$this->assertTrue(!$container->has('templating.helper.assets'), 'The templating.helper.assets helper service is removed when assets are disabled.');
509+
}
510+
504511
public function testAssetHelperWhenAssetsAndTemplatesAreDisabled()
505512
{
506513
$container = $this->createContainerFromFile('default_config');

0 commit comments

Comments
 (0)