Skip to content

Commit ed9c94c

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [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. [DependencyInjection] Resolve aliases before removing abstract services + add tests Fix Dom Crawler select option with empty value Remove unnecessary option assignment remove unused variable mock the proper method [PropertyAccess] Fix regression
2 parents cd86797 + 689f27b commit ed9c94c

File tree

15 files changed

+173
-43
lines changed

15 files changed

+173
-43
lines changed

src/Symfony/Component/Console/Helper/Helper.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,28 @@ public static function formatTime($secs)
6262
{
6363
static $timeFormats = array(
6464
array(0, '< 1 sec'),
65-
array(2, '1 sec'),
66-
array(59, 'secs', 1),
65+
array(1, '1 sec'),
66+
array(2, 'secs', 1),
6767
array(60, '1 min'),
68-
array(3600, 'mins', 60),
69-
array(5400, '1 hr'),
70-
array(86400, 'hrs', 3600),
71-
array(129600, '1 day'),
72-
array(604800, 'days', 86400),
68+
array(120, 'mins', 60),
69+
array(3600, '1 hr'),
70+
array(7200, 'hrs', 3600),
71+
array(86400, '1 day'),
72+
array(172800, 'days', 86400),
7373
);
7474

75-
foreach ($timeFormats as $format) {
75+
foreach ($timeFormats as $index => $format) {
7676
if ($secs >= $format[0]) {
77-
continue;
77+
if ((isset($timeFormats[$index + 1]) && $secs < $timeFormats[$index + 1][0])
78+
|| $index == count($timeFormats) - 1
79+
) {
80+
if (2 == count($format)) {
81+
return $format[1];
82+
}
83+
84+
return floor($secs / $format[2]).' '.$format[1];
85+
}
7886
}
79-
80-
if (2 == count($format)) {
81-
return $format[1];
82-
}
83-
84-
return ceil($secs / $format[2]).' '.$format[1];
8587
}
8688
}
8789

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Console\Tests\Helper;
13+
14+
use Symfony\Component\Console\Helper\Helper;
15+
16+
class HelperTest extends \PHPUnit_Framework_TestCase
17+
{
18+
public function formatTimeProvider()
19+
{
20+
return array(
21+
array(0, '< 1 sec'),
22+
array(1, '1 sec'),
23+
array(2, '2 secs'),
24+
array(59, '59 secs'),
25+
array(60, '1 min'),
26+
array(61, '1 min'),
27+
array(119, '1 min'),
28+
array(120, '2 mins'),
29+
array(121, '2 mins'),
30+
array(3599, '59 mins'),
31+
array(3600, '1 hr'),
32+
array(7199, '1 hr'),
33+
array(7200, '2 hrs'),
34+
array(7201, '2 hrs'),
35+
array(86399, '23 hrs'),
36+
array(86400, '1 day'),
37+
array(86401, '1 day'),
38+
array(172799, '1 day'),
39+
array(172800, '2 days'),
40+
array(172801, '2 days'),
41+
);
42+
}
43+
44+
/**
45+
* @dataProvider formatTimeProvider
46+
*
47+
* @param int $secs
48+
* @param string $expectedFormat
49+
*/
50+
public function testFormatTime($secs, $expectedFormat)
51+
{
52+
$this->assertEquals($expectedFormat, Helper::formatTime($secs));
53+
}
54+
}

src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,17 +585,17 @@ public function testAnsiColorsAndEmojis()
585585
$this->generateOutput(
586586
" \033[44;37m Starting the demo... fingers crossed \033[0m\n".
587587
' 0/15 '.$progress.str_repeat($empty, 26)." 0%\n".
588-
" \xf0\x9f\x8f\x81 1 sec \033[44;37m 0 B \033[0m"
588+
" \xf0\x9f\x8f\x81 < 1 sec \033[44;37m 0 B \033[0m"
589589
).
590590
$this->generateOutput(
591591
" \033[44;37m Looks good to me... \033[0m\n".
592592
' 4/15 '.str_repeat($done, 7).$progress.str_repeat($empty, 19)." 26%\n".
593-
" \xf0\x9f\x8f\x81 1 sec \033[41;37m 97 KiB \033[0m"
593+
" \xf0\x9f\x8f\x81 < 1 sec \033[41;37m 97 KiB \033[0m"
594594
).
595595
$this->generateOutput(
596596
" \033[44;37m Thanks, bye \033[0m\n".
597597
' 15/15 '.str_repeat($done, 28)." 100%\n".
598-
" \xf0\x9f\x8f\x81 1 sec \033[41;37m 195 KiB \033[0m"
598+
" \xf0\x9f\x8f\x81 < 1 sec \033[41;37m 195 KiB \033[0m"
599599
),
600600
stream_get_contents($output->getStream())
601601
);

src/Symfony/Component/DependencyInjection/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
/**

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,7 @@ private function processAnonymousServices(\DOMDocument $xml, $file)
325325
// give it a unique name
326326
$id = sprintf('%s_%d', hash('sha256', $file), ++$count);
327327
$node->setAttribute('id', $id);
328-
329-
if ($services = $this->getChildren($node, 'service')) {
330-
$definitions[$id] = array($node, $file, true);
331-
$services[0]->setAttribute('id', $id);
332-
}
328+
$definitions[$id] = array($node, $file, true);
333329
}
334330
}
335331

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

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

792+
public function testAbstractAlias()
793+
{
794+
$container = new ContainerBuilder();
795+
796+
$abstract = new Definition('AbstractClass');
797+
$abstract->setAbstract(true);
798+
799+
$container->setDefinition('abstract_service', $abstract);
800+
$container->setAlias('abstract_alias', 'abstract_service');
801+
802+
$container->compile();
803+
804+
$this->assertSame('abstract_service', (string) $container->getAlias('abstract_alias'));
805+
}
806+
792807
public function testLazyLoadedService()
793808
{
794809
$loader = new ClosureLoader($container = new ContainerBuilder());

src/Symfony/Component/DependencyInjection/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';

src/Symfony/Component/DependencyInjection/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>

src/Symfony/Component/DependencyInjection/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
/**

src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ private function buildOptionValue(\DOMElement $node)
263263
{
264264
$option = array();
265265

266-
$defaultValue = (isset($node->nodeValue) && !empty($node->nodeValue)) ? $node->nodeValue : 'on';
266+
$defaultDefaultValue = 'select' === $this->node->nodeName ? '' : 'on';
267+
$defaultValue = (isset($node->nodeValue) && !empty($node->nodeValue)) ? $node->nodeValue : $defaultDefaultValue;
267268
$option['value'] = $node->hasAttribute('value') ? $node->getAttribute('value') : $defaultValue;
268269
$option['disabled'] = $node->hasAttribute('disabled');
269270

0 commit comments

Comments
 (0)