Merge branch '3.1' into 3.2

* 3.1:
  Fix merge
  [DI] Dont share service when no id provided
  Fix Container and PhpDumper test inaccuracies
  [DI] Fix missing new line after private alias
  [ClassLoader] Throw an exception if the cache is not writeable
  Fixing regression in TwigEngine exception handling.
This commit is contained in:
Nicolas Grekas 2017-01-10 15:14:38 +01:00
commit 783abab7ae
11 changed files with 38 additions and 34 deletions

View File

@ -850,7 +850,7 @@ abstract class FrameworkExtensionTest extends TestCase
private function assertVersionStrategy(ContainerBuilder $container, Reference $reference, $version, $format)
{
$versionStrategy = $container->getDefinition($reference);
$versionStrategy = $container->getDefinition((string) $reference);
if (null === $version) {
$this->assertEquals('assets.empty_version_strategy', (string) $reference);
} else {

View File

@ -234,7 +234,7 @@ abstract class CompleteConfigurationTest extends \PHPUnit_Framework_TestCase
);
} elseif (3 === $i) {
$this->assertEquals('IS_AUTHENTICATED_ANONYMOUSLY', $attributes[0]);
$expression = $container->getDefinition($attributes[1])->getArgument(0);
$expression = $container->getDefinition((string) $attributes[1])->getArgument(0);
$this->assertEquals("token.getUsername() matches '/^admin/'", $expression);
}
}

View File

@ -49,16 +49,12 @@ class TwigEngine extends BaseEngine implements EngineInterface
try {
return parent::render($name, $parameters);
} catch (\Twig_Error $e) {
if ($name instanceof TemplateReference) {
if ($name instanceof TemplateReference && !method_exists($e, 'setSourceContext')) {
try {
// try to get the real name of the template where the error occurred
$name = $e->getTemplateName();
$path = (string) $this->locator->locate($this->parser->parse($name));
if (method_exists($e, 'setSourceContext')) {
$e->setSourceContext(new \Twig_Source('', $name, $path));
} else {
$e->setTemplateName($path);
}
$e->setTemplateName($path);
} catch (\Exception $e2) {
}
}

View File

@ -299,7 +299,13 @@ REGEX;
*/
private static function writeCacheFile($file, $content)
{
$tmpFile = tempnam(dirname($file), basename($file));
$dir = dirname($file);
if (!is_writable($dir)) {
throw new \RuntimeException(sprintf('Cache directory "%s" is not writable.', $dir));
}
$tmpFile = tempnam($dir, basename($file));
if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) {
@chmod($file, 0666 & ~umask());

View File

@ -424,7 +424,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
}
if (!isset($this->definitions[$id]) && isset($this->aliasDefinitions[$id])) {
return $this->get($this->aliasDefinitions[$id], $invalidBehavior);
return $this->get((string) $this->aliasDefinitions[$id], $invalidBehavior);
}
try {
@ -1140,14 +1140,14 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
/**
* Shares a given service in the container.
*
* @param Definition $definition
* @param mixed $service
* @param string $id
* @param Definition $definition
* @param mixed $service
* @param string|null $id
*/
private function shareService(Definition $definition, $service, $id)
{
if ($definition->isShared()) {
$this->services[$lowerId = strtolower($id)] = $service;
if (null !== $id && $definition->isShared()) {
$this->services[strtolower($id)] = $service;
}
}

View File

@ -168,7 +168,7 @@ class YamlDumper extends Dumper
return sprintf(" %s: '@%s'\n", $alias, $id);
}
return sprintf(" %s:\n alias: %s\n public: false", $alias, $id);
return sprintf(" %s:\n alias: %s\n public: false\n", $alias, $id);
}
/**

View File

@ -213,13 +213,13 @@ class AutowirePassTest extends \PHPUnit_Framework_TestCase
$this->assertCount(1, $container->getDefinition('coop_tilleuls')->getArguments());
$this->assertEquals('autowired.symfony\component\dependencyinjection\tests\compiler\dunglas', $container->getDefinition('coop_tilleuls')->getArgument(0));
$dunglasDefinition = $container->getDefinition('autowired.symfony\component\dependencyinjection\tests\compiler\dunglas');
$dunglasDefinition = $container->getDefinition('autowired.Symfony\Component\DependencyInjection\Tests\Compiler\Dunglas');
$this->assertEquals(__NAMESPACE__.'\Dunglas', $dunglasDefinition->getClass());
$this->assertFalse($dunglasDefinition->isPublic());
$this->assertCount(1, $dunglasDefinition->getArguments());
$this->assertEquals('autowired.symfony\component\dependencyinjection\tests\compiler\lille', $dunglasDefinition->getArgument(0));
$lilleDefinition = $container->getDefinition('autowired.symfony\component\dependencyinjection\tests\compiler\lille');
$lilleDefinition = $container->getDefinition('autowired.Symfony\Component\DependencyInjection\Tests\Compiler\Lille');
$this->assertEquals(__NAMESPACE__.'\Lille', $lilleDefinition->getClass());
}

View File

@ -144,7 +144,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
{
$sc = new Container();
$sc->set('foo', $foo = new \stdClass());
$this->assertEquals($foo, $sc->get('foo'), '->set() sets a service');
$this->assertSame($foo, $sc->get('foo'), '->set() sets a service');
}
public function testSetWithNullResetTheService()
@ -166,14 +166,14 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
{
$sc = new ProjectServiceContainer();
$sc->set('foo', $foo = new \stdClass());
$this->assertEquals($foo, $sc->get('foo'), '->get() returns the service for the given id');
$this->assertEquals($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase');
$this->assertEquals($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
$this->assertEquals($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined');
$this->assertEquals($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined');
$this->assertSame($foo, $sc->get('foo'), '->get() returns the service for the given id');
$this->assertSame($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase');
$this->assertSame($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
$this->assertSame($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined');
$this->assertSame($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined');
$sc->set('bar', $bar = new \stdClass());
$this->assertEquals($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()');
$this->assertSame($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()');
try {
$sc->get('');
@ -196,15 +196,15 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
$sc = new LegacyProjectServiceContainer();
$sc->set('foo', $foo = new \stdClass());
$this->assertEquals($foo, $sc->get('foo'), '->get() returns the service for the given id');
$this->assertEquals($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase');
$this->assertEquals($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
$this->assertEquals($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined');
$this->assertEquals($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined');
$this->assertEquals($sc->__foo_baz, $sc->get('foo\\baz'), '->get() returns the service if a get*Method() is defined');
$this->assertSame($foo, $sc->get('foo'), '->get() returns the service for the given id');
$this->assertSame($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase');
$this->assertSame($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
$this->assertSame($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined');
$this->assertSame($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined');
$this->assertSame($sc->__foo_baz, $sc->get('foo\\baz'), '->get() returns the service if a get*Method() is defined');
$sc->set('bar', $bar = new \stdClass());
$this->assertEquals($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()');
$this->assertSame($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()');
try {
$sc->get('');

View File

@ -252,7 +252,7 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
$container->set('bar', $bar = new \stdClass());
$container->setParameter('foo_bar', 'foo_bar');
$this->assertEquals($bar, $container->get('bar'), '->set() overrides an already defined service');
$this->assertSame($bar, $container->get('bar'), '->set() overrides an already defined service');
}
public function testOverrideServiceWhenUsingADumpedContainerAndServiceIsUsedFromAnotherOne()

View File

@ -25,6 +25,8 @@ services:
class: Request
synthetic: true
lazy: true
another_third_alias_for_foo:
alias: foo
decorator_service:
decorates: decorated
decorator_service_with_name:

View File

@ -56,7 +56,7 @@ class BundleTest extends \PHPUnit_Framework_TestCase
public function testHttpKernelRegisterCommandsIgnoresCommandsThatAreRegisteredAsServices()
{
$container = new ContainerBuilder();
$container->register('console.command.Symfony_Component_HttpKernel_Tests_Fixtures_ExtensionPresentBundle_Command_FooCommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand');
$container->register('console.command.symfony_component_httpkernel_tests_fixtures_extensionpresentbundle_command_foocommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand');
$application = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
// add() is never called when the found command classes are already registered as services