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 e939a42

Browse filesBrowse files
committed
[DependencyInjection] added some tests for PhpDumper when the container is compiled
1 parent 3827e3e commit e939a42
Copy full SHA for e939a42

File tree

Expand file treeCollapse file tree

7 files changed

+228
-19
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+228
-19
lines changed

‎tests/Symfony/Tests/Component/DependencyInjection/Dumper/PhpDumperTest.php

Copy file name to clipboardExpand all lines: tests/Symfony/Tests/Component/DependencyInjection/Dumper/PhpDumperTest.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,17 @@ public function testAddParameters()
9696

9797
public function testAddService()
9898
{
99+
// without compilation
99100
$container = include self::$fixturesPath.'/containers/container9.php';
100101
$dumper = new PhpDumper($container);
101102
$this->assertEquals(str_replace('%path%', str_replace('\\','\\\\',self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), file_get_contents(self::$fixturesPath.'/php/services9.php')), $dumper->dump(), '->dump() dumps services');
102103

104+
// with compilation
105+
$container = include self::$fixturesPath.'/containers/container9.php';
106+
$container->compile();
107+
$dumper = new PhpDumper($container);
108+
$this->assertEquals(str_replace('%path%', str_replace('\\','\\\\',self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), file_get_contents(self::$fixturesPath.'/php/services9_compiled.php')), $dumper->dump(), '->dump() dumps services');
109+
103110
$dumper = new PhpDumper($container = new ContainerBuilder());
104111
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
105112
try {

‎tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container9.php

Copy file name to clipboardExpand all lines: tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container9.php
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
addTag('foo', array('bar' => 'bar'))->
1515
setFactoryClass('FooClass')->
1616
setFactoryMethod('getInstance')->
17-
setArguments(array('foo', new Reference('foo.baz'), array('%foo%' => 'foo is %foo%', 'bar' => '%foo%'), true, new Reference('service_container')))->
17+
setArguments(array('foo', new Reference('foo.baz'), array('%foo%' => 'foo is %foo%', 'foobar' => '%foo%'), true, new Reference('service_container')))->
1818
setProperties(array('foo' => 'bar', 'moo' => new Reference('foo.baz')))->
19-
setScope('prototype')->
2019
addMethodCall('setBar', array(new Reference('bar')))->
2120
addMethodCall('initialize')->
2221
setConfigurator('sc_configure')
@@ -33,7 +32,10 @@
3332
setFactoryMethod('getInstance')->
3433
setConfigurator(array('%baz_class%', 'configureStatic1'))
3534
;
36-
$container->register('foo_bar', '%foo_class%');
35+
$container->
36+
register('foo_bar', '%foo_class%')->
37+
setScope('prototype')
38+
;
3739
$container->getParameterBag()->clear();
3840
$container->getParameterBag()->add(array(
3941
'baz_class' => 'BazClass',
@@ -50,7 +52,7 @@
5052
addMethodCall('setBar', array(new Reference('foobaz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)))
5153
;
5254
$container->
53-
register('factory_service')->
55+
register('factory_service', 'Bar')->
5456
setFactoryService('foo.baz')->
5557
setFactoryMethod('getInstance')
5658
;

‎tests/Symfony/Tests/Component/DependencyInjection/Fixtures/graphviz/services9.dot

Copy file name to clipboardExpand all lines: tests/Symfony/Tests/Component/DependencyInjection/Fixtures/graphviz/services9.dot
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ digraph sc {
33
node [fontsize="11" fontname="Arial" shape="record"];
44
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
55

6-
node_foo [label="foo (alias_for_foo)\nFooClass\n", shape=record, fillcolor="#eeeeee", style="dotted"];
6+
node_foo [label="foo (alias_for_foo)\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
77
node_bar [label="bar\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
88
node_foo_baz [label="foo.baz\nBazClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
9-
node_foo_bar [label="foo_bar\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
9+
node_foo_bar [label="foo_bar\nFooClass\n", shape=record, fillcolor="#eeeeee", style="dotted"];
1010
node_method_call1 [label="method_call1\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
11-
node_factory_service [label="factory_service\n\n", shape=record, fillcolor="#eeeeee", style="filled"];
11+
node_factory_service [label="factory_service\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"];
1212
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
1313
node_foo2 [label="foo2\n\n", shape=record, fillcolor="#ff9999", style="filled"];
1414
node_foo3 [label="foo3\n\n", shape=record, fillcolor="#ff9999", style="filled"];

‎tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services9.php

Copy file name to clipboardExpand all lines: tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services9.php
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function getBarService()
4646
* This service is shared.
4747
* This method always returns the same instance of the service.
4848
*
49-
* @return Object An instance returned by foo.baz::getInstance().
49+
* @return Bar A Bar instance.
5050
*/
5151
protected function getFactoryServiceService()
5252
{
@@ -56,13 +56,16 @@ protected function getFactoryServiceService()
5656
/**
5757
* Gets the 'foo' service.
5858
*
59+
* This service is shared.
60+
* This method always returns the same instance of the service.
61+
*
5962
* @return FooClass A FooClass instance.
6063
*/
6164
protected function getFooService()
6265
{
6366
$a = $this->get('foo.baz');
6467

65-
$instance = call_user_func(array('FooClass', 'getInstance'), 'foo', $a, array($this->getParameter('foo') => 'foo is '.$this->getParameter('foo'), 'bar' => $this->getParameter('foo')), true, $this);
68+
$this->services['foo'] = $instance = call_user_func(array('FooClass', 'getInstance'), 'foo', $a, array($this->getParameter('foo') => 'foo is '.$this->getParameter('foo'), 'foobar' => $this->getParameter('foo')), true, $this);
6669

6770
$instance->setBar($this->get('bar'));
6871
$instance->initialize();
@@ -93,15 +96,12 @@ protected function getFoo_BazService()
9396
/**
9497
* Gets the 'foo_bar' service.
9598
*
96-
* This service is shared.
97-
* This method always returns the same instance of the service.
98-
*
9999
* @return Object A %foo_class% instance.
100100
*/
101101
protected function getFooBarService()
102102
{
103103
$class = $this->getParameter('foo_class');
104-
return $this->services['foo_bar'] = new $class();
104+
return new $class();
105105
}
106106

107107
/**
+199Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\ContainerInterface;
4+
use Symfony\Component\DependencyInjection\Container;
5+
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
6+
use Symfony\Component\DependencyInjection\Reference;
7+
use Symfony\Component\DependencyInjection\Parameter;
8+
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
9+
10+
/**
11+
* ProjectServiceContainer
12+
*
13+
* This class has been auto-generated
14+
* by the Symfony Dependency Injection Component.
15+
*/
16+
class ProjectServiceContainer extends Container
17+
{
18+
/**
19+
* Constructor.
20+
*/
21+
public function __construct()
22+
{
23+
$this->parameters = $this->getDefaultParameters();
24+
25+
$this->services =
26+
$this->scopedServices =
27+
$this->scopeStacks = array();
28+
29+
$this->set('service_container', $this);
30+
31+
$this->scopes = array();
32+
$this->scopeChildren = array();
33+
}
34+
35+
/**
36+
* Gets the 'bar' service.
37+
*
38+
* This service is shared.
39+
* This method always returns the same instance of the service.
40+
*
41+
* @return FooClass A FooClass instance.
42+
*/
43+
protected function getBarService()
44+
{
45+
$this->services['bar'] = $instance = new \FooClass('foo', $this->get('foo.baz'), $this->getParameter('foo_bar'));
46+
47+
$this->get('foo.baz')->configure($instance);
48+
49+
return $instance;
50+
}
51+
52+
/**
53+
* Gets the 'factory_service' service.
54+
*
55+
* This service is shared.
56+
* This method always returns the same instance of the service.
57+
*
58+
* @return Bar A Bar instance.
59+
*/
60+
protected function getFactoryServiceService()
61+
{
62+
return $this->services['factory_service'] = $this->get('foo.baz')->getInstance();
63+
}
64+
65+
/**
66+
* Gets the 'foo' service.
67+
*
68+
* This service is shared.
69+
* This method always returns the same instance of the service.
70+
*
71+
* @return FooClass A FooClass instance.
72+
*/
73+
protected function getFooService()
74+
{
75+
$a = $this->get('foo.baz');
76+
77+
$this->services['foo'] = $instance = call_user_func(array('FooClass', 'getInstance'), 'foo', $a, array('bar' => 'foo is bar', 'foobar' => 'bar'), true, $this);
78+
79+
$instance->setBar($this->get('bar'));
80+
$instance->initialize();
81+
$instance->foo = 'bar';
82+
$instance->moo = $a;
83+
sc_configure($instance);
84+
85+
return $instance;
86+
}
87+
88+
/**
89+
* Gets the 'foo.baz' service.
90+
*
91+
* This service is shared.
92+
* This method always returns the same instance of the service.
93+
*
94+
* @return BazClass A BazClass instance.
95+
*/
96+
protected function getFoo_BazService()
97+
{
98+
$this->services['foo.baz'] = $instance = call_user_func(array('BazClass', 'getInstance'));
99+
100+
call_user_func(array('BazClass', 'configureStatic1'), $instance);
101+
102+
return $instance;
103+
}
104+
105+
/**
106+
* Gets the 'foo_bar' service.
107+
*
108+
* @return FooClass A FooClass instance.
109+
*/
110+
protected function getFooBarService()
111+
{
112+
return new \FooClass();
113+
}
114+
115+
/**
116+
* Gets the 'method_call1' service.
117+
*
118+
* This service is shared.
119+
* This method always returns the same instance of the service.
120+
*
121+
* @return FooClass A FooClass instance.
122+
*/
123+
protected function getMethodCall1Service()
124+
{
125+
require_once '%path%foo.php';
126+
127+
$this->services['method_call1'] = $instance = new \FooClass();
128+
129+
$instance->setBar($this->get('foo'));
130+
$instance->setBar(NULL);
131+
132+
return $instance;
133+
}
134+
135+
/**
136+
* Gets the alias_for_foo service alias.
137+
*
138+
* @return FooClass An instance of the foo service
139+
*/
140+
protected function getAliasForFooService()
141+
{
142+
return $this->get('foo');
143+
}
144+
145+
/**
146+
* {@inheritdoc}
147+
*/
148+
public function getParameter($name)
149+
{
150+
$name = strtolower($name);
151+
152+
if (!array_key_exists($name, $this->parameters)) {
153+
throw new \InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
154+
}
155+
156+
return $this->parameters[$name];
157+
}
158+
159+
/**
160+
* {@inheritdoc}
161+
*/
162+
public function hasParameter($name)
163+
{
164+
return array_key_exists(strtolower($name), $this->parameters);
165+
}
166+
167+
/**
168+
* {@inheritdoc}
169+
*/
170+
public function setParameter($name, $value)
171+
{
172+
throw new \LogicException('Impossible to call set() on a frozen ParameterBag.');
173+
}
174+
175+
/**
176+
* {@inheritDoc}
177+
*/
178+
public function getParameterBag()
179+
{
180+
if (null === $this->parameterBag) {
181+
$this->parameterBag = new FrozenParameterBag($this->parameters);
182+
}
183+
184+
return $this->parameterBag;
185+
}
186+
/**
187+
* Gets the default parameters.
188+
*
189+
* @return array An array of the default parameters
190+
*/
191+
protected function getDefaultParameters()
192+
{
193+
return array(
194+
'baz_class' => 'BazClass',
195+
'foo_class' => 'FooClass',
196+
'foo' => 'bar',
197+
);
198+
}
199+
}

‎tests/Symfony/Tests/Component/DependencyInjection/Fixtures/xml/services9.xml

Copy file name to clipboardExpand all lines: tests/Symfony/Tests/Component/DependencyInjection/Fixtures/xml/services9.xml
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
<parameter key="foo">bar</parameter>
77
</parameters>
88
<services>
9-
<service id="foo" class="FooClass" factory-method="getInstance" scope="prototype">
9+
<service id="foo" class="FooClass" factory-method="getInstance">
1010
<tag name="foo" foo="foo"/>
1111
<tag name="foo" bar="bar"/>
1212
<argument>foo</argument>
1313
<argument type="service" id="foo.baz"/>
1414
<argument type="collection">
1515
<argument key="%foo%">foo is %foo%</argument>
16-
<argument key="bar">%foo%</argument>
16+
<argument key="foobar">%foo%</argument>
1717
</argument>
1818
<argument>true</argument>
1919
<argument type="service" id="service_container"/>
@@ -34,7 +34,7 @@
3434
<service id="foo.baz" class="%baz_class%" factory-method="getInstance">
3535
<configurator class="%baz_class%" method="configureStatic1"/>
3636
</service>
37-
<service id="foo_bar" class="%foo_class%"/>
37+
<service id="foo_bar" class="%foo_class%" scope="prototype"/>
3838
<service id="method_call1" class="FooClass">
3939
<file>%path%foo.php</file>
4040
<call method="setBar">
@@ -50,7 +50,7 @@
5050
<argument type="service" id="foobaz" on-invalid="ignore"/>
5151
</call>
5252
</service>
53-
<service id="factory_service" factory-method="getInstance" factory-service="foo.baz"/>
53+
<service id="factory_service" class="Bar" factory-method="getInstance" factory-service="foo.baz"/>
5454
<service id="alias_for_foo" alias="foo"/>
5555
</services>
5656
</container>

‎tests/Symfony/Tests/Component/DependencyInjection/Fixtures/yaml/services9.yml

Copy file name to clipboardExpand all lines: tests/Symfony/Tests/Component/DependencyInjection/Fixtures/yaml/services9.yml
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ services:
1010
- { name: foo, foo: foo }
1111
- { name: foo, bar: bar }
1212
factory_method: getInstance
13-
arguments: [foo, '@foo.baz', { '%foo%': 'foo is %foo%', bar: '%foo%' }, true, '@service_container']
13+
arguments: [foo, '@foo.baz', { '%foo%': 'foo is %foo%', foobar: '%foo%' }, true, '@service_container']
1414
properties: { foo: bar, moo: '@foo.baz' }
1515
calls:
1616
- [setBar, ['@bar']]
1717
- [initialize, { }]
1818

19-
scope: prototype
2019
configurator: sc_configure
2120
bar:
2221
class: FooClass
@@ -28,6 +27,7 @@ services:
2827
configurator: ['%baz_class%', configureStatic1]
2928
foo_bar:
3029
class: %foo_class%
30+
scope: prototype
3131
method_call1:
3232
class: FooClass
3333
file: %path%foo.php
@@ -38,6 +38,7 @@ services:
3838
- [setBar, ['@?foobaz']]
3939

4040
factory_service:
41+
class: Bar
4142
factory_method: getInstance
4243
factory_service: foo.baz
4344
alias_for_foo: @foo

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.