8000 Merge branch '3.1' into 3.2 · symfony/symfony@e67e47d · GitHub
[go: up one dir, main page]

Skip to content

Commit e67e47d

Browse files
Merge branch '3.1' into 3.2
* 3.1: [DI] Fixed custom services definition BC break introduced in ec7e70fb… [Process] Fix kill process on reached timeout using getIterator() [DI] Aliases should preserve the aliased invalid behavior
2 parents 85033ff + 3918fff commit e67e47d

File tree

5 files changed

+65
-4
lines changed

5 files changed

+65
-4
lines changed

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV
424424
}
425425

426426
if (!isset($this->definitions[$id]) && isset($this->aliasDefinitions[$id])) {
427-
return $this->get($this->aliasDefinitions[$id]);
427+
return $this->get($this->aliasDefinitions[$id], $invalidBehavior);
428428
}
429429

430430
try {
@@ -835,8 +835,8 @@ public function findDefinition($id)
835835
*/
836836
private function createService(Definition $definition, $id, $tryProxy = true)
837837
{
838-
if ('Symfony\Component\DependencyInjection\Definition' !== get_class($definition)) {
839-
throw new RuntimeException(sprintf('Constructing service "%s" from a %s is not supported at build time.', $id, get_class($definition)));
838+
if ($definition instanceof DefinitionDecorator) {
839+
throw new RuntimeException(sprintf('Constructing service "%s" from a parent definition is not supported at build time.', $id));
840840
}
841841

842842
if ($definition->isSynthetic()) {

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
2929
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
3030
use Symfony\Component\Config\Resource\FileResource;
31+
use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition;
3132
use Symfony\Component\ExpressionLanguage\Expression;
3233

3334
class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
@@ -266,6 +267,18 @@ public function testSetReplacesAlias()
266267
$this->assertSame($foo, $builder->get('alias'), '->set() replaces an existing alias');
267268
}
268269

270+
public function testAliasesKeepInvalidBehavior()
271+
{
272+
$builder = new ContainerBuilder();
273+
274+
$aliased = new Definition('stdClass');
275+
$aliased->addMethodCall('setBar', array(new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
276+
$builder->setDefinition('aliased', $aliased);
277+
$builder->setAlias('alias', 'aliased');
278+
279+
$this->assertEquals(new \stdClass(), $builder->get('alias'));
280+
}
281+
269282
public function testAddGetCompilerPass()
270283
{
271284
$builder = new ContainerBuilder();
@@ -415,7 +428,7 @@ public function testResolveServices()
415428

416429
/**
417430
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
418-
* @expectedExceptionMessage Constructing service "foo" from a Symfony\Component\DependencyInjection\DefinitionDecorator is not supported at build time.
431+
* @expectedExceptionMessage Constructing service "foo" from a parent definition is not supported at build time.
419432
*/
420433
public function testResolveServicesWithDecoratedDefinition()
421434
{
@@ -427,6 +440,14 @@ public function testResolveServicesWithDecoratedDefinition()
427440
$builder->get('foo');
428441
}
429442

443+
public function testResolveServicesWithCustomDefinitionClass()
444+
{
445+
< ED48 span class=pl-c1>$builder = new ContainerBuilder();
446+
$builder->setDefinition('foo', new CustomDefinition('stdClass'));
447+
448+
$this->assertInstanceOf('stdClass', $builder->get('foo'));
449+
}
450+
430451
public function testMerge()
431452
{
432453
$container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\DependencyInjection\Tests\Fixtures;
13+
14+
use Symfony\Component\DependencyInjection\Definition;
15+
16+
class CustomDefinition extends Definition
17+
{
18+
}

src/Symfony/Component/Process/Process.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ public function getIterator($flags = 0)
573573
yield self::OUT => '';
574574
}
575575

576+
$this->checkTimeout();
576577
$this->readPipesForOutput(__FUNCTION__, $blocking);
577578
}
578579
}

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,27 @@ public function testRunProcessWithTimeout()
747747
throw $e;
748748
}
749749

750+
/**
751+
* @expectedException \Symfony\Component\Process\Exception\ProcessTimedOutException
752+
* @expectedExceptionMessage exceeded the timeout of 0.1 seconds.
753+
*/
754+
public function testIterateOverProcessWithTimeout()
755+
{
756+
$process = $this->getProcess(self::$phpBin.' -r "sleep(30);"');
757+
$process->setTimeout(0.1);
758+
$start = microtime(true);
759+
try {
760+
$process->start();
761+
foreach ($process as $buffer);
762+
$this->fail('A RuntimeException should have been raised');
763+
} catch (RuntimeException $e) {
764+
}
765+
766+
$this->assertLessThan(15, microtime(true) - $start);
767+
768+
throw $e;
769+
}
770+
750771
public function testCheckTimeoutOnNonStartedProcess()
751772
{
752773
$process = $this->getProcess('echo foo');

0 commit comments

Comments
 (0)
0