Skip to content

Commit c751d16

Browse files
committed
Merge branch '2.8' into 3.0
* 2.8: (23 commits) [Filesystem] Better error handling in remove() [DependencyInjection] Add coverage for invalid Expression in exportParameters [DependencyInjection] Add coverage for all invalid arguments in exportParameters anonymous services are always private [Console] Correct time formatting. [WebProfilerBundle] Fixed error from unset twig variable Force profiler toolbar svg display [DependencyInjection] Resolve aliases before removing abstract services + add tests Fix Dom Crawler select option with empty value Remove unnecessary option assignment fix tests (use non-deprecated options) remove unused variable mock the proper method [PropertyAccess] Fix regression [HttpFoundation] Improve phpdoc [Logging] Add support for firefox in ChromePhpHandler Windows 10 version check in just one line Detect CLI color support for Windows 10 build 10586 [Security] Fixed SwitchUserListener when exiting an impersonication with AnonymousToken [EventDispatcher] Try first if the event is Stopped ...
2 parents c115c71 + 5914cf1 commit c751d16

File tree

6 files changed

+59
-13
lines changed

6 files changed

+59
-13
lines changed

Compiler/PassConfig.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public function __construct()
5858

5959
$this->removingPasses = array(
6060
new RemovePrivateAliasesPass(),
61-
new RemoveAbstractDefinitionsPass(),
6261
new ReplaceAliasByActualDefinitionPass(),
62+
new RemoveAbstractDefinitionsPass(),
6363
new RepeatedPass(array(
6464
new AnalyzeServiceReferencesPass(),
6565
new InlineServiceDefinitionsPass(),
@@ -102,8 +102,7 @@ public function addPass(CompilerPassInterface $pass, $type = self::TYPE_BEFORE_O
102102
throw new InvalidArgumentException(sprintf('Invalid type "%s".', $type));
103103
}
104104

105-
$passes = &$this->$property;
106-
$passes[] = $pass;
105+
$this->{$property}[] = $pass;
107106
}
108107

109108
/**

Loader/XmlFileLoader.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,7 @@ private function processAnonymousServices(\DOMDocument $xml, $file)
302302
// give it a unique name
303303
$id = sprintf('%s_%d', hash('sha256', $file), ++$count);
304304
$node->setAttribute('id', $id);
305-
306-
if ($services = $this->getChildren($node, 'service')) {
307-
$definitions[$id] = array($node, $file, true);
308-
$services[0]->setAttribute('id', $id);
309-
}
305+
$definitions[$id] = array($node, $file, true);
310306
}
311307
}
312308

Tests/ContainerBuilderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,21 @@ public function testExtensionConfig()
687687
$this->assertEquals(array($second, $first), $configs);
688688
}
689689

690+
public function testAbstractAlias()
691+
{
692+
$container = new ContainerBuilder();
693+
694+
$abstract = new Definition('AbstractClass');
695+
$abstract->setAbstract(true);
696+
697+
$container->setDefinition('abstract_service', $abstract);
698+
$container->setAlias('abstract_alias', 'abstract_service');
699+
700+
$container->compile();
701+
702+
$this->assertSame('abstract_service', (string) $container->getAlias('abstract_alias'));
703+
}
704+
690705
public function testLazyLoadedService()
691706
{
692707
$loader = new ClosureLoader($container = new ContainerBuilder());

Tests/Dumper/PhpDumperTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
1717
use Symfony\Component\DependencyInjection\Reference;
1818
use Symfony\Component\DependencyInjection\Definition;
19+
use Symfony\Component\DependencyInjection\Variable;
20+
use Symfony\Component\ExpressionLanguage\Expression;
1921

2022
class PhpDumperTest extends \PHPUnit_Framework_TestCase
2123
{
@@ -85,14 +87,25 @@ public function testDumpRelativeDir()
8587
}
8688

8789
/**
90+
* @dataProvider provideInvalidParameters
8891
* @expectedException \InvalidArgumentException
8992
*/
90-
public function testExportParameters()
93+
public function testExportParameters($parameters)
9194
{
92-
$dumper = new PhpDumper(new ContainerBuilder(new ParameterBag(array('foo' => new Reference('foo')))));
95+
$dumper = new PhpDumper(new ContainerBuilder(new ParameterBag($parameters)));
9396
$dumper->dump();
9497
}
9598

99+
public function provideInvalidParameters()
100+
{
101+
return array(
102+
array(array('foo' => new Definition('stdClass'))),
103+
array(array('foo' => new Expression('service("foo").foo() ~ (container.hasparameter("foo") ? parameter("foo") : "default")'))),
104+
array(array('foo' => new Reference('foo'))),
105+
array(array('foo' => new Variable('foo'))),
106+
);
107+
}
108+
96109
public function testAddParameters()
97110
{
98111
$container = include self::$fixturesPath.'/containers/container8.php';

Tests/Fixtures/xml/services5.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
</service>
1515
</argument>
1616
<property name="p" type="service">
17-
<service class="BazClass" />
17+
<service class="BuzClass" />
1818
</property>
1919
</service>
20+
<service id="bar" parent="foo" />
21+
<service class="BizClass">
22+
<tag name="biz_tag" />
23+
</service>
2024
</services>
2125
</container>

Tests/Loader/XmlFileLoaderTest.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function testLoadAnonymousServices()
163163
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
164164
$loader->load('services5.xml');
165165
$services = $container->getDefinitions();
166-
$this->assertCount(4, $services, '->load() attributes unique ids to anonymous services');
166+
$this->assertCount(6, $services, '->load() attributes unique ids to anonymous services');
167167

168168
// anonymous service as an argument
169169
$args = $services['foo']->getArguments();
@@ -172,6 +172,7 @@ public function testLoadAnonymousServices()
172172
$this->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
173173
$inner = $services[(string) $args[0]];
174174
$this->assertEquals('BarClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
175+
$this->assertFalse($inner->isPublic());
175176

176177
// inner anonymous services
177178
$args = $inner->getArguments();
@@ -188,7 +189,25 @@ public function testLoadAnonymousServices()
188189
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $property, '->load() converts anonymous services to references to "normal" services');
189190
$this->assertTrue(isset($services[(string) $property]), '->load() makes a reference to the created ones');
190191
$inner = $services[(string) $property];
191-
$this->assertEquals('BazClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
192+
$this->assertEquals('BuzClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
193+
$this->assertFalse($inner->isPublic());
194+
195+
// "wild" service
196+
$service = $container->findTaggedServiceIds('biz_tag');
197+
$this->assertCount(1, $service);
198+
199+
foreach ($service as $id => $tag) {
200+
$service = $container->getDefinition($id);
201+
}
202+
$this->assertEquals('BizClass', $service->getClass(), '->load() uses the same configuration as for the anonymous ones');
203+
$this->assertFalse($service->isPublic());
204+
205+
// anonymous services are shared when using decoration definitions
206+
$container->compile();
207+
$services = $container->getDefinitions();
208+
$fooArgs = $services['foo']->getArguments();
209+
$barArgs = $services['bar']->getArguments();
210+
$this->assertSame($fooArgs[0], $barArgs[0]);
192211
}
193212

194213
public function testLoadServices()

0 commit comments

Comments
 (0)