Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
215
vendor/symfony/dependency-injection/Tests/Compiler/AnalyzeServiceReferencesPassTest.php
vendored
Normal file
215
vendor/symfony/dependency-injection/Tests/Compiler/AnalyzeServiceReferencesPassTest.php
vendored
Normal file
|
@ -0,0 +1,215 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\RepeatedPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class AnalyzeServiceReferencesPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$a = $container
|
||||
->register('a')
|
||||
->addArgument($ref1 = new Reference('b'))
|
||||
;
|
||||
|
||||
$b = $container
|
||||
->register('b')
|
||||
->addMethodCall('setA', array($ref2 = new Reference('a')))
|
||||
;
|
||||
|
||||
$c = $container
|
||||
->register('c')
|
||||
->addArgument($ref3 = new Reference('a'))
|
||||
->addArgument($ref4 = new Reference('b'))
|
||||
;
|
||||
|
||||
$d = $container
|
||||
->register('d')
|
||||
->setProperty('foo', $ref5 = new Reference('b'))
|
||||
;
|
||||
|
||||
$e = $container
|
||||
->register('e')
|
||||
->setConfigurator(array($ref6 = new Reference('b'), 'methodName'))
|
||||
;
|
||||
|
||||
$graph = $this->process($container);
|
||||
|
||||
$this->assertCount(4, $edges = $graph->getNode('b')->getInEdges());
|
||||
|
||||
$this->assertSame($ref1, $edges[0]->getValue());
|
||||
$this->assertSame($ref4, $edges[1]->getValue());
|
||||
$this->assertSame($ref5, $edges[2]->getValue());
|
||||
$this->assertSame($ref6, $edges[3]->getValue());
|
||||
}
|
||||
|
||||
public function testProcessMarksEdgesLazyWhenReferencedServiceIsLazy()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('a')
|
||||
->setLazy(true)
|
||||
->addArgument($ref1 = new Reference('b'))
|
||||
;
|
||||
|
||||
$container
|
||||
->register('b')
|
||||
->addArgument($ref2 = new Reference('a'))
|
||||
;
|
||||
|
||||
$graph = $this->process($container);
|
||||
|
||||
$this->assertCount(1, $graph->getNode('b')->getInEdges());
|
||||
$this->assertCount(1, $edges = $graph->getNode('a')->getInEdges());
|
||||
|
||||
$this->assertSame($ref2, $edges[0]->getValue());
|
||||
$this->assertTrue($edges[0]->isLazy());
|
||||
}
|
||||
|
||||
public function testProcessMarksEdgesLazyWhenReferencedFromIteratorArgument()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('a');
|
||||
$container->register('b');
|
||||
|
||||
$container
|
||||
->register('c')
|
||||
->addArgument($ref1 = new Reference('a'))
|
||||
->addArgument(new IteratorArgument(array($ref2 = new Reference('b'))))
|
||||
;
|
||||
|
||||
$graph = $this->process($container);
|
||||
|
||||
$this->assertCount(1, $graph->getNode('a')->getInEdges());
|
||||
$this->assertCount(1, $graph->getNode('b')->getInEdges());
|
||||
$this->assertCount(2, $edges = $graph->getNode('c')->getOutEdges());
|
||||
|
||||
$this->assertSame($ref1, $edges[0]->getValue());
|
||||
$this->assertFalse($edges[0]->isLazy());
|
||||
$this->assertSame($ref2, $edges[1]->getValue());
|
||||
$this->assertTrue($edges[1]->isLazy());
|
||||
}
|
||||
|
||||
public function testProcessDetectsReferencesFromInlinedDefinitions()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('a')
|
||||
;
|
||||
|
||||
$container
|
||||
->register('b')
|
||||
->addArgument(new Definition(null, array($ref = new Reference('a'))))
|
||||
;
|
||||
|
||||
$graph = $this->process($container);
|
||||
|
||||
$this->assertCount(1, $refs = $graph->getNode('a')->getInEdges());
|
||||
$this->assertSame($ref, $refs[0]->getValue());
|
||||
}
|
||||
|
||||
public function testProcessDetectsReferencesFromIteratorArguments()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('a')
|
||||
;
|
||||
|
||||
$container
|
||||
->register('b')
|
||||
->addArgument(new IteratorArgument(array($ref = new Reference('a'))))
|
||||
;
|
||||
|
||||
$graph = $this->process($container);
|
||||
|
||||
$this->assertCount(1, $refs = $graph->getNode('a')->getInEdges());
|
||||
$this->assertSame($ref, $refs[0]->getValue());
|
||||
}
|
||||
|
||||
public function testProcessDetectsReferencesFromInlinedFactoryDefinitions()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('a')
|
||||
;
|
||||
|
||||
$factory = new Definition();
|
||||
$factory->setFactory(array(new Reference('a'), 'a'));
|
||||
|
||||
$container
|
||||
->register('b')
|
||||
->addArgument($factory)
|
||||
;
|
||||
|
||||
$graph = $this->process($container);
|
||||
|
||||
$this->assertTrue($graph->hasNode('a'));
|
||||
$this->assertCount(1, $refs = $graph->getNode('a')->getInEdges());
|
||||
}
|
||||
|
||||
public function testProcessDoesNotSaveDuplicateReferences()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('a')
|
||||
;
|
||||
$container
|
||||
->register('b')
|
||||
->addArgument(new Definition(null, array($ref1 = new Reference('a'))))
|
||||
->addArgument(new Definition(null, array($ref2 = new Reference('a'))))
|
||||
;
|
||||
|
||||
$graph = $this->process($container);
|
||||
|
||||
$this->assertCount(2, $graph->getNode('a')->getInEdges());
|
||||
}
|
||||
|
||||
public function testProcessDetectsFactoryReferences()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('foo', 'stdClass')
|
||||
->setFactory(array('stdClass', 'getInstance'));
|
||||
|
||||
$container
|
||||
->register('bar', 'stdClass')
|
||||
->setFactory(array(new Reference('foo'), 'getInstance'));
|
||||
|
||||
$graph = $this->process($container);
|
||||
|
||||
$this->assertTrue($graph->hasNode('foo'));
|
||||
$this->assertCount(1, $graph->getNode('foo')->getInEdges());
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
$pass = new RepeatedPass(array(new AnalyzeServiceReferencesPass()));
|
||||
$pass->process($container);
|
||||
|
||||
return $container->getCompiler()->getServiceReferenceGraph();
|
||||
}
|
||||
}
|
112
vendor/symfony/dependency-injection/Tests/Compiler/AutoAliasServicePassTest.php
vendored
Normal file
112
vendor/symfony/dependency-injection/Tests/Compiler/AutoAliasServicePassTest.php
vendored
Normal file
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\AutoAliasServicePass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
class AutoAliasServicePassTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException
|
||||
*/
|
||||
public function testProcessWithMissingParameter()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('example')
|
||||
->addTag('auto_alias', array('format' => '%non_existing%.example'));
|
||||
|
||||
$pass = new AutoAliasServicePass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function testProcessWithMissingFormat()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('example')
|
||||
->addTag('auto_alias', array());
|
||||
$container->setParameter('existing', 'mysql');
|
||||
|
||||
$pass = new AutoAliasServicePass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testProcessWithNonExistingAlias()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault')
|
||||
->addTag('auto_alias', array('format' => '%existing%.example'));
|
||||
$container->setParameter('existing', 'mysql');
|
||||
|
||||
$pass = new AutoAliasServicePass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertEquals('Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault', $container->getDefinition('example')->getClass());
|
||||
}
|
||||
|
||||
public function testProcessWithExistingAlias()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault')
|
||||
->addTag('auto_alias', array('format' => '%existing%.example'));
|
||||
|
||||
$container->register('mysql.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql');
|
||||
$container->setParameter('existing', 'mysql');
|
||||
|
||||
$pass = new AutoAliasServicePass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertTrue($container->hasAlias('example'));
|
||||
$this->assertEquals('mysql.example', $container->getAlias('example'));
|
||||
$this->assertSame('Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql', $container->getDefinition('mysql.example')->getClass());
|
||||
}
|
||||
|
||||
public function testProcessWithManualAlias()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault')
|
||||
->addTag('auto_alias', array('format' => '%existing%.example'));
|
||||
|
||||
$container->register('mysql.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql');
|
||||
$container->register('mariadb.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMariaDb');
|
||||
$container->setAlias('example', 'mariadb.example');
|
||||
$container->setParameter('existing', 'mysql');
|
||||
|
||||
$pass = new AutoAliasServicePass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertTrue($container->hasAlias('example'));
|
||||
$this->assertEquals('mariadb.example', $container->getAlias('example'));
|
||||
$this->assertSame('Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMariaDb', $container->getDefinition('mariadb.example')->getClass());
|
||||
}
|
||||
}
|
||||
|
||||
class ServiceClassDefault
|
||||
{
|
||||
}
|
||||
|
||||
class ServiceClassMysql extends ServiceClassDefault
|
||||
{
|
||||
}
|
||||
|
||||
class ServiceClassMariaDb extends ServiceClassMysql
|
||||
{
|
||||
}
|
145
vendor/symfony/dependency-injection/Tests/Compiler/AutowireExceptionPassTest.php
vendored
Normal file
145
vendor/symfony/dependency-injection/Tests/Compiler/AutowireExceptionPassTest.php
vendored
Normal file
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\AutowireExceptionPass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\InlineServiceDefinitionsPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Exception\AutowiringFailedException;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class AutowireExceptionPassTest extends TestCase
|
||||
{
|
||||
public function testThrowsException()
|
||||
{
|
||||
$autowirePass = $this->getMockBuilder(AutowirePass::class)
|
||||
->getMock();
|
||||
|
||||
$autowireException = new AutowiringFailedException('foo_service_id', 'An autowiring exception message');
|
||||
$autowirePass->expects($this->any())
|
||||
->method('getAutowiringExceptions')
|
||||
->will($this->returnValue(array($autowireException)));
|
||||
|
||||
$inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class)
|
||||
->getMock();
|
||||
$inlinePass->expects($this->any())
|
||||
->method('getInlinedServiceIds')
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('foo_service_id');
|
||||
|
||||
$pass = new AutowireExceptionPass($autowirePass, $inlinePass);
|
||||
|
||||
try {
|
||||
$pass->process($container);
|
||||
$this->fail('->process() should throw the exception if the service id exists');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertSame($autowireException, $e);
|
||||
}
|
||||
}
|
||||
|
||||
public function testThrowExceptionIfServiceInlined()
|
||||
{
|
||||
$autowirePass = $this->getMockBuilder(AutowirePass::class)
|
||||
->getMock();
|
||||
|
||||
$autowireException = new AutowiringFailedException('a_service', 'An autowiring exception message');
|
||||
$autowirePass->expects($this->any())
|
||||
->method('getAutowiringExceptions')
|
||||
->will($this->returnValue(array($autowireException)));
|
||||
|
||||
$inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class)
|
||||
->getMock();
|
||||
$inlinePass->expects($this->any())
|
||||
->method('getInlinedServiceIds')
|
||||
->will($this->returnValue(array(
|
||||
// a_service inlined into b_service
|
||||
'a_service' => array('b_service'),
|
||||
// b_service inlined into c_service
|
||||
'b_service' => array('c_service'),
|
||||
)));
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
// ONLY register c_service in the final container
|
||||
$container->register('c_service', 'stdClass');
|
||||
|
||||
$pass = new AutowireExceptionPass($autowirePass, $inlinePass);
|
||||
|
||||
try {
|
||||
$pass->process($container);
|
||||
$this->fail('->process() should throw the exception if the service id exists');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertSame($autowireException, $e);
|
||||
}
|
||||
}
|
||||
|
||||
public function testDoNotThrowExceptionIfServiceInlinedButRemoved()
|
||||
{
|
||||
$autowirePass = $this->getMockBuilder(AutowirePass::class)
|
||||
->getMock();
|
||||
|
||||
$autowireException = new AutowiringFailedException('a_service', 'An autowiring exception message');
|
||||
$autowirePass->expects($this->any())
|
||||
->method('getAutowiringExceptions')
|
||||
->will($this->returnValue(array($autowireException)));
|
||||
|
||||
$inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class)
|
||||
->getMock();
|
||||
$inlinePass->expects($this->any())
|
||||
->method('getInlinedServiceIds')
|
||||
->will($this->returnValue(array(
|
||||
// a_service inlined into b_service
|
||||
'a_service' => array('b_service'),
|
||||
// b_service inlined into c_service
|
||||
'b_service' => array('c_service'),
|
||||
)));
|
||||
|
||||
// do NOT register c_service in the container
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$pass = new AutowireExceptionPass($autowirePass, $inlinePass);
|
||||
|
||||
$pass->process($container);
|
||||
// mark the test as passed
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testNoExceptionIfServiceRemoved()
|
||||
{
|
||||
$autowirePass = $this->getMockBuilder(AutowirePass::class)
|
||||
->getMock();
|
||||
|
||||
$autowireException = new AutowiringFailedException('non_existent_service');
|
||||
$autowirePass->expects($this->any())
|
||||
->method('getAutowiringExceptions')
|
||||
->will($this->returnValue(array($autowireException)));
|
||||
|
||||
$inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class)
|
||||
->getMock();
|
||||
$inlinePass->expects($this->any())
|
||||
->method('getInlinedServiceIds')
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$pass = new AutowireExceptionPass($autowirePass, $inlinePass);
|
||||
|
||||
$pass->process($container);
|
||||
// mark the test as passed
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
927
vendor/symfony/dependency-injection/Tests/Compiler/AutowirePassTest.php
vendored
Normal file
927
vendor/symfony/dependency-injection/Tests/Compiler/AutowirePassTest.php
vendored
Normal file
|
@ -0,0 +1,927 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveClassPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Exception\AutowiringFailedException;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\includes\FooVariadic;
|
||||
use Symfony\Component\DependencyInjection\TypedReference;
|
||||
|
||||
require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
|
||||
|
||||
/**
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class AutowirePassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register(Foo::class);
|
||||
$barDefinition = $container->register('bar', __NAMESPACE__.'\Bar');
|
||||
$barDefinition->setAutowired(true);
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$this->assertCount(1, $container->getDefinition('bar')->getArguments());
|
||||
$this->assertEquals(Foo::class, (string) $container->getDefinition('bar')->getArgument(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.6
|
||||
*/
|
||||
public function testProcessVariadic()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register(Foo::class);
|
||||
$definition = $container->register('fooVariadic', FooVariadic::class);
|
||||
$definition->setAutowired(true);
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$this->assertCount(1, $container->getDefinition('fooVariadic')->getArguments());
|
||||
$this->assertEquals(Foo::class, (string) $container->getDefinition('fooVariadic')->getArgument(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should alias the "Symfony\Component\DependencyInjection\Tests\Compiler\B" service to "Symfony\Component\DependencyInjection\Tests\Compiler\A" instead.
|
||||
* @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessageInSymfony4 Cannot autowire service "c": argument "$a" of method "Symfony\Component\DependencyInjection\Tests\Compiler\C::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\B" service.
|
||||
*/
|
||||
public function testProcessAutowireParent()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register(B::class);
|
||||
$cDefinition = $container->register('c', __NAMESPACE__.'\C');
|
||||
$cDefinition->setAutowired(true);
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$this->assertCount(1, $container->getDefinition('c')->getArguments());
|
||||
$this->assertEquals(B::class, (string) $container->getDefinition('c')->getArgument(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. Try changing the type-hint for argument "$a" of method "Symfony\Component\DependencyInjection\Tests\Compiler\C::__construct()" to "Symfony\Component\DependencyInjection\Tests\Compiler\AInterface" instead.
|
||||
* @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessageInSymfony4 Cannot autowire service "c": argument "$a" of method "Symfony\Component\DependencyInjection\Tests\Compiler\C::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\B" service.
|
||||
*/
|
||||
public function testProcessLegacyAutowireWithAvailableInterface()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->setAlias(AInterface::class, B::class);
|
||||
$container->register(B::class);
|
||||
$cDefinition = $container->register('c', __NAMESPACE__.'\C');
|
||||
$cDefinition->setAutowired(true);
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$this->assertCount(1, $container->getDefinition('c')->getArguments());
|
||||
$this->assertEquals(B::class, (string) $container->getDefinition('c')->getArgument(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should alias the "Symfony\Component\DependencyInjection\Tests\Compiler\F" service to "Symfony\Component\DependencyInjection\Tests\Compiler\DInterface" instead.
|
||||
* @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessageInSymfony4 Cannot autowire service "g": argument "$d" of method "Symfony\Component\DependencyInjection\Tests\Compiler\G::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\DInterface" but no such service exists. You should maybe alias this interface to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\F" service.
|
||||
*/
|
||||
public function testProcessAutowireInterface()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register(F::class);
|
||||
$gDefinition = $container->register('g', __NAMESPACE__.'\G');
|
||||
$gDefinition->setAutowired(true);
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$this->assertCount(3, $container->getDefinition('g')->getArguments());
|
||||
$this->assertEquals(F::class, (string) $container->getDefinition('g')->getArgument(0));
|
||||
$this->assertEquals(F::class, (string) $container->getDefinition('g')->getArgument(1));
|
||||
$this->assertEquals(F::class, (string) $container->getDefinition('g')->getArgument(2));
|
||||
}
|
||||
|
||||
public function testCompleteExistingDefinition()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('b', __NAMESPACE__.'\B');
|
||||
$container->register(DInterface::class, F::class);
|
||||
$hDefinition = $container->register('h', __NAMESPACE__.'\H')->addArgument(new Reference('b'));
|
||||
$hDefinition->setAutowired(true);
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$this->assertCount(2, $container->getDefinition('h')->getArguments());
|
||||
$this->assertEquals('b', (string) $container->getDefinition('h')->getArgument(0));
|
||||
$this->assertEquals(DInterface::class, (string) $container->getDefinition('h')->getArgument(1));
|
||||
}
|
||||
|
||||
public function testCompleteExistingDefinitionWithNotDefinedArguments()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register(B::class);
|
||||
$container->register(DInterface::class, F::class);
|
||||
$hDefinition = $container->register('h', __NAMESPACE__.'\H')->addArgument('')->addArgument('');
|
||||
$hDefinition->setAutowired(true);
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$this->assertCount(2, $container->getDefinition('h')->getArguments());
|
||||
$this->assertEquals(B::class, (string) $container->getDefinition('h')->getArgument(0));
|
||||
$this->assertEquals(DInterface::class, (string) $container->getDefinition('h')->getArgument(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testExceptionsAreStored()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('c1', __NAMESPACE__.'\CollisionA');
|
||||
$container->register('c2', __NAMESPACE__.'\CollisionB');
|
||||
$container->register('c3', __NAMESPACE__.'\CollisionB');
|
||||
$aDefinition = $container->register('a', __NAMESPACE__.'\CannotBeAutowired');
|
||||
$aDefinition->setAutowired(true);
|
||||
|
||||
$pass = new AutowirePass(false);
|
||||
$pass->process($container);
|
||||
$this->assertCount(1, $pass->getAutowiringExceptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
||||
* @expectedExceptionMessage Invalid service "private_service": constructor of class "Symfony\Component\DependencyInjection\Tests\Compiler\PrivateConstructor" must be public.
|
||||
*/
|
||||
public function testPrivateConstructorThrowsAutowireException()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->autowire('private_service', __NAMESPACE__.'\PrivateConstructor');
|
||||
|
||||
$pass = new AutowirePass(true);
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
||||
* @expectedExceptionMessage Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\CannotBeAutowired::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2", "c3".
|
||||
*/
|
||||
public function testTypeCollision()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('c1', __NAMESPACE__.'\CollisionA');
|
||||
$container->register('c2', __NAMESPACE__.'\CollisionB');
|
||||
$container->register('c3', __NAMESPACE__.'\CollisionB');
|
||||
$aDefinition = $container->register('a', __NAMESPACE__.'\CannotBeAutowired');
|
||||
$aDefinition->setAutowired(true);
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
||||
* @expectedExceptionMessage Cannot autowire service "a": argument "$k" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotGuessableArgument::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to one of these existing services: "a1", "a2".
|
||||
*/
|
||||
public function testTypeNotGuessable()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('a1', __NAMESPACE__.'\Foo');
|
||||
$container->register('a2', __NAMESPACE__.'\Foo');
|
||||
$aDefinition = $container->register('a', __NAMESPACE__.'\NotGuessableArgument');
|
||||
$aDefinition->setAutowired(true);
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
||||
* @expectedExceptionMessage Cannot autowire service "a": argument "$k" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotGuessableArgumentForSubclass::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to one of these existing services: "a1", "a2".
|
||||
*/
|
||||
public function testTypeNotGuessableWithSubclass()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('a1', __NAMESPACE__.'\B');
|
||||
$container->register('a2', __NAMESPACE__.'\B');
|
||||
$aDefinition = $container->register('a', __NAMESPACE__.'\NotGuessableArgumentForSubclass');
|
||||
$aDefinition->setAutowired(true);
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
||||
* @expectedExceptionMessage Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\CannotBeAutowired::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists.
|
||||
*/
|
||||
public function testTypeNotGuessableNoServicesFound()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$aDefinition = $container->register('a', __NAMESPACE__.'\CannotBeAutowired');
|
||||
$aDefinition->setAutowired(true);
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testTypeNotGuessableWithTypeSet()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('a1', __NAMESPACE__.'\Foo');
|
||||
$container->register('a2', __NAMESPACE__.'\Foo');
|
||||
$container->register(Foo::class, Foo::class);
|
||||
$aDefinition = $container->register('a', __NAMESPACE__.'\NotGuessableArgument');
|
||||
$aDefinition->setAutowired(true);
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertCount(1, $container->getDefinition('a')->getArguments());
|
||||
$this->assertEquals(Foo::class, (string) $container->getDefinition('a')->getArgument(0));
|
||||
}
|
||||
|
||||
public function testWithTypeSet()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('c1', __NAMESPACE__.'\CollisionA');
|
||||
$container->register('c2', __NAMESPACE__.'\CollisionB');
|
||||
$container->setAlias(CollisionInterface::class, 'c2');
|
||||
$aDefinition = $container->register('a', __NAMESPACE__.'\CannotBeAutowired');
|
||||
$aDefinition->setAutowired(true);
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertCount(1, $container->getDefinition('a')->getArguments());
|
||||
$this->assertEquals(CollisionInterface::class, (string) $container->getDefinition('a')->getArgument(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Relying on service auto-registration for type "Symfony\Component\DependencyInjection\Tests\Compiler\Lille" is deprecated since Symfony 3.4 and won't be supported in 4.0. Create a service named "Symfony\Component\DependencyInjection\Tests\Compiler\Lille" instead.
|
||||
* @expectedDeprecation Relying on service auto-registration for type "Symfony\Component\DependencyInjection\Tests\Compiler\Dunglas" is deprecated since Symfony 3.4 and won't be supported in 4.0. Create a service named "Symfony\Component\DependencyInjection\Tests\Compiler\Dunglas" instead.
|
||||
*/
|
||||
public function testCreateDefinition()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$coopTilleulsDefinition = $container->register('coop_tilleuls', __NAMESPACE__.'\LesTilleuls');
|
||||
$coopTilleulsDefinition->setAutowired(true);
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertCount(2, $container->getDefinition('coop_tilleuls')->getArguments());
|
||||
$this->assertEquals('autowired.Symfony\Component\DependencyInjection\Tests\Compiler\Dunglas', $container->getDefinition('coop_tilleuls')->getArgument(0));
|
||||
$this->assertEquals('autowired.Symfony\Component\DependencyInjection\Tests\Compiler\Dunglas', $container->getDefinition('coop_tilleuls')->getArgument(1));
|
||||
|
||||
$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');
|
||||
$this->assertEquals(__NAMESPACE__.'\Lille', $lilleDefinition->getClass());
|
||||
}
|
||||
|
||||
public function testResolveParameter()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->setParameter('class_name', Bar::class);
|
||||
$container->register(Foo::class);
|
||||
$barDefinition = $container->register('bar', '%class_name%');
|
||||
$barDefinition->setAutowired(true);
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$this->assertEquals(Foo::class, $container->getDefinition('bar')->getArgument(0));
|
||||
}
|
||||
|
||||
public function testOptionalParameter()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register(A::class);
|
||||
$container->register(Foo::class);
|
||||
$optDefinition = $container->register('opt', __NAMESPACE__.'\OptionalParameter');
|
||||
$optDefinition->setAutowired(true);
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$definition = $container->getDefinition('opt');
|
||||
$this->assertNull($definition->getArgument(0));
|
||||
$this->assertEquals(A::class, $definition->getArgument(1));
|
||||
$this->assertEquals(Foo::class, $definition->getArgument(2));
|
||||
}
|
||||
|
||||
public function testDontTriggerAutowiring()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register(Foo::class);
|
||||
$container->register('bar', __NAMESPACE__.'\Bar');
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$this->assertCount(0, $container->getDefinition('bar')->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
||||
* @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class was not found.
|
||||
*/
|
||||
public function testClassNotFoundThrowsException()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$aDefinition = $container->register('a', __NAMESPACE__.'\BadTypeHintedArgument');
|
||||
$aDefinition->setAutowired(true);
|
||||
|
||||
$container->register(Dunglas::class, Dunglas::class);
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
||||
* @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass" but this class is missing a parent class (Class Symfony\Bug\NotExistClass not found).
|
||||
*/
|
||||
public function testParentClassNotFoundThrowsException()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$aDefinition = $container->register('a', __NAMESPACE__.'\BadParentTypeHintedArgument');
|
||||
$aDefinition->setAutowired(true);
|
||||
|
||||
$container->register(Dunglas::class, Dunglas::class);
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should rename (or alias) the "foo" service to "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" instead.
|
||||
* @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
||||
* @expectedExceptionMessageInSymfony4 Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but this service is abstract. You should maybe alias this class to the existing "foo" service.
|
||||
*/
|
||||
public function testDontUseAbstractServices()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register(Foo::class)->setAbstract(true);
|
||||
$container->register('foo', __NAMESPACE__.'\Foo');
|
||||
$container->register('bar', __NAMESPACE__.'\Bar')->setAutowired(true);
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
}
|
||||
|
||||
public function testSomeSpecificArgumentsAreSet()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('foo', Foo::class);
|
||||
$container->register(A::class);
|
||||
$container->register(Dunglas::class);
|
||||
$container->register('multiple', __NAMESPACE__.'\MultipleArguments')
|
||||
->setAutowired(true)
|
||||
// set the 2nd (index 1) argument only: autowire the first and third
|
||||
// args are: A, Foo, Dunglas
|
||||
->setArguments(array(
|
||||
1 => new Reference('foo'),
|
||||
3 => array('bar'),
|
||||
));
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$definition = $container->getDefinition('multiple');
|
||||
$this->assertEquals(
|
||||
array(
|
||||
new TypedReference(A::class, A::class, MultipleArguments::class),
|
||||
new Reference('foo'),
|
||||
new TypedReference(Dunglas::class, Dunglas::class, MultipleArguments::class),
|
||||
array('bar'),
|
||||
),
|
||||
$definition->getArguments()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
||||
* @expectedExceptionMessage Cannot autowire service "arg_no_type_hint": argument "$bar" of method "Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArguments::__construct()" is type-hinted "array", you should configure its value explicitly.
|
||||
*/
|
||||
public function testScalarArgsCannotBeAutowired()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register(A::class);
|
||||
$container->register(Dunglas::class);
|
||||
$container->register('arg_no_type_hint', __NAMESPACE__.'\MultipleArguments')
|
||||
->setArguments(array(1 => 'foo'))
|
||||
->setAutowired(true);
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
||||
* @expectedExceptionMessage Cannot autowire service "arg_no_type_hint": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArguments::__construct()" has no type-hint, you should configure its value explicitly.
|
||||
*/
|
||||
public function testNoTypeArgsCannotBeAutowired()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register(A::class);
|
||||
$container->register(Dunglas::class);
|
||||
$container->register('arg_no_type_hint', __NAMESPACE__.'\MultipleArguments')
|
||||
->setAutowired(true);
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
}
|
||||
|
||||
public function testOptionalScalarNotReallyOptionalUsesDefaultValue()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register(A::class);
|
||||
$container->register(Lille::class);
|
||||
$definition = $container->register('not_really_optional_scalar', __NAMESPACE__.'\MultipleArgumentsOptionalScalarNotReallyOptional')
|
||||
->setAutowired(true);
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$this->assertSame('default_val', $definition->getArgument(1));
|
||||
}
|
||||
|
||||
public function testOptionalScalarArgsDontMessUpOrder()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register(A::class);
|
||||
$container->register(Lille::class);
|
||||
$container->register('with_optional_scalar', __NAMESPACE__.'\MultipleArgumentsOptionalScalar')
|
||||
->setAutowired(true);
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$definition = $container->getDefinition('with_optional_scalar');
|
||||
$this->assertEquals(
|
||||
array(
|
||||
new TypedReference(A::class, A::class, MultipleArgumentsOptionalScalar::class),
|
||||
// use the default value
|
||||
'default_val',
|
||||
new TypedReference(Lille::class, Lille::class),
|
||||
),
|
||||
$definition->getArguments()
|
||||
);
|
||||
}
|
||||
|
||||
public function testOptionalScalarArgsNotPassedIfLast()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register(A::class);
|
||||
$container->register(Lille::class);
|
||||
$container->register('with_optional_scalar_last', __NAMESPACE__.'\MultipleArgumentsOptionalScalarLast')
|
||||
->setAutowired(true);
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$definition = $container->getDefinition('with_optional_scalar_last');
|
||||
$this->assertEquals(
|
||||
array(
|
||||
new TypedReference(A::class, A::class, MultipleArgumentsOptionalScalarLast::class),
|
||||
new TypedReference(Lille::class, Lille::class, MultipleArgumentsOptionalScalarLast::class),
|
||||
),
|
||||
$definition->getArguments()
|
||||
);
|
||||
}
|
||||
|
||||
public function testOptionalArgsNoRequiredForCoreClasses()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('foo', \SplFileObject::class)
|
||||
->addArgument('foo.txt')
|
||||
->setAutowired(true);
|
||||
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$definition = $container->getDefinition('foo');
|
||||
$this->assertEquals(
|
||||
array('foo.txt'),
|
||||
$definition->getArguments()
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetterInjection()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register(Foo::class);
|
||||
$container->register(A::class);
|
||||
$container->register(CollisionA::class);
|
||||
$container->register(CollisionB::class);
|
||||
|
||||
// manually configure *one* call, to override autowiring
|
||||
$container
|
||||
->register('setter_injection', SetterInjection::class)
|
||||
->setAutowired(true)
|
||||
->addMethodCall('setWithCallsConfigured', array('manual_arg1', 'manual_arg2'))
|
||||
;
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowireRequiredMethodsPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$methodCalls = $container->getDefinition('setter_injection')->getMethodCalls();
|
||||
|
||||
$this->assertEquals(
|
||||
array('setWithCallsConfigured', 'setFoo', 'setDependencies', 'setChildMethodWithoutDocBlock'),
|
||||
array_column($methodCalls, 0)
|
||||
);
|
||||
|
||||
// test setWithCallsConfigured args
|
||||
$this->assertEquals(
|
||||
array('manual_arg1', 'manual_arg2'),
|
||||
$methodCalls[0][1]
|
||||
);
|
||||
// test setFoo args
|
||||
$this->assertEquals(
|
||||
array(new TypedReference(Foo::class, Foo::class, SetterInjection::class)),
|
||||
$methodCalls[1][1]
|
||||
);
|
||||
}
|
||||
|
||||
public function testExplicitMethodInjection()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register(Foo::class);
|
||||
$container->register(A::class);
|
||||
$container->register(CollisionA::class);
|
||||
$container->register(CollisionB::class);
|
||||
|
||||
$container
|
||||
->register('setter_injection', SetterInjection::class)
|
||||
->setAutowired(true)
|
||||
->addMethodCall('notASetter', array())
|
||||
;
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowireRequiredMethodsPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$methodCalls = $container->getDefinition('setter_injection')->getMethodCalls();
|
||||
|
||||
$this->assertEquals(
|
||||
array('notASetter', 'setFoo', 'setDependencies', 'setWithCallsConfigured', 'setChildMethodWithoutDocBlock'),
|
||||
array_column($methodCalls, 0)
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(new TypedReference(A::class, A::class, SetterInjection::class)),
|
||||
$methodCalls[0][1]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Relying on service auto-registration for type "Symfony\Component\DependencyInjection\Tests\Compiler\A" is deprecated since Symfony 3.4 and won't be supported in 4.0. Create a service named "Symfony\Component\DependencyInjection\Tests\Compiler\A" instead.
|
||||
*/
|
||||
public function testTypedReference()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('bar', Bar::class)
|
||||
->setProperty('a', array(new TypedReference(A::class, A::class, Bar::class)))
|
||||
;
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertSame(A::class, $container->getDefinition('autowired.'.A::class)->getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getCreateResourceTests
|
||||
* @group legacy
|
||||
*/
|
||||
public function testCreateResourceForClass($className, $isEqual)
|
||||
{
|
||||
$startingResource = AutowirePass::createResourceForClass(
|
||||
new \ReflectionClass(__NAMESPACE__.'\ClassForResource')
|
||||
);
|
||||
$newResource = AutowirePass::createResourceForClass(
|
||||
new \ReflectionClass(__NAMESPACE__.'\\'.$className)
|
||||
);
|
||||
|
||||
// hack so the objects don't differ by the class name
|
||||
$startingReflObject = new \ReflectionObject($startingResource);
|
||||
$reflProp = $startingReflObject->getProperty('class');
|
||||
$reflProp->setAccessible(true);
|
||||
$reflProp->setValue($startingResource, __NAMESPACE__.'\\'.$className);
|
||||
|
||||
if ($isEqual) {
|
||||
$this->assertEquals($startingResource, $newResource);
|
||||
} else {
|
||||
$this->assertNotEquals($startingResource, $newResource);
|
||||
}
|
||||
}
|
||||
|
||||
public function getCreateResourceTests()
|
||||
{
|
||||
return array(
|
||||
array('IdenticalClassResource', true),
|
||||
array('ClassChangedConstructorArgs', false),
|
||||
);
|
||||
}
|
||||
|
||||
public function testIgnoreServiceWithClassNotExisting()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('class_not_exist', __NAMESPACE__.'\OptionalServiceClass');
|
||||
|
||||
$barDefinition = $container->register('bar', __NAMESPACE__.'\Bar');
|
||||
$barDefinition->setAutowired(true);
|
||||
|
||||
$container->register(Foo::class, Foo::class);
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertTrue($container->hasDefinition('bar'));
|
||||
}
|
||||
|
||||
public function testSetterInjectionCollisionThrowsException()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('c1', CollisionA::class);
|
||||
$container->register('c2', CollisionB::class);
|
||||
$aDefinition = $container->register('setter_injection_collision', SetterInjectionCollision::class);
|
||||
$aDefinition->setAutowired(true);
|
||||
|
||||
(new AutowireRequiredMethodsPass())->process($container);
|
||||
|
||||
$pass = new AutowirePass();
|
||||
|
||||
try {
|
||||
$pass->process($container);
|
||||
} catch (AutowiringFailedException $e) {
|
||||
}
|
||||
|
||||
$this->assertNotNull($e);
|
||||
$this->assertSame('Cannot autowire service "setter_injection_collision": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\SetterInjectionCollision::setMultipleInstancesForOneArg()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2".', $e->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
||||
* @expectedExceptionMessage Cannot autowire service "my_service": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\K::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" but no such service exists. Did you create a class that implements this interface?
|
||||
*/
|
||||
public function testInterfaceWithNoImplementationSuggestToWriteOne()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$aDefinition = $container->register('my_service', K::class);
|
||||
$aDefinition->setAutowired(true);
|
||||
|
||||
(new AutowireRequiredMethodsPass())->process($container);
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should rename (or alias) the "foo" service to "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" instead.
|
||||
* @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
||||
* @expectedExceptionMessageInSymfony4 Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to the existing "foo" service.
|
||||
*/
|
||||
public function testProcessDoesNotTriggerDeprecations()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('deprecated', 'Symfony\Component\DependencyInjection\Tests\Fixtures\DeprecatedClass')->setDeprecated(true);
|
||||
$container->register('foo', __NAMESPACE__.'\Foo');
|
||||
$container->register('bar', __NAMESPACE__.'\Bar')->setAutowired(true);
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertTrue($container->hasDefinition('deprecated'));
|
||||
$this->assertTrue($container->hasDefinition('foo'));
|
||||
$this->assertTrue($container->hasDefinition('bar'));
|
||||
}
|
||||
|
||||
public function testEmptyStringIsKept()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register(A::class);
|
||||
$container->register(Lille::class);
|
||||
$container->register('foo', __NAMESPACE__.'\MultipleArgumentsOptionalScalar')
|
||||
->setAutowired(true)
|
||||
->setArguments(array('', ''));
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$this->assertEquals(array(new TypedReference(A::class, A::class, MultipleArgumentsOptionalScalar::class), '', new TypedReference(Lille::class, Lille::class)), $container->getDefinition('foo')->getArguments());
|
||||
}
|
||||
|
||||
public function testWithFactory()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register(Foo::class);
|
||||
$definition = $container->register('a', A::class)
|
||||
->setFactory(array(A::class, 'create'))
|
||||
->setAutowired(true);
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
|
||||
$this->assertEquals(array(new TypedReference(Foo::class, Foo::class, A::class)), $definition->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideNotWireableCalls
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
||||
*/
|
||||
public function testNotWireableCalls($method, $expectedMsg)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$foo = $container->register('foo', NotWireable::class)->setAutowired(true)
|
||||
->addMethodCall('setBar', array())
|
||||
->addMethodCall('setOptionalNotAutowireable', array())
|
||||
->addMethodCall('setOptionalNoTypeHint', array())
|
||||
->addMethodCall('setOptionalArgNoAutowireable', array())
|
||||
;
|
||||
|
||||
if ($method) {
|
||||
$foo->addMethodCall($method, array());
|
||||
}
|
||||
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->expectExceptionMessage($expectedMsg);
|
||||
} else {
|
||||
$this->setExpectedException(RuntimeException::class, $expectedMsg);
|
||||
}
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowireRequiredMethodsPass())->process($container);
|
||||
(new AutowirePass())->process($container);
|
||||
}
|
||||
|
||||
public function provideNotWireableCalls()
|
||||
{
|
||||
return array(
|
||||
array('setNotAutowireable', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setNotAutowireable()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class was not found.'),
|
||||
array('setDifferentNamespace', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setDifferentNamespace()" references class "stdClass" but no such service exists. It cannot be auto-registered because it is from a different root namespace.'),
|
||||
array(null, 'Invalid service "foo": method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setProtectedMethod()" must be public.'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. Try changing the type-hint for argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead.
|
||||
* @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
||||
* @expectedExceptionMessageInSymfony4 Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. Try changing the type-hint to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead.
|
||||
*/
|
||||
public function testByIdAlternative()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->setAlias(IInterface::class, 'i');
|
||||
$container->register('i', I::class);
|
||||
$container->register('j', J::class)
|
||||
->setAutowired(true);
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. Try changing the type-hint for "Symfony\Component\DependencyInjection\Tests\Compiler\A" in "Symfony\Component\DependencyInjection\Tests\Compiler\Bar" to "Symfony\Component\DependencyInjection\Tests\Compiler\AInterface" instead.
|
||||
*/
|
||||
public function testTypedReferenceDeprecationNotice()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('aClass', A::class);
|
||||
$container->setAlias(AInterface::class, 'aClass');
|
||||
$container
|
||||
->register('bar', Bar::class)
|
||||
->setProperty('a', array(new TypedReference(A::class, A::class, Bar::class)))
|
||||
;
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
||||
* @expectedExceptionMessage Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. Try changing the type-hint to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead.
|
||||
*/
|
||||
public function testExceptionWhenAliasExists()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
// multiple I services... but there *is* IInterface available
|
||||
$container->setAlias(IInterface::class, 'i');
|
||||
$container->register('i', I::class);
|
||||
$container->register('i2', I::class);
|
||||
// J type-hints against I concretely
|
||||
$container->register('j', J::class)
|
||||
->setAutowired(true);
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
||||
* @expectedExceptionMessage Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. You should maybe alias this class to one of these existing services: "i", "i2".
|
||||
*/
|
||||
public function testExceptionWhenAliasDoesNotExist()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
// multiple I instances... but no IInterface alias
|
||||
$container->register('i', I::class);
|
||||
$container->register('i2', I::class);
|
||||
// J type-hints against I concretely
|
||||
$container->register('j', J::class)
|
||||
->setAutowired(true);
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testInlineServicesAreNotCandidates()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new XmlFileLoader($container, new FileLocator(realpath(__DIR__.'/../Fixtures/xml')));
|
||||
$loader->load('services_inline_not_candidate.xml');
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertSame(array(), $container->getDefinition('autowired')->getArguments());
|
||||
}
|
||||
}
|
80
vendor/symfony/dependency-injection/Tests/Compiler/AutowireRequiredMethodsPassTest.php
vendored
Normal file
80
vendor/symfony/dependency-injection/Tests/Compiler/AutowireRequiredMethodsPassTest.php
vendored
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveClassPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
|
||||
|
||||
class AutowireRequiredMethodsPassTest extends TestCase
|
||||
{
|
||||
public function testSetterInjection()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register(Foo::class);
|
||||
$container->register(A::class);
|
||||
$container->register(CollisionA::class);
|
||||
$container->register(CollisionB::class);
|
||||
|
||||
// manually configure *one* call, to override autowiring
|
||||
$container
|
||||
->register('setter_injection', SetterInjection::class)
|
||||
->setAutowired(true)
|
||||
->addMethodCall('setWithCallsConfigured', array('manual_arg1', 'manual_arg2'));
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowireRequiredMethodsPass())->process($container);
|
||||
|
||||
$methodCalls = $container->getDefinition('setter_injection')->getMethodCalls();
|
||||
|
||||
$this->assertEquals(
|
||||
array('setWithCallsConfigured', 'setFoo', 'setDependencies', 'setChildMethodWithoutDocBlock'),
|
||||
array_column($methodCalls, 0)
|
||||
);
|
||||
|
||||
// test setWithCallsConfigured args
|
||||
$this->assertEquals(
|
||||
array('manual_arg1', 'manual_arg2'),
|
||||
$methodCalls[0][1]
|
||||
);
|
||||
// test setFoo args
|
||||
$this->assertEquals(array(), $methodCalls[1][1]);
|
||||
}
|
||||
|
||||
public function testExplicitMethodInjection()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register(Foo::class);
|
||||
$container->register(A::class);
|
||||
$container->register(CollisionA::class);
|
||||
$container->register(CollisionB::class);
|
||||
|
||||
$container
|
||||
->register('setter_injection', SetterInjection::class)
|
||||
->setAutowired(true)
|
||||
->addMethodCall('notASetter', array());
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowireRequiredMethodsPass())->process($container);
|
||||
|
||||
$methodCalls = $container->getDefinition('setter_injection')->getMethodCalls();
|
||||
|
||||
$this->assertEquals(
|
||||
array('notASetter', 'setFoo', 'setDependencies', 'setWithCallsConfigured', 'setChildMethodWithoutDocBlock'),
|
||||
array_column($methodCalls, 0)
|
||||
);
|
||||
$this->assertEquals(array(), $methodCalls[0][1]);
|
||||
}
|
||||
}
|
78
vendor/symfony/dependency-injection/Tests/Compiler/CheckArgumentsValidityPassTest.php
vendored
Normal file
78
vendor/symfony/dependency-injection/Tests/Compiler/CheckArgumentsValidityPassTest.php
vendored
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CheckArgumentsValidityPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class CheckArgumentsValidityPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$definition = $container->register('foo');
|
||||
$definition->setArguments(array(null, 1, 'a'));
|
||||
$definition->setMethodCalls(array(
|
||||
array('bar', array('a', 'b')),
|
||||
array('baz', array('c', 'd')),
|
||||
));
|
||||
|
||||
$pass = new CheckArgumentsValidityPass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertEquals(array(null, 1, 'a'), $container->getDefinition('foo')->getArguments());
|
||||
$this->assertEquals(array(
|
||||
array('bar', array('a', 'b')),
|
||||
array('baz', array('c', 'd')),
|
||||
), $container->getDefinition('foo')->getMethodCalls());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @dataProvider definitionProvider
|
||||
*/
|
||||
public function testException(array $arguments, array $methodCalls)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$definition = $container->register('foo');
|
||||
$definition->setArguments($arguments);
|
||||
$definition->setMethodCalls($methodCalls);
|
||||
|
||||
$pass = new CheckArgumentsValidityPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function definitionProvider()
|
||||
{
|
||||
return array(
|
||||
array(array(null, 'a' => 'a'), array()),
|
||||
array(array(1 => 1), array()),
|
||||
array(array(), array(array('baz', array(null, 'a' => 'a')))),
|
||||
array(array(), array(array('baz', array(1 => 1)))),
|
||||
);
|
||||
}
|
||||
|
||||
public function testNoException()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$definition = $container->register('foo');
|
||||
$definition->setArguments(array(null, 'a' => 'a'));
|
||||
|
||||
$pass = new CheckArgumentsValidityPass(false);
|
||||
$pass->process($container);
|
||||
$this->assertCount(1, $definition->getErrors());
|
||||
}
|
||||
}
|
158
vendor/symfony/dependency-injection/Tests/Compiler/CheckCircularReferencesPassTest.php
vendored
Normal file
158
vendor/symfony/dependency-injection/Tests/Compiler/CheckCircularReferencesPassTest.php
vendored
Normal file
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CheckCircularReferencesPass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\Compiler;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class CheckCircularReferencesPassTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||
*/
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('a')->addArgument(new Reference('b'));
|
||||
$container->register('b')->addArgument(new Reference('a'));
|
||||
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||
*/
|
||||
public function testProcessWithAliases()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('a')->addArgument(new Reference('b'));
|
||||
$container->setAlias('b', 'c');
|
||||
$container->setAlias('c', 'a');
|
||||
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||
*/
|
||||
public function testProcessWithFactory()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('a', 'stdClass')
|
||||
->setFactory(array(new Reference('b'), 'getInstance'));
|
||||
|
||||
$container
|
||||
->register('b', 'stdClass')
|
||||
->setFactory(array(new Reference('a'), 'getInstance'));
|
||||
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||
*/
|
||||
public function testProcessDetectsIndirectCircularReference()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('a')->addArgument(new Reference('b'));
|
||||
$container->register('b')->addArgument(new Reference('c'));
|
||||
$container->register('c')->addArgument(new Reference('a'));
|
||||
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||
*/
|
||||
public function testProcessDetectsIndirectCircularReferenceWithFactory()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('a')->addArgument(new Reference('b'));
|
||||
|
||||
$container
|
||||
->register('b', 'stdClass')
|
||||
->setFactory(array(new Reference('c'), 'getInstance'));
|
||||
|
||||
$container->register('c')->addArgument(new Reference('a'));
|
||||
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||
*/
|
||||
public function testDeepCircularReference()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('a')->addArgument(new Reference('b'));
|
||||
$container->register('b')->addArgument(new Reference('c'));
|
||||
$container->register('c')->addArgument(new Reference('b'));
|
||||
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
public function testProcessIgnoresMethodCalls()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('a')->addArgument(new Reference('b'));
|
||||
$container->register('b')->addMethodCall('setA', array(new Reference('a')));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testProcessIgnoresLazyServices()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('a')->setLazy(true)->addArgument(new Reference('b'));
|
||||
$container->register('b')->addArgument(new Reference('a'));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
// just make sure that a lazily loaded service does not trigger a CircularReferenceException
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testProcessIgnoresIteratorArguments()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('a')->addArgument(new Reference('b'));
|
||||
$container->register('b')->addArgument(new IteratorArgument(array(new Reference('a'))));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
// just make sure that an IteratorArgument does not trigger a CircularReferenceException
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
$compiler = new Compiler();
|
||||
$passConfig = $compiler->getPassConfig();
|
||||
$passConfig->setOptimizationPasses(array(
|
||||
new AnalyzeServiceReferencesPass(true),
|
||||
new CheckCircularReferencesPass(),
|
||||
));
|
||||
$passConfig->setRemovingPasses(array());
|
||||
|
||||
$compiler->compile($container);
|
||||
}
|
||||
}
|
120
vendor/symfony/dependency-injection/Tests/Compiler/CheckDefinitionValidityPassTest.php
vendored
Normal file
120
vendor/symfony/dependency-injection/Tests/Compiler/CheckDefinitionValidityPassTest.php
vendored
Normal file
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CheckDefinitionValidityPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
class CheckDefinitionValidityPassTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
*/
|
||||
public function testProcessDetectsSyntheticNonPublicDefinitions()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('a')->setSynthetic(true)->setPublic(false);
|
||||
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
*/
|
||||
public function testProcessDetectsNonSyntheticNonAbstractDefinitionWithoutClass()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('a')->setSynthetic(false)->setAbstract(false);
|
||||
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('a', 'class');
|
||||
$container->register('b', 'class')->setSynthetic(true)->setPublic(true);
|
||||
$container->register('c', 'class')->setAbstract(true);
|
||||
$container->register('d', 'class')->setSynthetic(true);
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testValidTags()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('a', 'class')->addTag('foo', array('bar' => 'baz'));
|
||||
$container->register('b', 'class')->addTag('foo', array('bar' => null));
|
||||
$container->register('c', 'class')->addTag('foo', array('bar' => 1));
|
||||
$container->register('d', 'class')->addTag('foo', array('bar' => 1.1));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
*/
|
||||
public function testInvalidTags()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('a', 'class')->addTag('foo', array('bar' => array('baz' => 'baz')));
|
||||
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\EnvParameterException
|
||||
*/
|
||||
public function testDynamicPublicServiceName()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$env = $container->getParameterBag()->get('env(BAR)');
|
||||
$container->register("foo.$env", 'class')->setPublic(true);
|
||||
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\EnvParameterException
|
||||
*/
|
||||
public function testDynamicPublicAliasName()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$env = $container->getParameterBag()->get('env(BAR)');
|
||||
$container->setAlias("foo.$env", 'class')->setPublic(true);
|
||||
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
public function testDynamicPrivateName()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$env = $container->getParameterBag()->get('env(BAR)');
|
||||
$container->register("foo.$env", 'class');
|
||||
$container->setAlias("bar.$env", 'class');
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
$pass = new CheckDefinitionValidityPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class CheckExceptionOnInvalidReferenceBehaviorPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('a', '\stdClass')
|
||||
->addArgument(new Reference('b'))
|
||||
;
|
||||
$container->register('b', '\stdClass');
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
|
||||
*/
|
||||
public function testProcessThrowsExceptionOnInvalidReference()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('a', '\stdClass')
|
||||
->addArgument(new Reference('b'))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
|
||||
*/
|
||||
public function testProcessThrowsExceptionOnInvalidReferenceFromInlinedDefinition()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$def = new Definition();
|
||||
$def->addArgument(new Reference('b'));
|
||||
|
||||
$container
|
||||
->register('a', '\stdClass')
|
||||
->addArgument($def)
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
public function testProcessDefinitionWithBindings()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('b')
|
||||
->setBindings(array(new BoundArgument(new Reference('a'))))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
private function process(ContainerBuilder $container)
|
||||
{
|
||||
$pass = new CheckExceptionOnInvalidReferenceBehaviorPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
}
|
50
vendor/symfony/dependency-injection/Tests/Compiler/CheckReferenceValidityPassTest.php
vendored
Normal file
50
vendor/symfony/dependency-injection/Tests/Compiler/CheckReferenceValidityPassTest.php
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CheckReferenceValidityPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class CheckReferenceValidityPassTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testProcessDetectsReferenceToAbstractDefinition()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('a')->setAbstract(true);
|
||||
$container->register('b')->addArgument(new Reference('a'));
|
||||
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('a')->addArgument(new Reference('b'));
|
||||
$container->register('b');
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
$pass = new CheckReferenceValidityPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
}
|
199
vendor/symfony/dependency-injection/Tests/Compiler/DecoratorServicePassTest.php
vendored
Normal file
199
vendor/symfony/dependency-injection/Tests/Compiler/DecoratorServicePassTest.php
vendored
Normal file
|
@ -0,0 +1,199 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
use Symfony\Component\DependencyInjection\Compiler\DecoratorServicePass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
class DecoratorServicePassTest extends TestCase
|
||||
{
|
||||
public function testProcessWithoutAlias()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$fooDefinition = $container
|
||||
->register('foo')
|
||||
->setPublic(false)
|
||||
;
|
||||
$fooExtendedDefinition = $container
|
||||
->register('foo.extended')
|
||||
->setPublic(true)
|
||||
->setDecoratedService('foo')
|
||||
;
|
||||
$barDefinition = $container
|
||||
->register('bar')
|
||||
->setPublic(true)
|
||||
;
|
||||
$barExtendedDefinition = $container
|
||||
->register('bar.extended')
|
||||
->setPublic(true)
|
||||
->setDecoratedService('bar', 'bar.yoo')
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertEquals('foo.extended', $container->getAlias('foo'));
|
||||
$this->assertFalse($container->getAlias('foo')->isPublic());
|
||||
|
||||
$this->assertEquals('bar.extended', $container->getAlias('bar'));
|
||||
$this->assertTrue($container->getAlias('bar')->isPublic());
|
||||
|
||||
$this->assertSame($fooDefinition, $container->getDefinition('foo.extended.inner'));
|
||||
$this->assertFalse($container->getDefinition('foo.extended.inner')->isPublic());
|
||||
|
||||
$this->assertSame($barDefinition, $container->getDefinition('bar.yoo'));
|
||||
$this->assertFalse($container->getDefinition('bar.yoo')->isPublic());
|
||||
|
||||
$this->assertNull($fooExtendedDefinition->getDecoratedService());
|
||||
$this->assertNull($barExtendedDefinition->getDecoratedService());
|
||||
}
|
||||
|
||||
public function testProcessWithAlias()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('foo')
|
||||
->setPublic(true)
|
||||
;
|
||||
$container->setAlias('foo.alias', new Alias('foo', false));
|
||||
$fooExtendedDefinition = $container
|
||||
->register('foo.extended')
|
||||
->setPublic(true)
|
||||
->setDecoratedService('foo.alias')
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertEquals('foo.extended', $container->getAlias('foo.alias'));
|
||||
$this->assertFalse($container->getAlias('foo.alias')->isPublic());
|
||||
|
||||
$this->assertEquals('foo', $container->getAlias('foo.extended.inner'));
|
||||
$this->assertFalse($container->getAlias('foo.extended.inner')->isPublic());
|
||||
|
||||
$this->assertNull($fooExtendedDefinition->getDecoratedService());
|
||||
}
|
||||
|
||||
public function testProcessWithPriority()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$fooDefinition = $container
|
||||
->register('foo')
|
||||
->setPublic(false)
|
||||
;
|
||||
$barDefinition = $container
|
||||
->register('bar')
|
||||
->setPublic(true)
|
||||
->setDecoratedService('foo')
|
||||
;
|
||||
$bazDefinition = $container
|
||||
->register('baz')
|
||||
->setPublic(true)
|
||||
->setDecoratedService('foo', null, 5)
|
||||
;
|
||||
$quxDefinition = $container
|
||||
->register('qux')
|
||||
->setPublic(true)
|
||||
->setDecoratedService('foo', null, 3)
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertEquals('bar', $container->getAlias('foo'));
|
||||
$this->assertFalse($container->getAlias('foo')->isPublic());
|
||||
|
||||
$this->assertSame($fooDefinition, $container->getDefinition('baz.inner'));
|
||||
$this->assertFalse($container->getDefinition('baz.inner')->isPublic());
|
||||
|
||||
$this->assertEquals('qux', $container->getAlias('bar.inner'));
|
||||
$this->assertFalse($container->getAlias('bar.inner')->isPublic());
|
||||
|
||||
$this->assertEquals('baz', $container->getAlias('qux.inner'));
|
||||
$this->assertFalse($container->getAlias('qux.inner')->isPublic());
|
||||
|
||||
$this->assertNull($barDefinition->getDecoratedService());
|
||||
$this->assertNull($bazDefinition->getDecoratedService());
|
||||
$this->assertNull($quxDefinition->getDecoratedService());
|
||||
}
|
||||
|
||||
public function testProcessMovesTagsFromDecoratedDefinitionToDecoratingDefinition()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('foo')
|
||||
->setTags(array('bar' => array('attr' => 'baz')))
|
||||
;
|
||||
$container
|
||||
->register('baz')
|
||||
->setTags(array('foobar' => array('attr' => 'bar')))
|
||||
->setDecoratedService('foo')
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertEmpty($container->getDefinition('baz.inner')->getTags());
|
||||
$this->assertEquals(array('bar' => array('attr' => 'baz'), 'foobar' => array('attr' => 'bar')), $container->getDefinition('baz')->getTags());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testProcessMergesAutowiringTypesInDecoratingDefinitionAndRemoveThemFromDecoratedDefinition()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('parent')
|
||||
->addAutowiringType('Bar')
|
||||
;
|
||||
|
||||
$container
|
||||
->register('child')
|
||||
->setDecoratedService('parent')
|
||||
->addAutowiringType('Foo')
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertEquals(array('Bar', 'Foo'), $container->getDefinition('child')->getAutowiringTypes());
|
||||
$this->assertEmpty($container->getDefinition('child.inner')->getAutowiringTypes());
|
||||
}
|
||||
|
||||
public function testProcessMovesTagsFromDecoratedDefinitionToDecoratingDefinitionMultipleTimes()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('foo')
|
||||
->setPublic(true)
|
||||
->setTags(array('bar' => array('attr' => 'baz')))
|
||||
;
|
||||
$container
|
||||
->register('deco1')
|
||||
->setDecoratedService('foo', null, 50)
|
||||
;
|
||||
$container
|
||||
->register('deco2')
|
||||
->setDecoratedService('foo', null, 2)
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertEmpty($container->getDefinition('deco1')->getTags());
|
||||
$this->assertEquals(array('bar' => array('attr' => 'baz')), $container->getDefinition('deco2')->getTags());
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
$repeatedPass = new DecoratorServicePass();
|
||||
$repeatedPass->process($container);
|
||||
}
|
||||
}
|
53
vendor/symfony/dependency-injection/Tests/Compiler/DefinitionErrorExceptionPassTest.php
vendored
Normal file
53
vendor/symfony/dependency-injection/Tests/Compiler/DefinitionErrorExceptionPassTest.php
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
class DefinitionErrorExceptionPassTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Things went wrong!
|
||||
*/
|
||||
public function testThrowsException()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$def = new Definition();
|
||||
$def->addError('Things went wrong!');
|
||||
$def->addError('Now something else!');
|
||||
$container->register('foo_service_id')
|
||||
->setArguments(array(
|
||||
$def,
|
||||
));
|
||||
|
||||
$pass = new DefinitionErrorExceptionPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testNoExceptionThrown()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$def = new Definition();
|
||||
$container->register('foo_service_id')
|
||||
->setArguments(array(
|
||||
$def,
|
||||
));
|
||||
|
||||
$pass = new DefinitionErrorExceptionPass();
|
||||
$pass->process($container);
|
||||
$this->assertSame($def, $container->getDefinition('foo_service_id')->getArgument(0));
|
||||
}
|
||||
}
|
81
vendor/symfony/dependency-injection/Tests/Compiler/ExtensionCompilerPassTest.php
vendored
Normal file
81
vendor/symfony/dependency-injection/Tests/Compiler/ExtensionCompilerPassTest.php
vendored
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ExtensionCompilerPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||
|
||||
/**
|
||||
* @author Wouter J <wouter@wouterj.nl>
|
||||
*/
|
||||
class ExtensionCompilerPassTest extends TestCase
|
||||
{
|
||||
private $container;
|
||||
private $pass;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->container = new ContainerBuilder();
|
||||
$this->pass = new ExtensionCompilerPass();
|
||||
}
|
||||
|
||||
public function testProcess()
|
||||
{
|
||||
$extension1 = new CompilerPassExtension('extension1');
|
||||
$extension2 = new DummyExtension('extension2');
|
||||
$extension3 = new DummyExtension('extension3');
|
||||
$extension4 = new CompilerPassExtension('extension4');
|
||||
|
||||
$this->container->registerExtension($extension1);
|
||||
$this->container->registerExtension($extension2);
|
||||
$this->container->registerExtension($extension3);
|
||||
$this->container->registerExtension($extension4);
|
||||
|
||||
$this->pass->process($this->container);
|
||||
|
||||
$this->assertTrue($this->container->hasDefinition('extension1'));
|
||||
$this->assertFalse($this->container->hasDefinition('extension2'));
|
||||
$this->assertFalse($this->container->hasDefinition('extension3'));
|
||||
$this->assertTrue($this->container->hasDefinition('extension4'));
|
||||
}
|
||||
}
|
||||
|
||||
class DummyExtension extends Extension
|
||||
{
|
||||
private $alias;
|
||||
|
||||
public function __construct($alias)
|
||||
{
|
||||
$this->alias = $alias;
|
||||
}
|
||||
|
||||
public function getAlias()
|
||||
{
|
||||
return $this->alias;
|
||||
}
|
||||
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
}
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$container->register($this->alias);
|
||||
}
|
||||
}
|
||||
|
||||
class CompilerPassExtension extends DummyExtension implements CompilerPassInterface
|
||||
{
|
||||
}
|
123
vendor/symfony/dependency-injection/Tests/Compiler/FactoryReturnTypePassTest.php
vendored
Normal file
123
vendor/symfony/dependency-injection/Tests/Compiler/FactoryReturnTypePassTest.php
vendored
Normal file
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\FactoryReturnTypePass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy;
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\factoryFunction;
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryParent;
|
||||
|
||||
/**
|
||||
* @author Guilhem N. <egetick@gmail.com>
|
||||
*
|
||||
* @group legacy
|
||||
*/
|
||||
class FactoryReturnTypePassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$factory = $container->register('factory');
|
||||
$factory->setFactory(array(FactoryDummy::class, 'createFactory'));
|
||||
|
||||
$container->setAlias('alias_factory', 'factory');
|
||||
|
||||
$foo = $container->register('foo');
|
||||
$foo->setFactory(array(new Reference('alias_factory'), 'create'));
|
||||
|
||||
$bar = $container->register('bar', __CLASS__);
|
||||
$bar->setFactory(array(new Reference('factory'), 'create'));
|
||||
|
||||
$pass = new FactoryReturnTypePass();
|
||||
$pass->process($container);
|
||||
|
||||
if (method_exists(\ReflectionMethod::class, 'getReturnType')) {
|
||||
$this->assertEquals(FactoryDummy::class, $factory->getClass());
|
||||
$this->assertEquals(\stdClass::class, $foo->getClass());
|
||||
} else {
|
||||
$this->assertNull($factory->getClass());
|
||||
$this->assertNull($foo->getClass());
|
||||
}
|
||||
$this->assertEquals(__CLASS__, $bar->getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider returnTypesProvider
|
||||
*/
|
||||
public function testReturnTypes($factory, $returnType, $hhvmSupport = true)
|
||||
{
|
||||
if (!$hhvmSupport && \defined('HHVM_VERSION')) {
|
||||
$this->markTestSkipped('Scalar typehints not supported by hhvm.');
|
||||
}
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$service = $container->register('service');
|
||||
$service->setFactory($factory);
|
||||
|
||||
$pass = new FactoryReturnTypePass();
|
||||
$pass->process($container);
|
||||
|
||||
if (method_exists(\ReflectionMethod::class, 'getReturnType')) {
|
||||
$this->assertEquals($returnType, $service->getClass());
|
||||
} else {
|
||||
$this->assertNull($service->getClass());
|
||||
}
|
||||
}
|
||||
|
||||
public function returnTypesProvider()
|
||||
{
|
||||
return array(
|
||||
// must be loaded before the function as they are in the same file
|
||||
array(array(FactoryDummy::class, 'createBuiltin'), null, false),
|
||||
array(array(FactoryDummy::class, 'createParent'), FactoryParent::class),
|
||||
array(array(FactoryDummy::class, 'createSelf'), FactoryDummy::class),
|
||||
array(factoryFunction::class, FactoryDummy::class),
|
||||
);
|
||||
}
|
||||
|
||||
public function testCircularReference()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$factory = $container->register('factory');
|
||||
$factory->setFactory(array(new Reference('factory2'), 'createSelf'));
|
||||
|
||||
$factory2 = $container->register('factory2');
|
||||
$factory2->setFactory(array(new Reference('factory'), 'create'));
|
||||
|
||||
$pass = new FactoryReturnTypePass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertNull($factory->getClass());
|
||||
$this->assertNull($factory2->getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires function ReflectionMethod::getReturnType
|
||||
* @expectedDeprecation Relying on its factory's return-type to define the class of service "factory" is deprecated since Symfony 3.3 and won't work in 4.0. Set the "class" attribute to "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy" on the service definition instead.
|
||||
*/
|
||||
public function testCompile()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$factory = $container->register('factory');
|
||||
$factory->setFactory(array(FactoryDummy::class, 'createFactory'));
|
||||
$container->compile();
|
||||
|
||||
$this->assertEquals(FactoryDummy::class, $container->getDefinition('factory')->getClass());
|
||||
}
|
||||
}
|
360
vendor/symfony/dependency-injection/Tests/Compiler/InlineServiceDefinitionsPassTest.php
vendored
Normal file
360
vendor/symfony/dependency-injection/Tests/Compiler/InlineServiceDefinitionsPassTest.php
vendored
Normal file
|
@ -0,0 +1,360 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\InlineServiceDefinitionsPass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\RepeatedPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class InlineServiceDefinitionsPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('inlinable.service')
|
||||
->setPublic(false)
|
||||
;
|
||||
|
||||
$container
|
||||
->register('service')
|
||||
->setArguments(array(new Reference('inlinable.service')))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$arguments = $container->getDefinition('service')->getArguments();
|
||||
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Definition', $arguments[0]);
|
||||
$this->assertSame($container->getDefinition('inlinable.service'), $arguments[0]);
|
||||
}
|
||||
|
||||
public function testProcessDoesNotInlinesWhenAliasedServiceIsShared()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('foo')
|
||||
->setPublic(false)
|
||||
;
|
||||
$container->setAlias('moo', 'foo');
|
||||
|
||||
$container
|
||||
->register('service')
|
||||
->setArguments(array($ref = new Reference('foo')))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$arguments = $container->getDefinition('service')->getArguments();
|
||||
$this->assertSame($ref, $arguments[0]);
|
||||
}
|
||||
|
||||
public function testProcessDoesInlineNonSharedService()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('foo')
|
||||
->setShared(false)
|
||||
;
|
||||
$container
|
||||
->register('bar')
|
||||
->setPublic(false)
|
||||
->setShared(false)
|
||||
;
|
||||
$container->setAlias('moo', 'bar');
|
||||
|
||||
$container
|
||||
->register('service')
|
||||
->setArguments(array(new Reference('foo'), $ref = new Reference('moo'), new Reference('bar')))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$arguments = $container->getDefinition('service')->getArguments();
|
||||
$this->assertEquals($container->getDefinition('foo'), $arguments[0]);
|
||||
$this->assertNotSame($container->getDefinition('foo'), $arguments[0]);
|
||||
$this->assertSame($ref, $arguments[1]);
|
||||
$this->assertEquals($container->getDefinition('bar'), $arguments[2]);
|
||||
$this->assertNotSame($container->getDefinition('bar'), $arguments[2]);
|
||||
}
|
||||
|
||||
public function testProcessDoesNotInlineMixedServicesLoop()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('foo')
|
||||
->addArgument(new Reference('bar'))
|
||||
->setShared(false)
|
||||
;
|
||||
$container
|
||||
->register('bar')
|
||||
->setPublic(false)
|
||||
->addMethodCall('setFoo', array(new Reference('foo')))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertEquals(new Reference('bar'), $container->getDefinition('foo')->getArgument(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||
* @expectedExceptionMessage Circular reference detected for service "bar", path: "bar -> foo -> bar".
|
||||
*/
|
||||
public function testProcessThrowsOnNonSharedLoops()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('foo')
|
||||
->addArgument(new Reference('bar'))
|
||||
->setShared(false)
|
||||
;
|
||||
$container
|
||||
->register('bar')
|
||||
->setShared(false)
|
||||
->addMethodCall('setFoo', array(new Reference('foo')))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
public function testProcessNestedNonSharedServices()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('foo')
|
||||
->addArgument(new Reference('bar1'))
|
||||
->addArgument(new Reference('bar2'))
|
||||
;
|
||||
$container
|
||||
->register('bar1')
|
||||
->setShared(false)
|
||||
->addArgument(new Reference('baz'))
|
||||
;
|
||||
$container
|
||||
->register('bar2')
|
||||
->setShared(false)
|
||||
->addArgument(new Reference('baz'))
|
||||
;
|
||||
$container
|
||||
->register('baz')
|
||||
->setShared(false)
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$baz1 = $container->getDefinition('foo')->getArgument(0)->getArgument(0);
|
||||
$baz2 = $container->getDefinition('foo')->getArgument(1)->getArgument(0);
|
||||
|
||||
$this->assertEquals($container->getDefinition('baz'), $baz1);
|
||||
$this->assertEquals($container->getDefinition('baz'), $baz2);
|
||||
$this->assertNotSame($baz1, $baz2);
|
||||
}
|
||||
|
||||
public function testProcessInlinesIfMultipleReferencesButAllFromTheSameDefinition()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$a = $container->register('a')->setPublic(false);
|
||||
$b = $container
|
||||
->register('b')
|
||||
->addArgument(new Reference('a'))
|
||||
->addArgument(new Definition(null, array(new Reference('a'))))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$arguments = $b->getArguments();
|
||||
$this->assertSame($a, $arguments[0]);
|
||||
|
||||
$inlinedArguments = $arguments[1]->getArguments();
|
||||
$this->assertSame($a, $inlinedArguments[0]);
|
||||
}
|
||||
|
||||
public function testProcessInlinesPrivateFactoryReference()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('a')->setPublic(false);
|
||||
$b = $container
|
||||
->register('b')
|
||||
->setPublic(false)
|
||||
->setFactory(array(new Reference('a'), 'a'))
|
||||
;
|
||||
|
||||
$container
|
||||
->register('foo')
|
||||
->setArguments(array(
|
||||
$ref = new Reference('b'),
|
||||
));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$inlinedArguments = $container->getDefinition('foo')->getArguments();
|
||||
$this->assertSame($b, $inlinedArguments[0]);
|
||||
}
|
||||
|
||||
public function testProcessDoesNotInlinePrivateFactoryIfReferencedMultipleTimesWithinTheSameDefinition()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('a')
|
||||
;
|
||||
$container
|
||||
->register('b')
|
||||
->setPublic(false)
|
||||
->setFactory(array(new Reference('a'), 'a'))
|
||||
;
|
||||
|
||||
$container
|
||||
->register('foo')
|
||||
->setArguments(array(
|
||||
$ref1 = new Reference('b'),
|
||||
$ref2 = new Reference('b'),
|
||||
))
|
||||
;
|
||||
$this->process($container);
|
||||
|
||||
$args = $container->getDefinition('foo')->getArguments();
|
||||
$this->assertSame($ref1, $args[0]);
|
||||
$this->assertSame($ref2, $args[1]);
|
||||
}
|
||||
|
||||
public function testProcessDoesNotInlineReferenceWhenUsedByInlineFactory()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('a')
|
||||
;
|
||||
$container
|
||||
->register('b')
|
||||
->setPublic(false)
|
||||
->setFactory(array(new Reference('a'), 'a'))
|
||||
;
|
||||
|
||||
$inlineFactory = new Definition();
|
||||
$inlineFactory->setPublic(false);
|
||||
$inlineFactory->setFactory(array(new Reference('b'), 'b'));
|
||||
|
||||
$container
|
||||
->register('foo')
|
||||
->setArguments(array(
|
||||
$ref = new Reference('b'),
|
||||
$inlineFactory,
|
||||
))
|
||||
;
|
||||
$this->process($container);
|
||||
|
||||
$args = $container->getDefinition('foo')->getArguments();
|
||||
$this->assertSame($ref, $args[0]);
|
||||
}
|
||||
|
||||
public function testProcessDoesNotInlineWhenServiceIsPrivateButLazy()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('foo')
|
||||
->setPublic(false)
|
||||
->setLazy(true)
|
||||
;
|
||||
|
||||
$container
|
||||
->register('service')
|
||||
->setArguments(array($ref = new Reference('foo')))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$arguments = $container->getDefinition('service')->getArguments();
|
||||
$this->assertSame($ref, $arguments[0]);
|
||||
}
|
||||
|
||||
public function testProcessDoesNotInlineWhenServiceReferencesItself()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('foo')
|
||||
->setPublic(false)
|
||||
->addMethodCall('foo', array($ref = new Reference('foo')))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$calls = $container->getDefinition('foo')->getMethodCalls();
|
||||
$this->assertSame($ref, $calls[0][1][0]);
|
||||
}
|
||||
|
||||
public function testProcessDoesNotSetLazyArgumentValuesAfterInlining()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('inline')
|
||||
->setShared(false)
|
||||
;
|
||||
$container
|
||||
->register('service-closure')
|
||||
->setArguments(array(new ServiceClosureArgument(new Reference('inline'))))
|
||||
;
|
||||
$container
|
||||
->register('iterator')
|
||||
->setArguments(array(new IteratorArgument(array(new Reference('inline')))))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$values = $container->getDefinition('service-closure')->getArgument(0)->getValues();
|
||||
$this->assertInstanceOf(Reference::class, $values[0]);
|
||||
$this->assertSame('inline', (string) $values[0]);
|
||||
|
||||
$values = $container->getDefinition('iterator')->getArgument(0)->getValues();
|
||||
$this->assertInstanceOf(Reference::class, $values[0]);
|
||||
$this->assertSame('inline', (string) $values[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testGetInlinedServiceIdData()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('inlinable.service')
|
||||
->setPublic(false)
|
||||
;
|
||||
$container
|
||||
->register('non_inlinable.service')
|
||||
->setPublic(true)
|
||||
;
|
||||
|
||||
$container
|
||||
->register('other_service')
|
||||
->setArguments(array(new Reference('inlinable.service')))
|
||||
;
|
||||
|
||||
$inlinePass = new InlineServiceDefinitionsPass();
|
||||
$repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), $inlinePass));
|
||||
$repeatedPass->process($container);
|
||||
|
||||
$this->assertEquals(array('inlinable.service' => array('other_service')), $inlinePass->getInlinedServiceIds());
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
$repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new InlineServiceDefinitionsPass()));
|
||||
$repeatedPass->process($container);
|
||||
}
|
||||
}
|
224
vendor/symfony/dependency-injection/Tests/Compiler/IntegrationTest.php
vendored
Normal file
224
vendor/symfony/dependency-injection/Tests/Compiler/IntegrationTest.php
vendored
Normal file
|
@ -0,0 +1,224 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* This class tests the integration of the different compiler passes.
|
||||
*/
|
||||
class IntegrationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* This tests that dependencies are correctly processed.
|
||||
*
|
||||
* We're checking that:
|
||||
*
|
||||
* * A is public, B/C are private
|
||||
* * A -> C
|
||||
* * B -> C
|
||||
*/
|
||||
public function testProcessRemovesAndInlinesRecursively()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setResourceTracking(false);
|
||||
|
||||
$a = $container
|
||||
->register('a', '\stdClass')
|
||||
->addArgument(new Reference('c'))
|
||||
;
|
||||
|
||||
$b = $container
|
||||
->register('b', '\stdClass')
|
||||
->addArgument(new Reference('c'))
|
||||
->setPublic(false)
|
||||
;
|
||||
|
||||
$c = $container
|
||||
->register('c', '\stdClass')
|
||||
->setPublic(false)
|
||||
;
|
||||
|
||||
$container->compile();
|
||||
|
||||
$this->assertTrue($container->hasDefinition('a'));
|
||||
$arguments = $a->getArguments();
|
||||
$this->assertSame($c, $arguments[0]);
|
||||
$this->assertFalse($container->hasDefinition('b'));
|
||||
$this->assertFalse($container->hasDefinition('c'));
|
||||
}
|
||||
|
||||
public function testProcessInlinesReferencesToAliases()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setResourceTracking(false);
|
||||
|
||||
$a = $container
|
||||
->register('a', '\stdClass')
|
||||
->addArgument(new Reference('b'))
|
||||
;
|
||||
|
||||
$container->setAlias('b', new Alias('c', false));
|
||||
|
||||
$c = $container
|
||||
->register('c', '\stdClass')
|
||||
->setPublic(false)
|
||||
;
|
||||
|
||||
$container->compile();
|
||||
|
||||
$this->assertTrue($container->hasDefinition('a'));
|
||||
$arguments = $a->getArguments();
|
||||
$this->assertSame($c, $arguments[0]);
|
||||
$this->assertFalse($container->hasAlias('b'));
|
||||
$this->assertFalse($container->hasDefinition('c'));
|
||||
}
|
||||
|
||||
public function testProcessInlinesWhenThereAreMultipleReferencesButFromTheSameDefinition()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setResourceTracking(false);
|
||||
|
||||
$container
|
||||
->register('a', '\stdClass')
|
||||
->addArgument(new Reference('b'))
|
||||
->addMethodCall('setC', array(new Reference('c')))
|
||||
;
|
||||
|
||||
$container
|
||||
->register('b', '\stdClass')
|
||||
->addArgument(new Reference('c'))
|
||||
->setPublic(false)
|
||||
;
|
||||
|
||||
$container
|
||||
->register('c', '\stdClass')
|
||||
->setPublic(false)
|
||||
;
|
||||
|
||||
$container->compile();
|
||||
|
||||
$this->assertTrue($container->hasDefinition('a'));
|
||||
$this->assertFalse($container->hasDefinition('b'));
|
||||
$this->assertFalse($container->hasDefinition('c'), 'Service C was not inlined.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getYamlCompileTests
|
||||
*/
|
||||
public function testYamlContainerCompiles($directory, $actualServiceId, $expectedServiceId, ContainerBuilder $mainContainer = null)
|
||||
{
|
||||
// allow a container to be passed in, which might have autoconfigure settings
|
||||
$container = $mainContainer ?: new ContainerBuilder();
|
||||
$container->setResourceTracking(false);
|
||||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Fixtures/yaml/integration/'.$directory));
|
||||
$loader->load('main.yml');
|
||||
$container->compile();
|
||||
$actualService = $container->getDefinition($actualServiceId);
|
||||
|
||||
// create a fresh ContainerBuilder, to avoid autoconfigure stuff
|
||||
$container = new ContainerBuilder();
|
||||
$container->setResourceTracking(false);
|
||||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Fixtures/yaml/integration/'.$directory));
|
||||
$loader->load('expected.yml');
|
||||
$container->compile();
|
||||
$expectedService = $container->getDefinition($expectedServiceId);
|
||||
|
||||
// reset changes, we don't care if these differ
|
||||
$actualService->setChanges(array());
|
||||
$expectedService->setChanges(array());
|
||||
|
||||
$this->assertEquals($expectedService, $actualService);
|
||||
}
|
||||
|
||||
public function getYamlCompileTests()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->registerForAutoconfiguration(IntegrationTestStub::class);
|
||||
yield array(
|
||||
'autoconfigure_child_not_applied',
|
||||
'child_service',
|
||||
'child_service_expected',
|
||||
$container,
|
||||
);
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->registerForAutoconfiguration(IntegrationTestStub::class);
|
||||
yield array(
|
||||
'autoconfigure_parent_child',
|
||||
'child_service',
|
||||
'child_service_expected',
|
||||
$container,
|
||||
);
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->registerForAutoconfiguration(IntegrationTestStub::class)
|
||||
->addTag('from_autoconfigure');
|
||||
yield array(
|
||||
'autoconfigure_parent_child_tags',
|
||||
'child_service',
|
||||
'child_service_expected',
|
||||
$container,
|
||||
);
|
||||
|
||||
yield array(
|
||||
'child_parent',
|
||||
'child_service',
|
||||
'child_service_expected',
|
||||
);
|
||||
|
||||
yield array(
|
||||
'defaults_child_tags',
|
||||
'child_service',
|
||||
'child_service_expected',
|
||||
);
|
||||
|
||||
yield array(
|
||||
'defaults_instanceof_importance',
|
||||
'main_service',
|
||||
'main_service_expected',
|
||||
);
|
||||
|
||||
yield array(
|
||||
'defaults_parent_child',
|
||||
'child_service',
|
||||
'child_service_expected',
|
||||
);
|
||||
|
||||
yield array(
|
||||
'instanceof_parent_child',
|
||||
'child_service',
|
||||
'child_service_expected',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class IntegrationTestStub extends IntegrationTestStubParent
|
||||
{
|
||||
}
|
||||
|
||||
class IntegrationTestStubParent
|
||||
{
|
||||
public function enableSummer($enable)
|
||||
{
|
||||
// methods used in calls - added here to prevent errors for not existing
|
||||
}
|
||||
|
||||
public function setSunshine($type)
|
||||
{
|
||||
}
|
||||
}
|
199
vendor/symfony/dependency-injection/Tests/Compiler/MergeExtensionConfigurationPassTest.php
vendored
Normal file
199
vendor/symfony/dependency-injection/Tests/Compiler/MergeExtensionConfigurationPassTest.php
vendored
Normal file
|
@ -0,0 +1,199 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
|
||||
class MergeExtensionConfigurationPassTest extends TestCase
|
||||
{
|
||||
public function testExpressionLanguageProviderForwarding()
|
||||
{
|
||||
$tmpProviders = array();
|
||||
|
||||
$extension = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface')->getMock();
|
||||
$extension->expects($this->any())
|
||||
->method('getXsdValidationBasePath')
|
||||
->will($this->returnValue(false));
|
||||
$extension->expects($this->any())
|
||||
->method('getNamespace')
|
||||
->will($this->returnValue('http://example.org/schema/dic/foo'));
|
||||
$extension->expects($this->any())
|
||||
->method('getAlias')
|
||||
->will($this->returnValue('foo'));
|
||||
$extension->expects($this->once())
|
||||
->method('load')
|
||||
->will($this->returnCallback(function (array $config, ContainerBuilder $container) use (&$tmpProviders) {
|
||||
$tmpProviders = $container->getExpressionLanguageProviders();
|
||||
}));
|
||||
|
||||
$provider = $this->getMockBuilder('Symfony\\Component\\ExpressionLanguage\\ExpressionFunctionProviderInterface')->getMock();
|
||||
$container = new ContainerBuilder(new ParameterBag());
|
||||
$container->registerExtension($extension);
|
||||
$container->prependExtensionConfig('foo', array('bar' => true));
|
||||
$container->addExpressionLanguageProvider($provider);
|
||||
|
||||
$pass = new MergeExtensionConfigurationPass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertEquals(array($provider), $tmpProviders);
|
||||
}
|
||||
|
||||
public function testExtensionLoadGetAMergeExtensionConfigurationContainerBuilderInstance()
|
||||
{
|
||||
$extension = $this->getMockBuilder(FooExtension::class)->setMethods(array('load'))->getMock();
|
||||
$extension->expects($this->once())
|
||||
->method('load')
|
||||
->with($this->isType('array'), $this->isInstanceOf(MergeExtensionConfigurationContainerBuilder::class))
|
||||
;
|
||||
|
||||
$container = new ContainerBuilder(new ParameterBag());
|
||||
$container->registerExtension($extension);
|
||||
$container->prependExtensionConfig('foo', array());
|
||||
|
||||
$pass = new MergeExtensionConfigurationPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testExtensionConfigurationIsTrackedByDefault()
|
||||
{
|
||||
$extension = $this->getMockBuilder(FooExtension::class)->setMethods(array('getConfiguration'))->getMock();
|
||||
$extension->expects($this->exactly(2))
|
||||
->method('getConfiguration')
|
||||
->will($this->returnValue(new FooConfiguration()));
|
||||
|
||||
$container = new ContainerBuilder(new ParameterBag());
|
||||
$container->registerExtension($extension);
|
||||
$container->prependExtensionConfig('foo', array('bar' => true));
|
||||
|
||||
$pass = new MergeExtensionConfigurationPass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertContains(new FileResource(__FILE__), $container->getResources(), '', false, false);
|
||||
}
|
||||
|
||||
public function testOverriddenEnvsAreMerged()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->registerExtension(new FooExtension());
|
||||
$container->prependExtensionConfig('foo', array('bar' => '%env(FOO)%'));
|
||||
$container->prependExtensionConfig('foo', array('bar' => '%env(BAR)%', 'baz' => '%env(BAZ)%'));
|
||||
|
||||
$pass = new MergeExtensionConfigurationPass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertSame(array('BAZ', 'FOO'), array_keys($container->getParameterBag()->getEnvPlaceholders()));
|
||||
$this->assertSame(array('BAZ' => 1, 'FOO' => 0), $container->getEnvCounters());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Using a cast in "env(int:FOO)" is incompatible with resolution at compile time in "Symfony\Component\DependencyInjection\Tests\Compiler\BarExtension". The logic in the extension should be moved to a compiler pass, or an env parameter with no cast should be used instead.
|
||||
*/
|
||||
public function testProcessedEnvsAreIncompatibleWithResolve()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->registerExtension(new BarExtension());
|
||||
$container->prependExtensionConfig('bar', array());
|
||||
|
||||
(new MergeExtensionConfigurationPass())->process($container);
|
||||
}
|
||||
|
||||
public function testThrowingExtensionsGetMergedBag()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->registerExtension(new ThrowingExtension());
|
||||
$container->prependExtensionConfig('throwing', array('bar' => '%env(FOO)%'));
|
||||
|
||||
try {
|
||||
$pass = new MergeExtensionConfigurationPass();
|
||||
$pass->process($container);
|
||||
$this->fail('An exception should have been thrown.');
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
|
||||
$this->assertSame(array('FOO'), array_keys($container->getParameterBag()->getEnvPlaceholders()));
|
||||
}
|
||||
}
|
||||
|
||||
class FooConfiguration implements ConfigurationInterface
|
||||
{
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$rootNode = $treeBuilder->root('foo');
|
||||
$rootNode
|
||||
->children()
|
||||
->scalarNode('bar')->end()
|
||||
->scalarNode('baz')->end()
|
||||
->end();
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
}
|
||||
|
||||
class FooExtension extends Extension
|
||||
{
|
||||
public function getAlias()
|
||||
{
|
||||
return 'foo';
|
||||
}
|
||||
|
||||
public function getConfiguration(array $config, ContainerBuilder $container)
|
||||
{
|
||||
return new FooConfiguration();
|
||||
}
|
||||
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$configuration = $this->getConfiguration($configs, $container);
|
||||
$config = $this->processConfiguration($configuration, $configs);
|
||||
|
||||
if (isset($config['baz'])) {
|
||||
$container->getParameterBag()->get('env(BOZ)');
|
||||
$container->resolveEnvPlaceholders($config['baz']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class BarExtension extends Extension
|
||||
{
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$container->resolveEnvPlaceholders('%env(int:FOO)%', true);
|
||||
}
|
||||
}
|
||||
|
||||
class ThrowingExtension extends Extension
|
||||
{
|
||||
public function getAlias()
|
||||
{
|
||||
return 'throwing';
|
||||
}
|
||||
|
||||
public function getConfiguration(array $config, ContainerBuilder $container)
|
||||
{
|
||||
return new FooConfiguration();
|
||||
}
|
||||
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
throw new \Exception();
|
||||
}
|
||||
}
|
18
vendor/symfony/dependency-injection/Tests/Compiler/OptionalServiceClass.php
vendored
Normal file
18
vendor/symfony/dependency-injection/Tests/Compiler/OptionalServiceClass.php
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use Symfony\Bug\NotExistClass;
|
||||
|
||||
class OptionalServiceClass extends NotExistClass
|
||||
{
|
||||
}
|
38
vendor/symfony/dependency-injection/Tests/Compiler/PassConfigTest.php
vendored
Normal file
38
vendor/symfony/dependency-injection/Tests/Compiler/PassConfigTest.php
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
|
||||
|
||||
/**
|
||||
* @author Guilhem N <egetick@gmail.com>
|
||||
*/
|
||||
class PassConfigTest extends TestCase
|
||||
{
|
||||
public function testPassOrdering()
|
||||
{
|
||||
$config = new PassConfig();
|
||||
$config->setBeforeOptimizationPasses(array());
|
||||
|
||||
$pass1 = $this->getMockBuilder(CompilerPassInterface::class)->getMock();
|
||||
$config->addPass($pass1, PassConfig::TYPE_BEFORE_OPTIMIZATION, 10);
|
||||
|
||||
$pass2 = $this->getMockBuilder(CompilerPassInterface::class)->getMock();
|
||||
$config->addPass($pass2, PassConfig::TYPE_BEFORE_OPTIMIZATION, 30);
|
||||
|
||||
$passes = $config->getBeforeOptimizationPasses();
|
||||
$this->assertSame($pass2, $passes[0]);
|
||||
$this->assertSame($pass1, $passes[1]);
|
||||
}
|
||||
}
|
91
vendor/symfony/dependency-injection/Tests/Compiler/PriorityTaggedServiceTraitTest.php
vendored
Normal file
91
vendor/symfony/dependency-injection/Tests/Compiler/PriorityTaggedServiceTraitTest.php
vendored
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class PriorityTaggedServiceTraitTest extends TestCase
|
||||
{
|
||||
public function testThatCacheWarmersAreProcessedInPriorityOrder()
|
||||
{
|
||||
$services = array(
|
||||
'my_service1' => array('my_custom_tag' => array('priority' => 100)),
|
||||
'my_service2' => array('my_custom_tag' => array('priority' => 200)),
|
||||
'my_service3' => array('my_custom_tag' => array('priority' => -501)),
|
||||
'my_service4' => array('my_custom_tag' => array()),
|
||||
'my_service5' => array('my_custom_tag' => array('priority' => -1)),
|
||||
'my_service6' => array('my_custom_tag' => array('priority' => -500)),
|
||||
'my_service7' => array('my_custom_tag' => array('priority' => -499)),
|
||||
'my_service8' => array('my_custom_tag' => array('priority' => 1)),
|
||||
'my_service9' => array('my_custom_tag' => array('priority' => -2)),
|
||||
'my_service10' => array('my_custom_tag' => array('priority' => -1000)),
|
||||
'my_service11' => array('my_custom_tag' => array('priority' => -1001)),
|
||||
'my_service12' => array('my_custom_tag' => array('priority' => -1002)),
|
||||
'my_service13' => array('my_custom_tag' => array('priority' => -1003)),
|
||||
'my_service14' => array('my_custom_tag' => array('priority' => -1000)),
|
||||
'my_service15' => array('my_custom_tag' => array('priority' => 1)),
|
||||
'my_service16' => array('my_custom_tag' => array('priority' => -1)),
|
||||
'my_service17' => array('my_custom_tag' => array('priority' => 200)),
|
||||
'my_service18' => array('my_custom_tag' => array('priority' => 100)),
|
||||
'my_service19' => array('my_custom_tag' => array()),
|
||||
);
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
foreach ($services as $id => $tags) {
|
||||
$definition = $container->register($id);
|
||||
|
||||
foreach ($tags as $name => $attributes) {
|
||||
$definition->addTag($name, $attributes);
|
||||
}
|
||||
}
|
||||
|
||||
$expected = array(
|
||||
new Reference('my_service2'),
|
||||
new Reference('my_service17'),
|
||||
new Reference('my_service1'),
|
||||
new Reference('my_service18'),
|
||||
new Reference('my_service8'),
|
||||
new Reference('my_service15'),
|
||||
new Reference('my_service4'),
|
||||
new Reference('my_service19'),
|
||||
new Reference('my_service5'),
|
||||
new Reference('my_service16'),
|
||||
new Reference('my_service9'),
|
||||
new Reference('my_service7'),
|
||||
new Reference('my_service6'),
|
||||
new Reference('my_service3'),
|
||||
new Reference('my_service10'),
|
||||
new Reference('my_service14'),
|
||||
new Reference('my_service11'),
|
||||
new Reference('my_service12'),
|
||||
new Reference('my_service13'),
|
||||
);
|
||||
|
||||
$priorityTaggedServiceTraitImplementation = new PriorityTaggedServiceTraitImplementation();
|
||||
|
||||
$this->assertEquals($expected, $priorityTaggedServiceTraitImplementation->test('my_custom_tag', $container));
|
||||
}
|
||||
}
|
||||
|
||||
class PriorityTaggedServiceTraitImplementation
|
||||
{
|
||||
use PriorityTaggedServiceTrait;
|
||||
|
||||
public function test($tagName, ContainerBuilder $container)
|
||||
{
|
||||
return $this->findAndSortTaggedServices($tagName, $container);
|
||||
}
|
||||
}
|
88
vendor/symfony/dependency-injection/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php
vendored
Normal file
88
vendor/symfony/dependency-injection/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php
vendored
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\RegisterEnvVarProcessorsPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\EnvVarProcessorInterface;
|
||||
|
||||
class RegisterEnvVarProcessorsPassTest extends TestCase
|
||||
{
|
||||
public function testSimpleProcessor()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('foo', SimpleProcessor::class)->addTag('container.env_var_processor');
|
||||
|
||||
(new RegisterEnvVarProcessorsPass())->process($container);
|
||||
|
||||
$this->assertTrue($container->has('container.env_var_processors_locator'));
|
||||
$this->assertInstanceOf(SimpleProcessor::class, $container->get('container.env_var_processors_locator')->get('foo'));
|
||||
|
||||
$expected = array(
|
||||
'foo' => array('string'),
|
||||
'base64' => array('string'),
|
||||
'bool' => array('bool'),
|
||||
'const' => array('bool', 'int', 'float', 'string', 'array'),
|
||||
'file' => array('string'),
|
||||
'float' => array('float'),
|
||||
'int' => array('int'),
|
||||
'json' => array('array'),
|
||||
'resolve' => array('string'),
|
||||
'string' => array('string'),
|
||||
);
|
||||
|
||||
$this->assertSame($expected, $container->getParameterBag()->getProvidedTypes());
|
||||
}
|
||||
|
||||
public function testNoProcessor()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
(new RegisterEnvVarProcessorsPass())->process($container);
|
||||
|
||||
$this->assertFalse($container->has('container.env_var_processors_locator'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Invalid type "foo" returned by "Symfony\Component\DependencyInjection\Tests\Compiler\BadProcessor::getProvidedTypes()", expected one of "array", "bool", "float", "int", "string".
|
||||
*/
|
||||
public function testBadProcessor()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('foo', BadProcessor::class)->addTag('container.env_var_processor');
|
||||
|
||||
(new RegisterEnvVarProcessorsPass())->process($container);
|
||||
}
|
||||
}
|
||||
|
||||
class SimpleProcessor implements EnvVarProcessorInterface
|
||||
{
|
||||
public function getEnv($prefix, $name, \Closure $getEnv)
|
||||
{
|
||||
return $getEnv($name);
|
||||
}
|
||||
|
||||
public static function getProvidedTypes()
|
||||
{
|
||||
return array('foo' => 'string');
|
||||
}
|
||||
}
|
||||
|
||||
class BadProcessor extends SimpleProcessor
|
||||
{
|
||||
public static function getProvidedTypes()
|
||||
{
|
||||
return array('foo' => 'string|foo');
|
||||
}
|
||||
}
|
139
vendor/symfony/dependency-injection/Tests/Compiler/RegisterServiceSubscribersPassTest.php
vendored
Normal file
139
vendor/symfony/dependency-injection/Tests/Compiler/RegisterServiceSubscribersPassTest.php
vendored
Normal file
|
@ -0,0 +1,139 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Container\ContainerInterface as PsrContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\Compiler\RegisterServiceSubscribersPass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveServiceSubscribersPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\ServiceLocator;
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition;
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber;
|
||||
use Symfony\Component\DependencyInjection\TypedReference;
|
||||
|
||||
require_once __DIR__.'/../Fixtures/includes/classes.php';
|
||||
|
||||
class RegisterServiceSubscribersPassTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Service "foo" must implement interface "Symfony\Component\DependencyInjection\ServiceSubscriberInterface".
|
||||
*/
|
||||
public function testInvalidClass()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('foo', CustomDefinition::class)
|
||||
->addTag('container.service_subscriber')
|
||||
;
|
||||
|
||||
(new RegisterServiceSubscribersPass())->process($container);
|
||||
(new ResolveServiceSubscribersPass())->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage The "container.service_subscriber" tag accepts only the "key" and "id" attributes, "bar" given for service "foo".
|
||||
*/
|
||||
public function testInvalidAttributes()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('foo', TestServiceSubscriber::class)
|
||||
->addTag('container.service_subscriber', array('bar' => '123'))
|
||||
;
|
||||
|
||||
(new RegisterServiceSubscribersPass())->process($container);
|
||||
(new ResolveServiceSubscribersPass())->process($container);
|
||||
}
|
||||
|
||||
public function testNoAttributes()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('foo', TestServiceSubscriber::class)
|
||||
->addArgument(new Reference(PsrContainerInterface::class))
|
||||
->addTag('container.service_subscriber')
|
||||
;
|
||||
|
||||
(new RegisterServiceSubscribersPass())->process($container);
|
||||
(new ResolveServiceSubscribersPass())->process($container);
|
||||
|
||||
$foo = $container->getDefinition('foo');
|
||||
$locator = $container->getDefinition((string) $foo->getArgument(0));
|
||||
|
||||
$this->assertFalse($locator->isPublic());
|
||||
$this->assertSame(ServiceLocator::class, $locator->getClass());
|
||||
|
||||
$expected = array(
|
||||
TestServiceSubscriber::class => new ServiceClosureArgument(new TypedReference(TestServiceSubscriber::class, TestServiceSubscriber::class, TestServiceSubscriber::class)),
|
||||
CustomDefinition::class => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, TestServiceSubscriber::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
|
||||
'bar' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, TestServiceSubscriber::class)),
|
||||
'baz' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, TestServiceSubscriber::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));
|
||||
}
|
||||
|
||||
public function testWithAttributes()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('foo', TestServiceSubscriber::class)
|
||||
->setAutowired(true)
|
||||
->addArgument(new Reference(PsrContainerInterface::class))
|
||||
->addTag('container.service_subscriber', array('key' => 'bar', 'id' => 'bar'))
|
||||
->addTag('container.service_subscriber', array('key' => 'bar', 'id' => 'baz')) // should be ignored: the first wins
|
||||
;
|
||||
|
||||
(new RegisterServiceSubscribersPass())->process($container);
|
||||
(new ResolveServiceSubscribersPass())->process($container);
|
||||
|
||||
$foo = $container->getDefinition('foo');
|
||||
$locator = $container->getDefinition((string) $foo->getArgument(0));
|
||||
|
||||
$this->assertFalse($locator->isPublic());
|
||||
$this->assertSame(ServiceLocator::class, $locator->getClass());
|
||||
|
||||
$expected = array(
|
||||
TestServiceSubscriber::class => new ServiceClosureArgument(new TypedReference(TestServiceSubscriber::class, TestServiceSubscriber::class, TestServiceSubscriber::class)),
|
||||
CustomDefinition::class => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, TestServiceSubscriber::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
|
||||
'bar' => new ServiceClosureArgument(new TypedReference('bar', CustomDefinition::class, TestServiceSubscriber::class)),
|
||||
'baz' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, TestServiceSubscriber::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Service key "test" does not exist in the map returned by "Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber::getSubscribedServices()" for service "foo_service".
|
||||
*/
|
||||
public function testExtraServiceSubscriber()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('foo_service', TestServiceSubscriber::class)
|
||||
->setAutowired(true)
|
||||
->addArgument(new Reference(PsrContainerInterface::class))
|
||||
->addTag('container.service_subscriber', array(
|
||||
'key' => 'test',
|
||||
'id' => TestServiceSubscriber::class,
|
||||
))
|
||||
;
|
||||
$container->register(TestServiceSubscriber::class, TestServiceSubscriber::class);
|
||||
$container->compile();
|
||||
}
|
||||
}
|
137
vendor/symfony/dependency-injection/Tests/Compiler/RemoveUnusedDefinitionsPassTest.php
vendored
Normal file
137
vendor/symfony/dependency-injection/Tests/Compiler/RemoveUnusedDefinitionsPassTest.php
vendored
Normal file
|
@ -0,0 +1,137 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\RemoveUnusedDefinitionsPass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\RepeatedPass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class RemoveUnusedDefinitionsPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('foo')
|
||||
->setPublic(false)
|
||||
;
|
||||
$container
|
||||
->register('bar')
|
||||
->setPublic(false)
|
||||
;
|
||||
$container
|
||||
->register('moo')
|
||||
->setArguments(array(new Reference('bar')))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertFalse($container->hasDefinition('foo'));
|
||||
$this->assertTrue($container->hasDefinition('bar'));
|
||||
$this->assertTrue($container->hasDefinition('moo'));
|
||||
}
|
||||
|
||||
public function testProcessRemovesUnusedDefinitionsRecursively()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('foo')
|
||||
->setPublic(false)
|
||||
;
|
||||
$container
|
||||
->register('bar')
|
||||
->setArguments(array(new Reference('foo')))
|
||||
->setPublic(false)
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertFalse($container->hasDefinition('foo'));
|
||||
$this->assertFalse($container->hasDefinition('bar'));
|
||||
}
|
||||
|
||||
public function testProcessWorksWithInlinedDefinitions()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('foo')
|
||||
->setPublic(false)
|
||||
;
|
||||
$container
|
||||
->register('bar')
|
||||
->setArguments(array(new Definition(null, array(new Reference('foo')))))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertTrue($container->hasDefinition('foo'));
|
||||
$this->assertTrue($container->hasDefinition('bar'));
|
||||
}
|
||||
|
||||
public function testProcessWontRemovePrivateFactory()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('foo', 'stdClass')
|
||||
->setFactory(array('stdClass', 'getInstance'))
|
||||
->setPublic(false);
|
||||
|
||||
$container
|
||||
->register('bar', 'stdClass')
|
||||
->setFactory(array(new Reference('foo'), 'getInstance'))
|
||||
->setPublic(false);
|
||||
|
||||
$container
|
||||
->register('foobar')
|
||||
->addArgument(new Reference('bar'));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertTrue($container->hasDefinition('foo'));
|
||||
$this->assertTrue($container->hasDefinition('bar'));
|
||||
$this->assertTrue($container->hasDefinition('foobar'));
|
||||
}
|
||||
|
||||
public function testProcessConsiderEnvVariablesAsUsedEvenInPrivateServices()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setParameter('env(FOOBAR)', 'test');
|
||||
$container
|
||||
->register('foo')
|
||||
->setArguments(array('%env(FOOBAR)%'))
|
||||
->setPublic(false)
|
||||
;
|
||||
|
||||
$resolvePass = new ResolveParameterPlaceHoldersPass();
|
||||
$resolvePass->process($container);
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertFalse($container->hasDefinition('foo'));
|
||||
|
||||
$envCounters = $container->getEnvCounters();
|
||||
$this->assertArrayHasKey('FOOBAR', $envCounters);
|
||||
$this->assertSame(1, $envCounters['FOOBAR']);
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
$repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new RemoveUnusedDefinitionsPass()));
|
||||
$repeatedPass->process($container);
|
||||
}
|
||||
}
|
71
vendor/symfony/dependency-injection/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php
vendored
Normal file
71
vendor/symfony/dependency-injection/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ReplaceAliasByActualDefinitionPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
require_once __DIR__.'/../Fixtures/includes/foo.php';
|
||||
|
||||
class ReplaceAliasByActualDefinitionPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$aDefinition = $container->register('a', '\stdClass');
|
||||
$aDefinition->setFactory(array(new Reference('b'), 'createA'));
|
||||
|
||||
$bDefinition = new Definition('\stdClass');
|
||||
$bDefinition->setPublic(false);
|
||||
$container->setDefinition('b', $bDefinition);
|
||||
|
||||
$container->setAlias('a_alias', 'a');
|
||||
$container->setAlias('b_alias', 'b');
|
||||
|
||||
$container->setAlias('container', 'service_container');
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertTrue($container->has('a'), '->process() does nothing to public definitions.');
|
||||
$this->assertTrue($container->hasAlias('a_alias'));
|
||||
$this->assertFalse($container->has('b'), '->process() removes non-public definitions.');
|
||||
$this->assertTrue(
|
||||
$container->has('b_alias') && !$container->hasAlias('b_alias'),
|
||||
'->process() replaces alias to actual.'
|
||||
);
|
||||
|
||||
$this->assertTrue($container->has('container'));
|
||||
|
||||
$resolvedFactory = $aDefinition->getFactory();
|
||||
$this->assertSame('b_alias', (string) $resolvedFactory[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testProcessWithInvalidAlias()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setAlias('a_alias', 'a');
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
$pass = new ReplaceAliasByActualDefinitionPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
}
|
114
vendor/symfony/dependency-injection/Tests/Compiler/ResolveBindingsPassTest.php
vendored
Normal file
114
vendor/symfony/dependency-injection/Tests/Compiler/ResolveBindingsPassTest.php
vendored
Normal file
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
|
||||
use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists;
|
||||
use Symfony\Component\DependencyInjection\TypedReference;
|
||||
|
||||
require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
|
||||
|
||||
class ResolveBindingsPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$bindings = array(CaseSensitiveClass::class => new BoundArgument(new Reference('foo')));
|
||||
|
||||
$definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class);
|
||||
$definition->setArguments(array(1 => '123'));
|
||||
$definition->addMethodCall('setSensitiveClass');
|
||||
$definition->setBindings($bindings);
|
||||
|
||||
$container->register('foo', CaseSensitiveClass::class)
|
||||
->setBindings($bindings);
|
||||
|
||||
$pass = new ResolveBindingsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertEquals(array(new Reference('foo'), '123'), $definition->getArguments());
|
||||
$this->assertEquals(array(array('setSensitiveClass', array(new Reference('foo')))), $definition->getMethodCalls());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Unused binding "$quz" in service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy".
|
||||
*/
|
||||
public function testUnusedBinding()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class);
|
||||
$definition->setBindings(array('$quz' => '123'));
|
||||
|
||||
$pass = new ResolveBindingsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessageRegexp Unused binding "$quz" in service [\s\S]+ Invalid service ".*\\ParentNotExists": class NotExists not found\.
|
||||
*/
|
||||
public function testMissingParent()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definition = $container->register(ParentNotExists::class, ParentNotExists::class);
|
||||
$definition->setBindings(array('$quz' => '123'));
|
||||
|
||||
$pass = new ResolveBindingsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testTypedReferenceSupport()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$bindings = array(CaseSensitiveClass::class => new BoundArgument(new Reference('foo')));
|
||||
|
||||
// Explicit service id
|
||||
$definition1 = $container->register('def1', NamedArgumentsDummy::class);
|
||||
$definition1->addArgument($typedRef = new TypedReference('bar', CaseSensitiveClass::class));
|
||||
$definition1->setBindings($bindings);
|
||||
|
||||
$definition2 = $container->register('def2', NamedArgumentsDummy::class);
|
||||
$definition2->addArgument(new TypedReference(CaseSensitiveClass::class, CaseSensitiveClass::class));
|
||||
$definition2->setBindings($bindings);
|
||||
|
||||
$pass = new ResolveBindingsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertEquals(array($typedRef), $container->getDefinition('def1')->getArguments());
|
||||
$this->assertEquals(array(new Reference('foo')), $container->getDefinition('def2')->getArguments());
|
||||
}
|
||||
|
||||
public function testScalarSetter()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definition = $container->autowire('foo', ScalarSetter::class);
|
||||
$definition->setBindings(array('$defaultLocale' => 'fr'));
|
||||
|
||||
(new AutowireRequiredMethodsPass())->process($container);
|
||||
(new ResolveBindingsPass())->process($container);
|
||||
|
||||
$this->assertEquals(array(array('setDefaultLocale', array('fr'))), $definition->getMethodCalls());
|
||||
}
|
||||
}
|
451
vendor/symfony/dependency-injection/Tests/Compiler/ResolveChildDefinitionsPassTest.php
vendored
Normal file
451
vendor/symfony/dependency-injection/Tests/Compiler/ResolveChildDefinitionsPassTest.php
vendored
Normal file
|
@ -0,0 +1,451 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
class ResolveChildDefinitionsPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('parent', 'foo')->setArguments(array('moo', 'b'))->setProperty('foo', 'moo');
|
||||
$container->setDefinition('child', new ChildDefinition('parent'))
|
||||
->replaceArgument(0, 'a')
|
||||
->setProperty('foo', 'bar')
|
||||
->setClass('bar')
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertNotInstanceOf(ChildDefinition::class, $def);
|
||||
$this->assertEquals('bar', $def->getClass());
|
||||
$this->assertEquals(array('a', 'b'), $def->getArguments());
|
||||
$this->assertEquals(array('foo' => 'bar'), $def->getProperties());
|
||||
}
|
||||
|
||||
public function testProcessAppendsMethodCallsAlways()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('parent')
|
||||
->addMethodCall('foo', array('bar'))
|
||||
;
|
||||
|
||||
$container
|
||||
->setDefinition('child', new ChildDefinition('parent'))
|
||||
->addMethodCall('bar', array('foo'))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertEquals(array(
|
||||
array('foo', array('bar')),
|
||||
array('bar', array('foo')),
|
||||
), $def->getMethodCalls());
|
||||
}
|
||||
|
||||
public function testProcessDoesNotCopyAbstract()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('parent')
|
||||
->setAbstract(true)
|
||||
;
|
||||
|
||||
$container
|
||||
->setDefinition('child', new ChildDefinition('parent'))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertFalse($def->isAbstract());
|
||||
}
|
||||
|
||||
public function testProcessDoesNotCopyShared()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('parent')
|
||||
->setShared(false)
|
||||
;
|
||||
|
||||
$container
|
||||
->setDefinition('child', new ChildDefinition('parent'))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertTrue($def->isShared());
|
||||
}
|
||||
|
||||
public function testProcessDoesNotCopyTags()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('parent')
|
||||
->addTag('foo')
|
||||
;
|
||||
|
||||
$container
|
||||
->setDefinition('child', new ChildDefinition('parent'))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertEquals(array(), $def->getTags());
|
||||
}
|
||||
|
||||
public function testProcessDoesNotCopyDecoratedService()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('parent')
|
||||
->setDecoratedService('foo')
|
||||
;
|
||||
|
||||
$container
|
||||
->setDefinition('child', new ChildDefinition('parent'))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertNull($def->getDecoratedService());
|
||||
}
|
||||
|
||||
public function testProcessDoesNotDropShared()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('parent')
|
||||
;
|
||||
|
||||
$container
|
||||
->setDefinition('child', new ChildDefinition('parent'))
|
||||
->setShared(false)
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertFalse($def->isShared());
|
||||
}
|
||||
|
||||
public function testProcessHandlesMultipleInheritance()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('parent', 'foo')
|
||||
->setArguments(array('foo', 'bar', 'c'))
|
||||
;
|
||||
|
||||
$container
|
||||
->setDefinition('child2', new ChildDefinition('child1'))
|
||||
->replaceArgument(1, 'b')
|
||||
;
|
||||
|
||||
$container
|
||||
->setDefinition('child1', new ChildDefinition('parent'))
|
||||
->replaceArgument(0, 'a')
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child2');
|
||||
$this->assertEquals(array('a', 'b', 'c'), $def->getArguments());
|
||||
$this->assertEquals('foo', $def->getClass());
|
||||
}
|
||||
|
||||
public function testSetLazyOnServiceHasParent()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'stdClass');
|
||||
|
||||
$container->setDefinition('child1', new ChildDefinition('parent'))
|
||||
->setLazy(true)
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertTrue($container->getDefinition('child1')->isLazy());
|
||||
}
|
||||
|
||||
public function testSetLazyOnServiceIsParent()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'stdClass')
|
||||
->setLazy(true)
|
||||
;
|
||||
|
||||
$container->setDefinition('child1', new ChildDefinition('parent'));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertTrue($container->getDefinition('child1')->isLazy());
|
||||
}
|
||||
|
||||
public function testSetAutowiredOnServiceHasParent()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'stdClass')
|
||||
->setAutowired(true)
|
||||
;
|
||||
|
||||
$container->setDefinition('child1', new ChildDefinition('parent'))
|
||||
->setAutowired(false)
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertFalse($container->getDefinition('child1')->isAutowired());
|
||||
}
|
||||
|
||||
public function testSetAutowiredOnServiceIsParent()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'stdClass')
|
||||
->setAutowired(true)
|
||||
;
|
||||
|
||||
$container->setDefinition('child1', new ChildDefinition('parent'));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertTrue($container->getDefinition('child1')->isAutowired());
|
||||
}
|
||||
|
||||
public function testDeepDefinitionsResolving()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'parentClass');
|
||||
$container->register('sibling', 'siblingClass')
|
||||
->setConfigurator(new ChildDefinition('parent'), 'foo')
|
||||
->setFactory(array(new ChildDefinition('parent'), 'foo'))
|
||||
->addArgument(new ChildDefinition('parent'))
|
||||
->setProperty('prop', new ChildDefinition('parent'))
|
||||
->addMethodCall('meth', array(new ChildDefinition('parent')))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$configurator = $container->getDefinition('sibling')->getConfigurator();
|
||||
$this->assertSame('Symfony\Component\DependencyInjection\Definition', \get_class($configurator));
|
||||
$this->assertSame('parentClass', $configurator->getClass());
|
||||
|
||||
$factory = $container->getDefinition('sibling')->getFactory();
|
||||
$this->assertSame('Symfony\Component\DependencyInjection\Definition', \get_class($factory[0]));
|
||||
$this->assertSame('parentClass', $factory[0]->getClass());
|
||||
|
||||
$argument = $container->getDefinition('sibling')->getArgument(0);
|
||||
$this->assertSame('Symfony\Component\DependencyInjection\Definition', \get_class($argument));
|
||||
$this->assertSame('parentClass', $argument->getClass());
|
||||
|
||||
$properties = $container->getDefinition('sibling')->getProperties();
|
||||
$this->assertSame('Symfony\Component\DependencyInjection\Definition', \get_class($properties['prop']));
|
||||
$this->assertSame('parentClass', $properties['prop']->getClass());
|
||||
|
||||
$methodCalls = $container->getDefinition('sibling')->getMethodCalls();
|
||||
$this->assertSame('Symfony\Component\DependencyInjection\Definition', \get_class($methodCalls[0][1][0]));
|
||||
$this->assertSame('parentClass', $methodCalls[0][1][0]->getClass());
|
||||
}
|
||||
|
||||
public function testSetDecoratedServiceOnServiceHasParent()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'stdClass');
|
||||
|
||||
$container->setDefinition('child1', new ChildDefinition('parent'))
|
||||
->setDecoratedService('foo', 'foo_inner', 5)
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertEquals(array('foo', 'foo_inner', 5), $container->getDefinition('child1')->getDecoratedService());
|
||||
}
|
||||
|
||||
public function testDecoratedServiceCopiesDeprecatedStatusFromParent()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('deprecated_parent')
|
||||
->setDeprecated(true)
|
||||
;
|
||||
|
||||
$container->setDefinition('decorated_deprecated_parent', new ChildDefinition('deprecated_parent'));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertTrue($container->getDefinition('decorated_deprecated_parent')->isDeprecated());
|
||||
}
|
||||
|
||||
public function testDecoratedServiceCanOverwriteDeprecatedParentStatus()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('deprecated_parent')
|
||||
->setDeprecated(true)
|
||||
;
|
||||
|
||||
$container->setDefinition('decorated_deprecated_parent', new ChildDefinition('deprecated_parent'))
|
||||
->setDeprecated(false)
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertFalse($container->getDefinition('decorated_deprecated_parent')->isDeprecated());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testProcessMergeAutowiringTypes()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('parent')
|
||||
->addAutowiringType('Foo')
|
||||
;
|
||||
|
||||
$container
|
||||
->setDefinition('child', new ChildDefinition('parent'))
|
||||
->addAutowiringType('Bar')
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$childDef = $container->getDefinition('child');
|
||||
$this->assertEquals(array('Foo', 'Bar'), $childDef->getAutowiringTypes());
|
||||
|
||||
$parentDef = $container->getDefinition('parent');
|
||||
$this->assertSame(array('Foo'), $parentDef->getAutowiringTypes());
|
||||
}
|
||||
|
||||
public function testProcessResolvesAliases()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'ParentClass');
|
||||
$container->setAlias('parent_alias', 'parent');
|
||||
$container->setDefinition('child', new ChildDefinition('parent_alias'));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertSame('ParentClass', $def->getClass());
|
||||
}
|
||||
|
||||
public function testProcessSetsArguments()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'ParentClass')->setArguments(array(0));
|
||||
$container->setDefinition('child', (new ChildDefinition('parent'))->setArguments(array(
|
||||
1,
|
||||
'index_0' => 2,
|
||||
'foo' => 3,
|
||||
)));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertSame(array(2, 1, 'foo' => 3), $def->getArguments());
|
||||
}
|
||||
|
||||
public function testBindings()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'stdClass')
|
||||
->setBindings(array('a' => '1', 'b' => '2'))
|
||||
;
|
||||
|
||||
$child = $container->setDefinition('child', new ChildDefinition('parent'))
|
||||
->setBindings(array('b' => 'B', 'c' => 'C'))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$bindings = array();
|
||||
foreach ($container->getDefinition('child')->getBindings() as $k => $v) {
|
||||
$bindings[$k] = $v->getValues()[0];
|
||||
}
|
||||
$this->assertEquals(array('b' => 'B', 'c' => 'C', 'a' => '1'), $bindings);
|
||||
}
|
||||
|
||||
public function testSetAutoconfiguredOnServiceIsParent()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'stdClass')
|
||||
->setAutoconfigured(true)
|
||||
;
|
||||
|
||||
$container->setDefinition('child1', new ChildDefinition('parent'));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertFalse($container->getDefinition('child1')->isAutoconfigured());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testAliasExistsForBackwardsCompatibility()
|
||||
{
|
||||
$this->assertInstanceOf(ResolveChildDefinitionsPass::class, new ResolveDefinitionTemplatesPass());
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
$pass = new ResolveChildDefinitionsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||
* @expectedExceptionMessageRegExp /^Circular reference detected for service "c", path: "c -> b -> a -> c"./
|
||||
*/
|
||||
public function testProcessDetectsChildDefinitionIndirectCircularReference()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('a');
|
||||
|
||||
$container->setDefinition('b', new ChildDefinition('a'));
|
||||
$container->setDefinition('c', new ChildDefinition('b'));
|
||||
$container->setDefinition('a', new ChildDefinition('c'));
|
||||
|
||||
$this->process($container);
|
||||
}
|
||||
}
|
97
vendor/symfony/dependency-injection/Tests/Compiler/ResolveClassPassTest.php
vendored
Normal file
97
vendor/symfony/dependency-injection/Tests/Compiler/ResolveClassPassTest.php
vendored
Normal file
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveClassPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
|
||||
|
||||
class ResolveClassPassTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideValidClassId
|
||||
*/
|
||||
public function testResolveClassFromId($serviceId)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$def = $container->register($serviceId);
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
|
||||
$this->assertSame($serviceId, $def->getClass());
|
||||
}
|
||||
|
||||
public function provideValidClassId()
|
||||
{
|
||||
yield array('Acme\UnknownClass');
|
||||
yield array(CaseSensitiveClass::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInvalidClassId
|
||||
*/
|
||||
public function testWontResolveClassFromId($serviceId)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$def = $container->register($serviceId);
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
|
||||
$this->assertNull($def->getClass());
|
||||
}
|
||||
|
||||
public function provideInvalidClassId()
|
||||
{
|
||||
yield array(\stdClass::class);
|
||||
yield array('bar');
|
||||
yield array('\DateTime');
|
||||
}
|
||||
|
||||
public function testNonFqcnChildDefinition()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$parent = $container->register('App\Foo', null);
|
||||
$child = $container->setDefinition('App\Foo.child', new ChildDefinition('App\Foo'));
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
|
||||
$this->assertSame('App\Foo', $parent->getClass());
|
||||
$this->assertNull($child->getClass());
|
||||
}
|
||||
|
||||
public function testClassFoundChildDefinition()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$parent = $container->register('App\Foo', null);
|
||||
$child = $container->setDefinition(self::class, new ChildDefinition('App\Foo'));
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
|
||||
$this->assertSame('App\Foo', $parent->getClass());
|
||||
$this->assertSame(self::class, $child->getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Service definition "App\Foo\Child" has a parent but no class, and its name looks like a FQCN. Either the class is missing or you want to inherit it from the parent service. To resolve this ambiguity, please rename this service to a non-FQCN (e.g. using dots), or create the missing class.
|
||||
*/
|
||||
public function testAmbiguousChildDefinition()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$parent = $container->register('App\Foo', null);
|
||||
$child = $container->setDefinition('App\Foo\Child', new ChildDefinition('App\Foo'));
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
}
|
||||
}
|
407
vendor/symfony/dependency-injection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php
vendored
Normal file
407
vendor/symfony/dependency-injection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php
vendored
Normal file
|
@ -0,0 +1,407 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ResolveDefinitionTemplatesPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('parent', 'foo')->setArguments(array('moo', 'b'))->setProperty('foo', 'moo');
|
||||
$container->setDefinition('child', new ChildDefinition('parent'))
|
||||
->replaceArgument(0, 'a')
|
||||
->setProperty('foo', 'bar')
|
||||
->setClass('bar')
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertNotInstanceOf(ChildDefinition::class, $def);
|
||||
$this->assertEquals('bar', $def->getClass());
|
||||
$this->assertEquals(array('a', 'b'), $def->getArguments());
|
||||
$this->assertEquals(array('foo' => 'bar'), $def->getProperties());
|
||||
}
|
||||
|
||||
public function testProcessAppendsMethodCallsAlways()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('parent')
|
||||
->addMethodCall('foo', array('bar'))
|
||||
;
|
||||
|
||||
$container
|
||||
->setDefinition('child', new ChildDefinition('parent'))
|
||||
->addMethodCall('bar', array('foo'))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertEquals(array(
|
||||
array('foo', array('bar')),
|
||||
array('bar', array('foo')),
|
||||
), $def->getMethodCalls());
|
||||
}
|
||||
|
||||
public function testProcessDoesNotCopyAbstract()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('parent')
|
||||
->setAbstract(true)
|
||||
;
|
||||
|
||||
$container
|
||||
->setDefinition('child', new ChildDefinition('parent'))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertFalse($def->isAbstract());
|
||||
}
|
||||
|
||||
public function testProcessDoesNotCopyShared()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('parent')
|
||||
->setShared(false)
|
||||
;
|
||||
|
||||
$container
|
||||
->setDefinition('child', new ChildDefinition('parent'))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertTrue($def->isShared());
|
||||
}
|
||||
|
||||
public function testProcessDoesNotCopyTags()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('parent')
|
||||
->addTag('foo')
|
||||
;
|
||||
|
||||
$container
|
||||
->setDefinition('child', new ChildDefinition('parent'))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertEquals(array(), $def->getTags());
|
||||
}
|
||||
|
||||
public function testProcessDoesNotCopyDecoratedService()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('parent')
|
||||
->setDecoratedService('foo')
|
||||
;
|
||||
|
||||
$container
|
||||
->setDefinition('child', new ChildDefinition('parent'))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertNull($def->getDecoratedService());
|
||||
}
|
||||
|
||||
public function testProcessDoesNotDropShared()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('parent')
|
||||
;
|
||||
|
||||
$container
|
||||
->setDefinition('child', new ChildDefinition('parent'))
|
||||
->setShared(false)
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertFalse($def->isShared());
|
||||
}
|
||||
|
||||
public function testProcessHandlesMultipleInheritance()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('parent', 'foo')
|
||||
->setArguments(array('foo', 'bar', 'c'))
|
||||
;
|
||||
|
||||
$container
|
||||
->setDefinition('child2', new ChildDefinition('child1'))
|
||||
->replaceArgument(1, 'b')
|
||||
;
|
||||
|
||||
$container
|
||||
->setDefinition('child1', new ChildDefinition('parent'))
|
||||
->replaceArgument(0, 'a')
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child2');
|
||||
$this->assertEquals(array('a', 'b', 'c'), $def->getArguments());
|
||||
$this->assertEquals('foo', $def->getClass());
|
||||
}
|
||||
|
||||
public function testSetLazyOnServiceHasParent()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'stdClass');
|
||||
|
||||
$container->setDefinition('child1', new ChildDefinition('parent'))
|
||||
->setLazy(true)
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertTrue($container->getDefinition('child1')->isLazy());
|
||||
}
|
||||
|
||||
public function testSetLazyOnServiceIsParent()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'stdClass')
|
||||
->setLazy(true)
|
||||
;
|
||||
|
||||
$container->setDefinition('child1', new ChildDefinition('parent'));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertTrue($container->getDefinition('child1')->isLazy());
|
||||
}
|
||||
|
||||
public function testSetAutowiredOnServiceHasParent()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'stdClass')
|
||||
->setAutowired(true)
|
||||
;
|
||||
|
||||
$container->setDefinition('child1', new ChildDefinition('parent'))
|
||||
->setAutowired(false)
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertFalse($container->getDefinition('child1')->isAutowired());
|
||||
}
|
||||
|
||||
public function testSetAutowiredOnServiceIsParent()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'stdClass')
|
||||
->setAutowired(true)
|
||||
;
|
||||
|
||||
$container->setDefinition('child1', new ChildDefinition('parent'));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertTrue($container->getDefinition('child1')->isAutowired());
|
||||
}
|
||||
|
||||
public function testDeepDefinitionsResolving()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'parentClass');
|
||||
$container->register('sibling', 'siblingClass')
|
||||
->setConfigurator(new ChildDefinition('parent'), 'foo')
|
||||
->setFactory(array(new ChildDefinition('parent'), 'foo'))
|
||||
->addArgument(new ChildDefinition('parent'))
|
||||
->setProperty('prop', new ChildDefinition('parent'))
|
||||
->addMethodCall('meth', array(new ChildDefinition('parent')))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$configurator = $container->getDefinition('sibling')->getConfigurator();
|
||||
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Definition', $configurator);
|
||||
$this->assertSame('parentClass', $configurator->getClass());
|
||||
|
||||
$factory = $container->getDefinition('sibling')->getFactory();
|
||||
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Definition', $factory[0]);
|
||||
$this->assertSame('parentClass', $factory[0]->getClass());
|
||||
|
||||
$argument = $container->getDefinition('sibling')->getArgument(0);
|
||||
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Definition', $argument);
|
||||
$this->assertSame('parentClass', $argument->getClass());
|
||||
|
||||
$properties = $container->getDefinition('sibling')->getProperties();
|
||||
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Definition', $properties['prop']);
|
||||
$this->assertSame('parentClass', $properties['prop']->getClass());
|
||||
|
||||
$methodCalls = $container->getDefinition('sibling')->getMethodCalls();
|
||||
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Definition', $methodCalls[0][1][0]);
|
||||
$this->assertSame('parentClass', $methodCalls[0][1][0]->getClass());
|
||||
}
|
||||
|
||||
public function testSetDecoratedServiceOnServiceHasParent()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'stdClass');
|
||||
|
||||
$container->setDefinition('child1', new ChildDefinition('parent'))
|
||||
->setDecoratedService('foo', 'foo_inner', 5)
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertEquals(array('foo', 'foo_inner', 5), $container->getDefinition('child1')->getDecoratedService());
|
||||
}
|
||||
|
||||
public function testDecoratedServiceCopiesDeprecatedStatusFromParent()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('deprecated_parent')
|
||||
->setDeprecated(true)
|
||||
;
|
||||
|
||||
$container->setDefinition('decorated_deprecated_parent', new ChildDefinition('deprecated_parent'));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertTrue($container->getDefinition('decorated_deprecated_parent')->isDeprecated());
|
||||
}
|
||||
|
||||
public function testDecoratedServiceCanOverwriteDeprecatedParentStatus()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('deprecated_parent')
|
||||
->setDeprecated(true)
|
||||
;
|
||||
|
||||
$container->setDefinition('decorated_deprecated_parent', new ChildDefinition('deprecated_parent'))
|
||||
->setDeprecated(false)
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertFalse($container->getDefinition('decorated_deprecated_parent')->isDeprecated());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testProcessMergeAutowiringTypes()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('parent')
|
||||
->addAutowiringType('Foo')
|
||||
;
|
||||
|
||||
$container
|
||||
->setDefinition('child', new ChildDefinition('parent'))
|
||||
->addAutowiringType('Bar')
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$childDef = $container->getDefinition('child');
|
||||
$this->assertEquals(array('Foo', 'Bar'), $childDef->getAutowiringTypes());
|
||||
|
||||
$parentDef = $container->getDefinition('parent');
|
||||
$this->assertSame(array('Foo'), $parentDef->getAutowiringTypes());
|
||||
}
|
||||
|
||||
public function testProcessResolvesAliases()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'ParentClass');
|
||||
$container->setAlias('parent_alias', 'parent');
|
||||
$container->setDefinition('child', new ChildDefinition('parent_alias'));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertSame('ParentClass', $def->getClass());
|
||||
}
|
||||
|
||||
public function testProcessSetsArguments()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'ParentClass')->setArguments(array(0));
|
||||
$container->setDefinition('child', (new ChildDefinition('parent'))->setArguments(array(
|
||||
1,
|
||||
'index_0' => 2,
|
||||
'foo' => 3,
|
||||
)));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertSame(array(2, 1, 'foo' => 3), $def->getArguments());
|
||||
}
|
||||
|
||||
public function testSetAutoconfiguredOnServiceIsParent()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'stdClass')
|
||||
->setAutoconfigured(true)
|
||||
;
|
||||
|
||||
$container->setDefinition('child1', new ChildDefinition('parent'));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertFalse($container->getDefinition('child1')->isAutoconfigured());
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
$pass = new ResolveDefinitionTemplatesPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
}
|
88
vendor/symfony/dependency-injection/Tests/Compiler/ResolveFactoryClassPassTest.php
vendored
Normal file
88
vendor/symfony/dependency-injection/Tests/Compiler/ResolveFactoryClassPassTest.php
vendored
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveFactoryClassPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class ResolveFactoryClassPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$factory = $container->register('factory', 'Foo\Bar');
|
||||
$factory->setFactory(array(null, 'create'));
|
||||
|
||||
$pass = new ResolveFactoryClassPass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertSame(array('Foo\Bar', 'create'), $factory->getFactory());
|
||||
}
|
||||
|
||||
public function testInlinedDefinitionFactoryIsProcessed()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$factory = $container->register('factory');
|
||||
$factory->setFactory(array((new Definition('Baz\Qux'))->setFactory(array(null, 'getInstance')), 'create'));
|
||||
|
||||
$pass = new ResolveFactoryClassPass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertSame(array('Baz\Qux', 'getInstance'), $factory->getFactory()[0]->getFactory());
|
||||
}
|
||||
|
||||
public function provideFulfilledFactories()
|
||||
{
|
||||
return array(
|
||||
array(array('Foo\Bar', 'create')),
|
||||
array(array(new Reference('foo'), 'create')),
|
||||
array(array(new Definition('Baz'), 'create')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideFulfilledFactories
|
||||
*/
|
||||
public function testIgnoresFulfilledFactories($factory)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$definition = new Definition();
|
||||
$definition->setFactory($factory);
|
||||
|
||||
$container->setDefinition('factory', $definition);
|
||||
|
||||
$pass = new ResolveFactoryClassPass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertSame($factory, $container->getDefinition('factory')->getFactory());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessage The "factory" service is defined to be created by a factory, but is missing the factory class. Did you forget to define the factory or service class?
|
||||
*/
|
||||
public function testNotAnyClassThrowsException()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$factory = $container->register('factory');
|
||||
$factory->setFactory(array(null, 'create'));
|
||||
|
||||
$pass = new ResolveFactoryClassPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
}
|
57
vendor/symfony/dependency-injection/Tests/Compiler/ResolveHotPathPassTest.php
vendored
Normal file
57
vendor/symfony/dependency-injection/Tests/Compiler/ResolveHotPathPassTest.php
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveHotPathPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class ResolveHotPathPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('foo')
|
||||
->addTag('container.hot_path')
|
||||
->addArgument(new IteratorArgument(array(new Reference('lazy'))))
|
||||
->addArgument(new Reference('service_container'))
|
||||
->addArgument(new Definition('', array(new Reference('bar'))))
|
||||
->addArgument(new Reference('baz', ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE))
|
||||
->addArgument(new Reference('missing'))
|
||||
;
|
||||
|
||||
$container->register('lazy');
|
||||
$container->register('bar')
|
||||
->addArgument(new Reference('buz'))
|
||||
->addArgument(new Reference('deprec_ref_notag'));
|
||||
$container->register('baz')
|
||||
->addArgument(new Reference('lazy'))
|
||||
->addArgument(new Reference('lazy'));
|
||||
$container->register('buz');
|
||||
$container->register('deprec_with_tag')->setDeprecated()->addTag('container.hot_path');
|
||||
$container->register('deprec_ref_notag')->setDeprecated();
|
||||
|
||||
(new ResolveHotPathPass())->process($container);
|
||||
|
||||
$this->assertFalse($container->getDefinition('lazy')->hasTag('container.hot_path'));
|
||||
$this->assertTrue($container->getDefinition('bar')->hasTag('container.hot_path'));
|
||||
$this->assertTrue($container->getDefinition('buz')->hasTag('container.hot_path'));
|
||||
$this->assertFalse($container->getDefinition('baz')->hasTag('container.hot_path'));
|
||||
$this->assertFalse($container->getDefinition('service_container')->hasTag('container.hot_path'));
|
||||
$this->assertFalse($container->getDefinition('deprec_with_tag')->hasTag('container.hot_path'));
|
||||
$this->assertFalse($container->getDefinition('deprec_ref_notag')->hasTag('container.hot_path'));
|
||||
}
|
||||
}
|
268
vendor/symfony/dependency-injection/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php
vendored
Normal file
268
vendor/symfony/dependency-injection/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php
vendored
Normal file
|
@ -0,0 +1,268 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
class ResolveInstanceofConditionalsPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$def = $container->register('foo', self::class)->addTag('tag')->setAutowired(true)->setChanges(array());
|
||||
$def->setInstanceofConditionals(array(
|
||||
parent::class => (new ChildDefinition(''))->setProperty('foo', 'bar')->addTag('baz', array('attr' => 123)),
|
||||
));
|
||||
|
||||
(new ResolveInstanceofConditionalsPass())->process($container);
|
||||
|
||||
$parent = 'instanceof.'.parent::class.'.0.foo';
|
||||
$def = $container->getDefinition('foo');
|
||||
$this->assertEmpty($def->getInstanceofConditionals());
|
||||
$this->assertInstanceOf(ChildDefinition::class, $def);
|
||||
$this->assertTrue($def->isAutowired());
|
||||
$this->assertSame($parent, $def->getParent());
|
||||
$this->assertSame(array('tag' => array(array()), 'baz' => array(array('attr' => 123))), $def->getTags());
|
||||
|
||||
$parent = $container->getDefinition($parent);
|
||||
$this->assertSame(array('foo' => 'bar'), $parent->getProperties());
|
||||
$this->assertSame(array(), $parent->getTags());
|
||||
}
|
||||
|
||||
public function testProcessInheritance()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$def = $container
|
||||
->register('parent', parent::class)
|
||||
->addMethodCall('foo', array('foo'));
|
||||
$def->setInstanceofConditionals(array(
|
||||
parent::class => (new ChildDefinition(''))->addMethodCall('foo', array('bar')),
|
||||
));
|
||||
|
||||
$def = (new ChildDefinition('parent'))->setClass(self::class);
|
||||
$container->setDefinition('child', $def);
|
||||
|
||||
(new ResolveInstanceofConditionalsPass())->process($container);
|
||||
(new ResolveChildDefinitionsPass())->process($container);
|
||||
|
||||
$expected = array(
|
||||
array('foo', array('bar')),
|
||||
array('foo', array('foo')),
|
||||
);
|
||||
|
||||
$this->assertSame($expected, $container->getDefinition('parent')->getMethodCalls());
|
||||
$this->assertSame($expected, $container->getDefinition('child')->getMethodCalls());
|
||||
}
|
||||
|
||||
public function testProcessDoesReplaceShared()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$def = $container->register('foo', 'stdClass');
|
||||
$def->setInstanceofConditionals(array(
|
||||
'stdClass' => (new ChildDefinition(''))->setShared(false),
|
||||
));
|
||||
|
||||
(new ResolveInstanceofConditionalsPass())->process($container);
|
||||
|
||||
$def = $container->getDefinition('foo');
|
||||
$this->assertFalse($def->isShared());
|
||||
}
|
||||
|
||||
public function testProcessHandlesMultipleInheritance()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$def = $container->register('foo', self::class)->setShared(true);
|
||||
|
||||
$def->setInstanceofConditionals(array(
|
||||
parent::class => (new ChildDefinition(''))->setLazy(true)->setShared(false),
|
||||
self::class => (new ChildDefinition(''))->setAutowired(true),
|
||||
));
|
||||
|
||||
(new ResolveInstanceofConditionalsPass())->process($container);
|
||||
(new ResolveChildDefinitionsPass())->process($container);
|
||||
|
||||
$def = $container->getDefinition('foo');
|
||||
$this->assertTrue($def->isAutowired());
|
||||
$this->assertTrue($def->isLazy());
|
||||
$this->assertTrue($def->isShared());
|
||||
}
|
||||
|
||||
public function testProcessUsesAutoconfiguredInstanceof()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$def = $container->register('normal_service', self::class);
|
||||
$def->setInstanceofConditionals(array(
|
||||
parent::class => (new ChildDefinition(''))
|
||||
->addTag('local_instanceof_tag')
|
||||
->setFactory('locally_set_factory'),
|
||||
));
|
||||
$def->setAutoconfigured(true);
|
||||
$container->registerForAutoconfiguration(parent::class)
|
||||
->addTag('autoconfigured_tag')
|
||||
->setAutowired(true)
|
||||
->setFactory('autoconfigured_factory');
|
||||
|
||||
(new ResolveInstanceofConditionalsPass())->process($container);
|
||||
(new ResolveChildDefinitionsPass())->process($container);
|
||||
|
||||
$def = $container->getDefinition('normal_service');
|
||||
// autowired thanks to the autoconfigured instanceof
|
||||
$this->assertTrue($def->isAutowired());
|
||||
// factory from the specific instanceof overrides global one
|
||||
$this->assertEquals('locally_set_factory', $def->getFactory());
|
||||
// tags are merged, the locally set one is first
|
||||
$this->assertSame(array('local_instanceof_tag' => array(array()), 'autoconfigured_tag' => array(array())), $def->getTags());
|
||||
}
|
||||
|
||||
public function testAutoconfigureInstanceofDoesNotDuplicateTags()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$def = $container->register('normal_service', self::class);
|
||||
$def
|
||||
->addTag('duplicated_tag')
|
||||
->addTag('duplicated_tag', array('and_attributes' => 1))
|
||||
;
|
||||
$def->setInstanceofConditionals(array(
|
||||
parent::class => (new ChildDefinition(''))->addTag('duplicated_tag'),
|
||||
));
|
||||
$def->setAutoconfigured(true);
|
||||
$container->registerForAutoconfiguration(parent::class)
|
||||
->addTag('duplicated_tag', array('and_attributes' => 1))
|
||||
;
|
||||
|
||||
(new ResolveInstanceofConditionalsPass())->process($container);
|
||||
(new ResolveChildDefinitionsPass())->process($container);
|
||||
|
||||
$def = $container->getDefinition('normal_service');
|
||||
$this->assertSame(array('duplicated_tag' => array(array(), array('and_attributes' => 1))), $def->getTags());
|
||||
}
|
||||
|
||||
public function testProcessDoesNotUseAutoconfiguredInstanceofIfNotEnabled()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$def = $container->register('normal_service', self::class);
|
||||
$def->setInstanceofConditionals(array(
|
||||
parent::class => (new ChildDefinition(''))
|
||||
->addTag('foo_tag'),
|
||||
));
|
||||
$container->registerForAutoconfiguration(parent::class)
|
||||
->setAutowired(true);
|
||||
|
||||
(new ResolveInstanceofConditionalsPass())->process($container);
|
||||
(new ResolveChildDefinitionsPass())->process($container);
|
||||
|
||||
$def = $container->getDefinition('normal_service');
|
||||
$this->assertFalse($def->isAutowired());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessage "App\FakeInterface" is set as an "instanceof" conditional, but it does not exist.
|
||||
*/
|
||||
public function testBadInterfaceThrowsException()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$def = $container->register('normal_service', self::class);
|
||||
$def->setInstanceofConditionals(array(
|
||||
'App\\FakeInterface' => (new ChildDefinition(''))
|
||||
->addTag('foo_tag'),
|
||||
));
|
||||
|
||||
(new ResolveInstanceofConditionalsPass())->process($container);
|
||||
}
|
||||
|
||||
public function testBadInterfaceForAutomaticInstanceofIsOk()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('normal_service', self::class)
|
||||
->setAutoconfigured(true);
|
||||
$container->registerForAutoconfiguration('App\\FakeInterface')
|
||||
->setAutowired(true);
|
||||
|
||||
(new ResolveInstanceofConditionalsPass())->process($container);
|
||||
$this->assertTrue($container->hasDefinition('normal_service'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Autoconfigured instanceof for type "PHPUnit\Framework\TestCase" defines method calls but these are not supported and should be removed.
|
||||
*/
|
||||
public function testProcessThrowsExceptionForAutoconfiguredCalls()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->registerForAutoconfiguration(parent::class)
|
||||
->addMethodCall('setFoo');
|
||||
|
||||
(new ResolveInstanceofConditionalsPass())->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Autoconfigured instanceof for type "PHPUnit\Framework\TestCase" defines arguments but these are not supported and should be removed.
|
||||
*/
|
||||
public function testProcessThrowsExceptionForArguments()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->registerForAutoconfiguration(parent::class)
|
||||
->addArgument('bar');
|
||||
|
||||
(new ResolveInstanceofConditionalsPass())->process($container);
|
||||
}
|
||||
|
||||
public function testMergeReset()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('bar', self::class)
|
||||
->addArgument('a')
|
||||
->addMethodCall('setB')
|
||||
->setDecoratedService('foo')
|
||||
->addTag('t')
|
||||
->setInstanceofConditionals(array(
|
||||
parent::class => (new ChildDefinition(''))->addTag('bar'),
|
||||
))
|
||||
;
|
||||
|
||||
(new ResolveInstanceofConditionalsPass())->process($container);
|
||||
|
||||
$abstract = $container->getDefinition('abstract.instanceof.bar');
|
||||
|
||||
$this->assertEmpty($abstract->getArguments());
|
||||
$this->assertEmpty($abstract->getMethodCalls());
|
||||
$this->assertNull($abstract->getDecoratedService());
|
||||
$this->assertEmpty($abstract->getTags());
|
||||
$this->assertTrue($abstract->isAbstract());
|
||||
}
|
||||
|
||||
public function testBindings()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$def = $container->register('foo', self::class)->setBindings(array('$toto' => 123));
|
||||
$def->setInstanceofConditionals(array(parent::class => new ChildDefinition('')));
|
||||
|
||||
(new ResolveInstanceofConditionalsPass())->process($container);
|
||||
|
||||
$bindings = $container->getDefinition('foo')->getBindings();
|
||||
$this->assertSame(array('$toto'), array_keys($bindings));
|
||||
$this->assertInstanceOf(BoundArgument::class, $bindings['$toto']);
|
||||
$this->assertSame(123, $bindings['$toto']->getValues()[0]);
|
||||
}
|
||||
}
|
135
vendor/symfony/dependency-injection/Tests/Compiler/ResolveInvalidReferencesPassTest.php
vendored
Normal file
135
vendor/symfony/dependency-injection/Tests/Compiler/ResolveInvalidReferencesPassTest.php
vendored
Normal file
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveInvalidReferencesPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class ResolveInvalidReferencesPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$def = $container
|
||||
->register('foo')
|
||||
->setArguments(array(
|
||||
new Reference('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE),
|
||||
new Reference('baz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
|
||||
))
|
||||
->addMethodCall('foo', array(new Reference('moo', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$arguments = $def->getArguments();
|
||||
$this->assertSame(array(null, null), $arguments);
|
||||
$this->assertCount(0, $def->getMethodCalls());
|
||||
}
|
||||
|
||||
public function testProcessIgnoreInvalidArgumentInCollectionArgument()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('baz');
|
||||
$def = $container
|
||||
->register('foo')
|
||||
->setArguments(array(
|
||||
array(
|
||||
new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
|
||||
$baz = new Reference('baz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
|
||||
new Reference('moo', ContainerInterface::NULL_ON_INVALID_REFERENCE),
|
||||
),
|
||||
))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$arguments = $def->getArguments();
|
||||
$this->assertSame(array($baz, null), $arguments[0]);
|
||||
}
|
||||
|
||||
public function testProcessKeepMethodCallOnInvalidArgumentInCollectionArgument()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('baz');
|
||||
$def = $container
|
||||
->register('foo')
|
||||
->addMethodCall('foo', array(
|
||||
array(
|
||||
new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
|
||||
$baz = new Reference('baz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
|
||||
new Reference('moo', ContainerInterface::NULL_ON_INVALID_REFERENCE),
|
||||
),
|
||||
))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$calls = $def->getMethodCalls();
|
||||
$this->assertCount(1, $def->getMethodCalls());
|
||||
$this->assertSame(array($baz, null), $calls[0][1][0]);
|
||||
}
|
||||
|
||||
public function testProcessIgnoreNonExistentServices()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$def = $container
|
||||
->register('foo')
|
||||
->setArguments(array(new Reference('bar')))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$arguments = $def->getArguments();
|
||||
$this->assertEquals('bar', (string) $arguments[0]);
|
||||
}
|
||||
|
||||
public function testProcessRemovesPropertiesOnInvalid()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$def = $container
|
||||
->register('foo')
|
||||
->setProperty('foo', new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertEquals(array(), $def->getProperties());
|
||||
}
|
||||
|
||||
public function testProcessRemovesArgumentsOnInvalid()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$def = $container
|
||||
->register('foo')
|
||||
->addArgument(array(
|
||||
array(
|
||||
new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
|
||||
new ServiceClosureArgument(new Reference('baz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
|
||||
),
|
||||
))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertSame(array(array(array())), $def->getArguments());
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
$pass = new ResolveInvalidReferencesPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
}
|
162
vendor/symfony/dependency-injection/Tests/Compiler/ResolveNamedArgumentsPassTest.php
vendored
Normal file
162
vendor/symfony/dependency-injection/Tests/Compiler/ResolveNamedArgumentsPassTest.php
vendored
Normal file
|
@ -0,0 +1,162 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveNamedArgumentsPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy;
|
||||
|
||||
/**
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class ResolveNamedArgumentsPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class);
|
||||
$definition->setArguments(array(
|
||||
2 => 'http://api.example.com',
|
||||
'$apiKey' => '123',
|
||||
0 => new Reference('foo'),
|
||||
));
|
||||
$definition->addMethodCall('setApiKey', array('$apiKey' => '123'));
|
||||
|
||||
$pass = new ResolveNamedArgumentsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertEquals(array(0 => new Reference('foo'), 1 => '123', 2 => 'http://api.example.com'), $definition->getArguments());
|
||||
$this->assertEquals(array(array('setApiKey', array('123'))), $definition->getMethodCalls());
|
||||
}
|
||||
|
||||
public function testWithFactory()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('factory', NoConstructor::class);
|
||||
$definition = $container->register('foo', NoConstructor::class)
|
||||
->setFactory(array(new Reference('factory'), 'create'))
|
||||
->setArguments(array('$apiKey' => '123'));
|
||||
|
||||
$pass = new ResolveNamedArgumentsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertSame(array(0 => '123'), $definition->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
*/
|
||||
public function testClassNull()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definition = $container->register(NamedArgumentsDummy::class);
|
||||
$definition->setArguments(array('$apiKey' => '123'));
|
||||
|
||||
$pass = new ResolveNamedArgumentsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
*/
|
||||
public function testClassNotExist()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definition = $container->register(NotExist::class, NotExist::class);
|
||||
$definition->setArguments(array('$apiKey' => '123'));
|
||||
|
||||
$pass = new ResolveNamedArgumentsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
*/
|
||||
public function testClassNoConstructor()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definition = $container->register(NoConstructor::class, NoConstructor::class);
|
||||
$definition->setArguments(array('$apiKey' => '123'));
|
||||
|
||||
$pass = new ResolveNamedArgumentsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function testArgumentNotFound()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class);
|
||||
$definition->setArguments(array('$notFound' => '123'));
|
||||
|
||||
$pass = new ResolveNamedArgumentsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testTypedArgument()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class);
|
||||
$definition->setArguments(array('$apiKey' => '123', CaseSensitiveClass::class => new Reference('foo')));
|
||||
|
||||
$pass = new ResolveNamedArgumentsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertEquals(array(new Reference('foo'), '123'), $definition->getArguments());
|
||||
}
|
||||
|
||||
public function testResolvesMultipleArgumentsOfTheSameType()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definition = $container->register(SimilarArgumentsDummy::class, SimilarArgumentsDummy::class);
|
||||
$definition->setArguments(array(CaseSensitiveClass::class => new Reference('foo'), '$token' => 'qwerty'));
|
||||
|
||||
$pass = new ResolveNamedArgumentsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertEquals(array(new Reference('foo'), 'qwerty', new Reference('foo')), $definition->getArguments());
|
||||
}
|
||||
|
||||
public function testResolvePrioritizeNamedOverType()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definition = $container->register(SimilarArgumentsDummy::class, SimilarArgumentsDummy::class);
|
||||
$definition->setArguments(array(CaseSensitiveClass::class => new Reference('foo'), '$token' => 'qwerty', '$class1' => new Reference('bar')));
|
||||
|
||||
$pass = new ResolveNamedArgumentsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertEquals(array(new Reference('bar'), 'qwerty', new Reference('foo')), $definition->getArguments());
|
||||
}
|
||||
}
|
||||
|
||||
class NoConstructor
|
||||
{
|
||||
public static function create($apiKey)
|
||||
{
|
||||
}
|
||||
}
|
100
vendor/symfony/dependency-injection/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php
vendored
Normal file
100
vendor/symfony/dependency-injection/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php
vendored
Normal file
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
class ResolveParameterPlaceHoldersPassTest extends TestCase
|
||||
{
|
||||
private $compilerPass;
|
||||
private $container;
|
||||
private $fooDefinition;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->compilerPass = new ResolveParameterPlaceHoldersPass();
|
||||
$this->container = $this->createContainerBuilder();
|
||||
$this->compilerPass->process($this->container);
|
||||
$this->fooDefinition = $this->container->getDefinition('foo');
|
||||
}
|
||||
|
||||
public function testClassParametersShouldBeResolved()
|
||||
{
|
||||
$this->assertSame('Foo', $this->fooDefinition->getClass());
|
||||
}
|
||||
|
||||
public function testFactoryParametersShouldBeResolved()
|
||||
{
|
||||
$this->assertSame(array('FooFactory', 'getFoo'), $this->fooDefinition->getFactory());
|
||||
}
|
||||
|
||||
public function testArgumentParametersShouldBeResolved()
|
||||
{
|
||||
$this->assertSame(array('bar', array('bar' => 'baz')), $this->fooDefinition->getArguments());
|
||||
}
|
||||
|
||||
public function testMethodCallParametersShouldBeResolved()
|
||||
{
|
||||
$this->assertSame(array(array('foobar', array('bar', array('bar' => 'baz')))), $this->fooDefinition->getMethodCalls());
|
||||
}
|
||||
|
||||
public function testPropertyParametersShouldBeResolved()
|
||||
{
|
||||
$this->assertSame(array('bar' => 'baz'), $this->fooDefinition->getProperties());
|
||||
}
|
||||
|
||||
public function testFileParametersShouldBeResolved()
|
||||
{
|
||||
$this->assertSame('foo.php', $this->fooDefinition->getFile());
|
||||
}
|
||||
|
||||
public function testAliasParametersShouldBeResolved()
|
||||
{
|
||||
$this->assertSame('foo', $this->container->getAlias('bar')->__toString());
|
||||
}
|
||||
|
||||
public function testBindingsShouldBeResolved()
|
||||
{
|
||||
list($boundValue) = $this->container->getDefinition('foo')->getBindings()['$baz']->getValues();
|
||||
|
||||
$this->assertSame($this->container->getParameterBag()->resolveValue('%env(BAZ)%'), $boundValue);
|
||||
}
|
||||
|
||||
private function createContainerBuilder()
|
||||
{
|
||||
$containerBuilder = new ContainerBuilder();
|
||||
|
||||
$containerBuilder->setParameter('foo.class', 'Foo');
|
||||
$containerBuilder->setParameter('foo.factory.class', 'FooFactory');
|
||||
$containerBuilder->setParameter('foo.arg1', 'bar');
|
||||
$containerBuilder->setParameter('foo.arg2', array('%foo.arg1%' => 'baz'));
|
||||
$containerBuilder->setParameter('foo.method', 'foobar');
|
||||
$containerBuilder->setParameter('foo.property.name', 'bar');
|
||||
$containerBuilder->setParameter('foo.property.value', 'baz');
|
||||
$containerBuilder->setParameter('foo.file', 'foo.php');
|
||||
$containerBuilder->setParameter('alias.id', 'bar');
|
||||
|
||||
$fooDefinition = $containerBuilder->register('foo', '%foo.class%');
|
||||
$fooDefinition->setFactory(array('%foo.factory.class%', 'getFoo'));
|
||||
$fooDefinition->setArguments(array('%foo.arg1%', array('%foo.arg1%' => 'baz')));
|
||||
$fooDefinition->addMethodCall('%foo.method%', array('%foo.arg1%', '%foo.arg2%'));
|
||||
$fooDefinition->setProperty('%foo.property.name%', '%foo.property.value%');
|
||||
$fooDefinition->setFile('%foo.file%');
|
||||
$fooDefinition->setBindings(array('$baz' => '%env(BAZ)%'));
|
||||
|
||||
$containerBuilder->setAlias('%alias.id%', 'foo');
|
||||
|
||||
return $containerBuilder;
|
||||
}
|
||||
}
|
39
vendor/symfony/dependency-injection/Tests/Compiler/ResolvePrivatesPassTest.php
vendored
Normal file
39
vendor/symfony/dependency-injection/Tests/Compiler/ResolvePrivatesPassTest.php
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolvePrivatesPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
class ResolvePrivatesPassTest extends TestCase
|
||||
{
|
||||
public function testPrivateHasHigherPrecedenceThanPublic()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('foo', 'stdClass')
|
||||
->setPublic(true)
|
||||
->setPrivate(true)
|
||||
;
|
||||
|
||||
$container->setAlias('bar', 'foo')
|
||||
->setPublic(false)
|
||||
->setPrivate(false)
|
||||
;
|
||||
|
||||
(new ResolvePrivatesPass())->process($container);
|
||||
|
||||
$this->assertFalse($container->getDefinition('foo')->isPublic());
|
||||
$this->assertFalse($container->getAlias('bar')->isPublic());
|
||||
}
|
||||
}
|
91
vendor/symfony/dependency-injection/Tests/Compiler/ResolveReferencesToAliasesPassTest.php
vendored
Normal file
91
vendor/symfony/dependency-injection/Tests/Compiler/ResolveReferencesToAliasesPassTest.php
vendored
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveReferencesToAliasesPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class ResolveReferencesToAliasesPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setAlias('bar', 'foo');
|
||||
$def = $container
|
||||
->register('moo')
|
||||
->setArguments(array(new Reference('bar')))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$arguments = $def->getArguments();
|
||||
$this->assertEquals('foo', (string) $arguments[0]);
|
||||
}
|
||||
|
||||
public function testProcessRecursively()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setAlias('bar', 'foo');
|
||||
$container->setAlias('moo', 'bar');
|
||||
$def = $container
|
||||
->register('foobar')
|
||||
->setArguments(array(new Reference('moo')))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$arguments = $def->getArguments();
|
||||
$this->assertEquals('foo', (string) $arguments[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||
*/
|
||||
public function testAliasCircularReference()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setAlias('bar', 'foo');
|
||||
$container->setAlias('foo', 'bar');
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
public function testResolveFactory()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('factory', 'Factory');
|
||||
$container->setAlias('factory_alias', new Alias('factory'));
|
||||
$foo = new Definition();
|
||||
$foo->setFactory(array(new Reference('factory_alias'), 'createFoo'));
|
||||
$container->setDefinition('foo', $foo);
|
||||
$bar = new Definition();
|
||||
$bar->setFactory(array('Factory', 'createFoo'));
|
||||
$container->setDefinition('bar', $bar);
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$resolvedFooFactory = $container->getDefinition('foo')->getFactory();
|
||||
$resolvedBarFactory = $container->getDefinition('bar')->getFactory();
|
||||
|
||||
$this->assertSame('factory', (string) $resolvedFooFactory[0]);
|
||||
$this->assertSame('Factory', (string) $resolvedBarFactory[0]);
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
$pass = new ResolveReferencesToAliasesPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
}
|
40
vendor/symfony/dependency-injection/Tests/Compiler/ResolveTaggedIteratorArgumentPassTest.php
vendored
Normal file
40
vendor/symfony/dependency-injection/Tests/Compiler/ResolveTaggedIteratorArgumentPassTest.php
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveTaggedIteratorArgumentPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* @author Roland Franssen <franssen.roland@gmail.com>
|
||||
*/
|
||||
class ResolveTaggedIteratorArgumentPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('a', 'stdClass')->addTag('foo');
|
||||
$container->register('b', 'stdClass')->addTag('foo', array('priority' => 20));
|
||||
$container->register('c', 'stdClass')->addTag('foo', array('priority' => 10));
|
||||
$container->register('d', 'stdClass')->setProperty('foos', new TaggedIteratorArgument('foo'));
|
||||
|
||||
(new ResolveTaggedIteratorArgumentPass())->process($container);
|
||||
|
||||
$properties = $container->getDefinition('d')->getProperties();
|
||||
$expected = new TaggedIteratorArgument('foo');
|
||||
$expected->setValues(array(new Reference('b'), new Reference('c'), new Reference('a')));
|
||||
$this->assertEquals($expected, $properties['foos']);
|
||||
}
|
||||
}
|
Reference in a new issue