Merge branch '3.2'

* 3.2:
  [DI] Add missing legacy group on testLegacy
  Minor tweaks
  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:28:13 +01:00
commit 16d33e1fff
13 changed files with 53 additions and 54 deletions

View File

@ -36,7 +36,6 @@ class CachePoolPass implements CompilerPassInterface
}
$seed .= '.'.$container->getParameter('kernel.name').'.'.$container->getParameter('kernel.environment');
$aliases = $container->getAliases();
$attributes = array(
'provider',
'namespace',
@ -59,9 +58,9 @@ class CachePoolPass implements CompilerPassInterface
$tags[0]['namespace'] = $this->getNamespace($seed, $id);
}
if (isset($tags[0]['clearer'])) {
$clearer = strtolower($tags[0]['clearer']);
while (isset($aliases[$clearer])) {
$clearer = (string) $aliases[$clearer];
$clearer = $tags[0]['clearer'];
while ($container->hasAlias($clearer)) {
$clearer = (string) $container->getAlias($clearer);
}
} else {
$clearer = null;

View File

@ -320,26 +320,26 @@ abstract class FrameworkExtensionTest extends TestCase
$packages = $container->getDefinition('assets.packages');
// default package
$defaultPackage = $container->getDefinition($packages->getArgument(0));
$defaultPackage = $container->getDefinition((string) $packages->getArgument(0));
$this->assertUrlPackage($container, $defaultPackage, array('http://cdn.example.com'), 'SomeVersionScheme', '%%s?version=%%s');
// packages
$packages = $packages->getArgument(1);
$this->assertCount(5, $packages);
$package = $container->getDefinition($packages['images_path']);
$package = $container->getDefinition((string) $packages['images_path']);
$this->assertPathPackage($container, $package, '/foo', 'SomeVersionScheme', '%%s?version=%%s');
$package = $container->getDefinition($packages['images']);
$package = $container->getDefinition((string) $packages['images']);
$this->assertUrlPackage($container, $package, array('http://images1.example.com', 'http://images2.example.com'), '1.0.0', '%%s?version=%%s');
$package = $container->getDefinition($packages['foo']);
$package = $container->getDefinition((string) $packages['foo']);
$this->assertPathPackage($container, $package, '', '1.0.0', '%%s-%%s');
$package = $container->getDefinition($packages['bar']);
$package = $container->getDefinition((string) $packages['bar']);
$this->assertUrlPackage($container, $package, array('https://bar2.example.com'), 'SomeVersionScheme', '%%s?version=%%s');
$package = $container->getDefinition($packages['bar_version_strategy']);
$package = $container->getDefinition((string) $packages['bar_version_strategy']);
$this->assertEquals('assets.custom_version_strategy', (string) $package->getArgument(1));
}
@ -349,7 +349,7 @@ abstract class FrameworkExtensionTest extends TestCase
$packages = $container->getDefinition('assets.packages');
// default package
$defaultPackage = $container->getDefinition($packages->getArgument(0));
$defaultPackage = $container->getDefinition((string) $packages->getArgument(0));
$this->assertEquals('assets.custom_version_strategy', (string) $defaultPackage->getArgument(1));
}
@ -865,7 +865,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

@ -407,7 +407,7 @@ class SecurityExtension extends Extension
$config->replaceArgument(8, isset($firewall['access_denied_handler']) ? $firewall['access_denied_handler'] : null);
$config->replaceArgument(9, isset($firewall['access_denied_url']) ? $firewall['access_denied_url'] : null);
$container->setAlias(new Alias('security.user_checker.'.$id, false), $firewall['user_checker']);
$container->setAlias('security.user_checker.'.$id, new Alias($firewall['user_checker'], false));
foreach ($this->factories as $position) {
foreach ($position as $factory) {

View File

@ -73,7 +73,7 @@ abstract class CompleteConfigurationTest extends \PHPUnit_Framework_TestCase
$arguments = $contextDef->getArguments();
$listeners[] = array_map(function ($ref) { return (string) $ref; }, $arguments['index_0']);
$configDef = $container->getDefinition($arguments['index_2']);
$configDef = $container->getDefinition((string) $arguments['index_2']);
$configs[] = array_values($configDef->getArguments());
}
@ -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

@ -305,7 +305,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

@ -436,7 +436,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 {
@ -1240,14 +1240,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

@ -170,7 +170,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

@ -272,7 +272,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()
@ -308,7 +308,7 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
$container->compile();
$dumper = new PhpDumper($container);
$this->assertEquals(file_get_contents(self::$fixturesPath.'/php/services24.php'), $dumper->dump());
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services24.php', $dumper->dump());
}
public function testEnvParameter()
@ -466,8 +466,7 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
$container->compile();
$dumper = new PhpDumper($container);
$dump = $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Closure_Proxy'));
$this->assertEquals(file_get_contents(self::$fixturesPath.'/php/services31.php'), $dumper->dump());
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services31.php', $dumper->dump());
$res = $container->getResources();
$this->assertSame(realpath(self::$fixturesPath.'/containers/container31.php'), array_pop($res)->getResource());
}
@ -481,8 +480,7 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
$container->compile();
$dumper = new PhpDumper($container);
$dump = $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Closure_Proxy_Php71'));
$this->assertEquals(file_get_contents(self::$fixturesPath.'/php/services32.php'), $dumper->dump());
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services32.php', $dumper->dump());
$res = $container->getResources();
$this->assertSame(realpath(self::$fixturesPath.'/containers/container32.php'), array_pop($res)->getResource());
}

View File

@ -18,8 +18,6 @@ services:
calls:
- [ setBar, [ foo, '@foo', [true, false] ] ]
alias_for_foo: '@foo'
another_third_alias_for_foo:
alias: foo
another_alias_for_foo:
alias: foo
public: false
@ -27,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

@ -57,7 +57,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