8000 Merge branch '2.4' into 2.5 · symfony/symfony@aa5179b · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit aa5179b

Browse files
committed
Merge branch '2.4' into 2.5
* 2.4: Make Doctrine's dependency injection test less fragile. [Finder] [Iterator] Make the tests less fragile [Form][DateTime] Propagate invalid_message & invalid_message parameters to date & time sub widgets Fix expression language in the container when using the "container" variable
2 parents d7615e7 + e768f37 commit aa5179b

File tree

17 files changed

+120
-47
lines changed

17 files changed

+120
-47
lines changed

src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPassTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ public function testProcessEventSubscribersWithPriorities()
132132
;
133133

134134
$this->process($container);
135-
$this->assertEquals(array('c', 'd', 'e', 'b', 'a'), $this->getServiceOrder($container, 'addEventSubscriber'));
135+
$serviceOrder = $this->getServiceOrder($container, 'addEventSubscriber');
136+
$unordered = array_splice($serviceOrder, 0, 3);
137+
sort($unordered);
138+
$this->assertEquals(array('c', 'd', 'e'), $unordered);
139+
$this->assertEquals(array('b', 'a'), $serviceOrder);
136140
}
137141

138142
public function testProcessNoTaggedServices()

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ private function dumpValue($value, $interpolate = true)
12301230

12311231
return $this->getServiceCall((string) $value, $value);
12321232
} elseif ($value instanceof Expression) {
1233-
return $this->getExpressionLanguage()->compile((string) $value, array('container'));
1233+
return $this->getExpressionLanguage()->compile((string) $value, array('this' => 'container'));
12341234
} elseif ($value instanceof Parameter) {
12351235
return $this->dumpParameter($value);
12361236
} elseif (true === $interpolate && is_string($value)) {

src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
addMethodCall('setBar', array(new Reference('foo2', ContainerInterface::NULL_ON_INVALID_REFERENCE)))->
5353
addMethodCall('setBar', array(new Reference('foo3', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)))->
5454
addMethodCall('setBar', array(new Reference('foobaz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)))->
55-
addMethodCall('setBar', array(new Expression('service("foo").foo() ~ parameter("foo")')))
55+
addMethodCall('setBar', array(new Expression('service("foo").foo() ~ (container.hasparameter("foo") ? parameter("foo") : "default")')))
5656
;
5757
$container->
5858
register('factory_service', 'Bar')->

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ protected function getMethodCall1Service()
260260
if ($this->has('foobaz')) {
261261
$instance->setBar($this->get('foobaz', ContainerInterface::NULL_ON_INVALID_REFERENCE));
262262
}
263-
$instance->setBar(($this->get("foo")->foo() . $this->getParameter("foo")));
263+
$instance->setBar(($this->get("foo")->foo() . (($this->hasparameter("foo")) ? ($this->getParameter("foo")) : ("default"))));
264264

265265
return $instance;
266266
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ protected function getMethodCall1Service()
256256

257257
$instance->setBar($this->get('foo'));
258258
$instance->setBar(NULL);
259-
$instance->setBar(($this->get("foo")->foo() . $this->getParameter("foo")));
259+
$instance->setBar(($this->get("foo")->foo() . (($this->hasparameter("foo")) ? ($this->getParameter("foo")) : ("default"))));
260260

261261
return $instance;
262262
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services6.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<service id="method_call1" class="FooClass">
3434
<call method="setBar" />
3535
<call method="setBar">
36-
<argument type="expression">service("foo").foo() ~ parameter("foo")</argument>
36+
<argument type="expression">service("foo").foo() ~ (container.hasparameter("foo") ? parameter("foo") : "default")</argument>
3737
</call>
3838
</service>
3939
<service id="method_call2" class="FooClass">

src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<argument type="service" id="foobaz" on-invalid="ignore"/>
5555
</call>
5656
<call method="setBar">
57-
<argument type="expression">service("foo").foo() ~ parameter("foo")</argument>
57+
<argument type="expression">service("foo").foo() ~ (container.hasparameter("foo") ? parameter("foo") : "default")</argument>
5858
</call>
5959
</service>
6060
<service id="factory_service" class="Bar" factory-method="getInstance" factory-service="foo.baz"/>

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
calls:
1616
- [ setBar, [] ]
1717
- [ setBar ]
18-
- [ setBar, ['@=service("foo").foo() ~ parameter("foo")'] ]
18+
- [ setBar, ['@=service("foo").foo() ~ (container.hasparameter("foo") ? parameter("foo") : "default")'] ]
1919
method_call2:
2020
class: FooClass
2121
calls:

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ services:
3838
- [setBar, ['@?foo2']]
3939
- [setBar, ['@?foo3']]
4040
- [setBar, ['@?foobaz']]
41-
- [setBar, ['@=service("foo").foo() ~ parameter("foo")']]
41+
- [setBar, ['@=service("foo").foo() ~ (container.hasparameter("foo") ? parameter("foo") : "default")']]
4242

4343
factory_service:
4444
class: Bar

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public function testLoadServices()
211211
$this->assertEquals('sc_configure', $services['configurator1']->getConfigurator(), '->load() parses the configurator tag');
212212
$this->assertEquals(array(new Reference('baz', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false), 'configure'), $services['configurator2']->getConfigurator(), '->load() parses the configurator tag');
213213
$this->assertEquals(array('BazClass', 'configureStatic'), $services['configurator3']->getConfigurator(), '->load() parses the configurator tag');
214-
$this->assertEquals(array(array('setBar', array()), array('setBar', array(new Expression('service("foo").foo() ~ parameter("foo")')))), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag');
214+
$this->assertEquals(array(array('setBar', array()), array('setBar', array(new Expression('service("foo").foo() ~ (container.hasparameter("foo") ? paramete 57AE r("foo") : "default")')))), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag');
215215
$this->assertEquals(array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), $services['method_call2']->getMethodCalls(), '->load() parses the method_call tag');
216216
$this->assertNull($services['factory_service']->getClass());
217217
$this->assertEquals('getInstance', $services['factory_service']->getFactoryMethod());

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function testLoadServices()
138138
$this->assertEquals('sc_configure', $services['configurator1']->getConfigurator(), '->load() parses the configurator tag');
139139
$this->assertEquals(array(new Reference('baz'), 'configure'), $services['configurator2']->getConfigurator(), '->load() parses the configurator tag');
140140
$this->assertEquals(array('BazClass', 'configureStatic'), $services['configurator3']->getConfigurator(), '->load() parses the configurator tag');
141-
$this->assertEquals(array(array('setBar', array()), array('setBar', array()), array('setBar', array(new Expression('service("foo").foo() ~ parameter("foo")')))), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag');
141+
$this->assertEquals(array(array('setBar', array()), array('setBar', array()), array('setBar', array(new Expression('service("foo").foo() ~ (container.hasparameter("foo") ? parameter("foo") : "default")')))), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag');
142142
$this->assertEquals(array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), $services['method_call2']->getMethodCalls(), '->load() parses the method_call tag');
143143
$this->assertEquals('baz_factory', $services['factory_service']->getFactoryService());
144144

src/Symfony/Component/ExpressionLanguage/Parser.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ public function __construct(array $functions)
7575
/**
7676
* Converts a token stream to a node tree.
7777
*
78+
* The valid names is an array where the values
79+
* are the names that the user can use in an expression.
80+
*
81+
* If the variable name in the compiled PHP code must be
82+
* different, define it as the key.
83+
*
84+
* For instance, ['this' => 'container'] means that the
85+
* variable 'container' can be used in the expression
86+
* but the compiled code will use 'this'.
87+
*
7888
* @param TokenStream $stream A token stream instance
7989
* @param array $names An array of valid names
8090
*
@@ -194,7 +204,13 @@ public function parsePrimaryExpression()
194204
throw new SyntaxError(sprintf('Variable "%s" is not valid', $token->value), $token->cursor);
195205
}
196206

197-
$node = new Node\NameNode($token->value);
207+
// is the name used in the compiled code different
208+
// from the name used in the expression?
209+
if (is_int($name = array_search($token->value, $this->names))) {
210+
$name = $token->value;
211+
}
212+
213+
$node = new Node\NameNode($name);
198214
}
199215
}
200216
break;

src/Symfony/Component/ExpressionLanguage/Tests/ParserTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ public function getParseData()
148148
'foo.bar().foo().baz[3]',
149149
array('foo'),
150150
),
151+
152+
array(
153+
new Node\NameNode('foo'),
154+
'bar',
155+
array('foo' => 'bar'),
156+
),
151157
);
152158
}
153159

src/Symfony/Component/Finder/Tests/Iterator/IteratorTestCase.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,31 @@ protected function assertOrderedIterator($expected, \Traversable $iterator)
3434
$this->assertEquals($expected, array_values($values));
3535
}
3636

37+
/**
38+
* Same as assertOrderedIterator, but checks the order of groups of
39+
* array elements.
40+
*
41+
* @param array $expected - an array of arrays. For any two subarrays
42+
* $a and $b such that $a goes before $b in $expected, the method
43+
* asserts that any element of $a goes before any element of $b
44+
* in the sequence generated by $iterator
45+
* @param \Traversable $iterator
46+
*/
47+
protected function assertOrderedIteratorForGroups($expected, \Traversable $iterator)
48+
{
49+
$values = array_values(array_map(function (\SplFileInfo $fileinfo) { return $fileinfo->getPathname(); }, iterator_to_array($iterator)));
50+
51+
foreach ($expected as $subarray) {
52+
$temp = array();
53+
while (count($values) && count($temp) < count($subarray)) {
54+
array_push($temp, array_shift($values));
55+
}
56+
sort($temp);
57+
sort($subarray);
58+
$this->assertEquals($subarray, $temp);
59+
}
60+
}
61+
3762
/**
3863
* Same as IteratorTestCase::assertIterator with foreach usage
3964
*

src/Symfony/Component/Finder/Tests/Iterator/RealIteratorTestCase.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ protected static function toAbsolute($files = null)
8080
if (is_array($files)) {
8181
$f = array();
8282
foreach ($files as $file) {
83-
$f[] = self::$tmpDir.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, $file);
83+
if (is_array($file)) {
84+
$f[] = self::toAbsolute($file);
85+
} else {
86+
$f[] = self::$tmpDir.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, $file);
87+
}
8488
}
8589

8690
return $f;

src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ public function testAccept($mode, $expected)
5454

5555
$iterator = new SortableIterator($inner, $mode);
5656

57-
$this->assertOrderedIterator($expected, $iterator);
57+
if ($mode === SortableIterator::SORT_BY_ACCESSED_TIME
58+
|| $mode === SortableIterator::SORT_BY_CHANGED_TIME
59+
|| $mode === SortableIterator::SORT_BY_MODIFIED_TIME) {
60+
$this->assertOrderedIteratorForGroups($expected, $iterator);
61+
} else {
62+
$this->assertOrderedIterator($expected, $iterator);
63+
}
5864
}
5965

6066
public function getAcceptData()
@@ -102,45 +108,53 @@ public function getAcceptData()
102108
);
103109

104110
$sortByAccessedTime = array(
105-
'foo/bar.tmp',
106-
'test.php',
107-
'toto',
108-
'foo bar',
109-
'foo',
110-
'test.py',
111-
'.foo',
112-
'.foo/.bar',
113-
'.foo/bar',
114-
'.git',
115-
'.bar',
111+
// For these two files the access time was set to 2005-10-15
112+
array('foo/bar.tmp', 'test.php'),
113+
// These files were created more or less at the same time
114+
array(
115+
'.git',
116+
'.foo',
117+
'.foo/.bar',
118+
'.foo/bar',
119+
'test.py',
120+
'foo',
121+
'toto',
122+
'foo bar',
123+
),
124+
// This file was accessed after sleeping for 1 sec
125+
array('.bar'),
116126
);
117127

118128
$sortByChangedTime = array(
119-
'foo',
120-
'foo/bar.tmp',
121-
'toto',
122-
'.git',
123-
'.bar',
124-
'.foo',
125-
'foo bar',
126-
'.foo/.bar',
127-
'.foo/bar',
128-
'test.php',
129-
'test.py',
129+
array(
130+
'.git',
131+
'.foo',
132+
'.foo/.bar',
133+
'.foo/bar',
134+
'.bar',
135+
'foo',
136+
'foo/bar.tmp',
137+
'toto',
138+
'foo bar',
139+
),
140+
array('test.php'),
141+
array('test.py'),
130142
);
131143

132144
$sortByModifiedTime = array(
133-
'foo/bar.tmp',
134-
'foo',
135-
'toto',
136-
'.git',
137-
'.bar',
138-
'.foo',
139-
'foo bar',
140-
'.foo/.bar',
141-
'.foo/bar',
142-
'test.php',
143-
'test.py',
145+
array(
146+
'.git',
147+
'.foo',
148+
'.foo/.bar',
149+
'.foo/bar',
150+
'.bar',
151+
'foo',
152+
'foo/bar.tmp',
153+
'toto',
154+
'foo bar',
155+
),
156+
array('test.php'),
157+
array('test.py'),
144158
);
145159

146160
return array(

src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
117117
'empty_value',
118118
'required',
119119
'translation_domain',
120+
'invalid_message',
121+
'invalid_message_parameters',
120122
)));
121123

122124
$timeOptions = array_intersect_key($options, array_flip(array(
@@ -128,6 +130,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
128130
'empty_value',
129131
'required',
130132
'translation_domain',
133+
'invalid_message',
134+
'invalid_message_parameters',
131135
)));
132136

133137
if (null !== $options['date_widget']) {

0 commit comments

Comments
 (0)
0