Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
53
vendor/symfony/dependency-injection/Tests/Argument/RewindableGeneratorTest.php
vendored
Normal file
53
vendor/symfony/dependency-injection/Tests/Argument/RewindableGeneratorTest.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\Argument;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
|
||||
|
||||
class RewindableGeneratorTest extends TestCase
|
||||
{
|
||||
public function testImplementsCountable()
|
||||
{
|
||||
$this->assertInstanceOf(\Countable::class, new RewindableGenerator(function () {
|
||||
yield 1;
|
||||
}, 1));
|
||||
}
|
||||
|
||||
public function testCountUsesProvidedValue()
|
||||
{
|
||||
$generator = new RewindableGenerator(function () {
|
||||
yield 1;
|
||||
}, 3);
|
||||
|
||||
$this->assertCount(3, $generator);
|
||||
}
|
||||
|
||||
public function testCountUsesProvidedValueAsCallback()
|
||||
{
|
||||
$called = 0;
|
||||
$generator = new RewindableGenerator(function () {
|
||||
yield 1;
|
||||
}, function () use (&$called) {
|
||||
++$called;
|
||||
|
||||
return 3;
|
||||
});
|
||||
|
||||
$this->assertSame(0, $called, 'Count callback is called lazily');
|
||||
$this->assertCount(3, $generator);
|
||||
|
||||
\count($generator);
|
||||
|
||||
$this->assertSame(1, $called, 'Count callback is called only once');
|
||||
}
|
||||
}
|
157
vendor/symfony/dependency-injection/Tests/ChildDefinitionTest.php
vendored
Normal file
157
vendor/symfony/dependency-injection/Tests/ChildDefinitionTest.php
vendored
Normal file
|
@ -0,0 +1,157 @@
|
|||
<?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;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
||||
|
||||
class ChildDefinitionTest extends TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$def = new ChildDefinition('foo');
|
||||
|
||||
$this->assertSame('foo', $def->getParent());
|
||||
$this->assertSame(array(), $def->getChanges());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyTests
|
||||
*/
|
||||
public function testSetProperty($property, $changeKey)
|
||||
{
|
||||
$def = new ChildDefinition('foo');
|
||||
|
||||
$getter = 'get'.ucfirst($property);
|
||||
$setter = 'set'.ucfirst($property);
|
||||
|
||||
$this->assertNull($def->$getter());
|
||||
$this->assertSame($def, $def->$setter('foo'));
|
||||
$this->assertSame('foo', $def->$getter());
|
||||
$this->assertSame(array($changeKey => true), $def->getChanges());
|
||||
}
|
||||
|
||||
public function getPropertyTests()
|
||||
{
|
||||
return array(
|
||||
array('class', 'class'),
|
||||
array('factory', 'factory'),
|
||||
array('configurator', 'configurator'),
|
||||
array('file', 'file'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetPublic()
|
||||
{
|
||||
$def = new ChildDefinition('foo');
|
||||
|
||||
$this->assertTrue($def->isPublic());
|
||||
$this->assertSame($def, $def->setPublic(false));
|
||||
$this->assertFalse($def->isPublic());
|
||||
$this->assertSame(array('public' => true), $def->getChanges());
|
||||
}
|
||||
|
||||
public function testSetLazy()
|
||||
{
|
||||
$def = new ChildDefinition('foo');
|
||||
|
||||
$this->assertFalse($def->isLazy());
|
||||
$this->assertSame($def, $def->setLazy(false));
|
||||
$this->assertFalse($def->isLazy());
|
||||
$this->assertSame(array('lazy' => true), $def->getChanges());
|
||||
}
|
||||
|
||||
public function testSetAutowired()
|
||||
{
|
||||
$def = new ChildDefinition('foo');
|
||||
|
||||
$this->assertFalse($def->isAutowired());
|
||||
$this->assertSame($def, $def->setAutowired(true));
|
||||
$this->assertTrue($def->isAutowired());
|
||||
$this->assertSame(array('autowired' => true), $def->getChanges());
|
||||
}
|
||||
|
||||
public function testSetArgument()
|
||||
{
|
||||
$def = new ChildDefinition('foo');
|
||||
|
||||
$this->assertSame(array(), $def->getArguments());
|
||||
$this->assertSame($def, $def->replaceArgument(0, 'foo'));
|
||||
$this->assertSame(array('index_0' => 'foo'), $def->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testReplaceArgumentShouldRequireIntegerIndex()
|
||||
{
|
||||
$def = new ChildDefinition('foo');
|
||||
|
||||
$def->replaceArgument('0', 'foo');
|
||||
}
|
||||
|
||||
public function testReplaceArgument()
|
||||
{
|
||||
$def = new ChildDefinition('foo');
|
||||
|
||||
$def->setArguments(array(0 => 'foo', 1 => 'bar'));
|
||||
$this->assertSame('foo', $def->getArgument(0));
|
||||
$this->assertSame('bar', $def->getArgument(1));
|
||||
|
||||
$this->assertSame($def, $def->replaceArgument(1, 'baz'));
|
||||
$this->assertSame('foo', $def->getArgument(0));
|
||||
$this->assertSame('baz', $def->getArgument(1));
|
||||
|
||||
$this->assertSame(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz'), $def->getArguments());
|
||||
|
||||
$this->assertSame($def, $def->replaceArgument('$bar', 'val'));
|
||||
$this->assertSame('val', $def->getArgument('$bar'));
|
||||
$this->assertSame(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz', '$bar' => 'val'), $def->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \OutOfBoundsException
|
||||
*/
|
||||
public function testGetArgumentShouldCheckBounds()
|
||||
{
|
||||
$def = new ChildDefinition('foo');
|
||||
|
||||
$def->setArguments(array(0 => 'foo'));
|
||||
$def->replaceArgument(0, 'foo');
|
||||
|
||||
$def->getArgument(1);
|
||||
}
|
||||
|
||||
public function testDefinitionDecoratorAliasExistsForBackwardsCompatibility()
|
||||
{
|
||||
$this->assertInstanceOf(ChildDefinition::class, new DefinitionDecorator('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\BadMethodCallException
|
||||
*/
|
||||
public function testCannotCallSetAutoconfigured()
|
||||
{
|
||||
$def = new ChildDefinition('foo');
|
||||
$def->setAutoconfigured(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\BadMethodCallException
|
||||
*/
|
||||
public function testCannotCallSetInstanceofConditionals()
|
||||
{
|
||||
$def = new ChildDefinition('foo');
|
||||
$def->setInstanceofConditionals(array('Foo' => new ChildDefinition('')));
|
||||
}
|
||||
}
|
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']);
|
||||
}
|
||||
}
|
124
vendor/symfony/dependency-injection/Tests/Config/AutowireServiceResourceTest.php
vendored
Normal file
124
vendor/symfony/dependency-injection/Tests/Config/AutowireServiceResourceTest.php
vendored
Normal file
|
@ -0,0 +1,124 @@
|
|||
<?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\Config;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
|
||||
use Symfony\Component\DependencyInjection\Config\AutowireServiceResource;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class AutowireServiceResourceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var AutowireServiceResource
|
||||
*/
|
||||
private $resource;
|
||||
private $file;
|
||||
private $class;
|
||||
private $time;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->file = realpath(sys_get_temp_dir()).'/tmp.php';
|
||||
$this->time = time();
|
||||
touch($this->file, $this->time);
|
||||
|
||||
$this->class = __NAMESPACE__.'\Foo';
|
||||
$this->resource = new AutowireServiceResource(
|
||||
$this->class,
|
||||
$this->file,
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
public function testToString()
|
||||
{
|
||||
$this->assertSame('service.autowire.'.$this->class, (string) $this->resource);
|
||||
}
|
||||
|
||||
public function testSerializeUnserialize()
|
||||
{
|
||||
$unserialized = unserialize(serialize($this->resource));
|
||||
|
||||
$this->assertEquals($this->resource, $unserialized);
|
||||
}
|
||||
|
||||
public function testIsFresh()
|
||||
{
|
||||
$this->assertTrue($this->resource->isFresh($this->time), '->isFresh() returns true if the resource has not changed in same second');
|
||||
$this->assertTrue($this->resource->isFresh($this->time + 10), '->isFresh() returns true if the resource has not changed');
|
||||
$this->assertFalse($this->resource->isFresh($this->time - 86400), '->isFresh() returns false if the resource has been updated');
|
||||
}
|
||||
|
||||
public function testIsFreshForDeletedResources()
|
||||
{
|
||||
unlink($this->file);
|
||||
|
||||
$this->assertFalse($this->resource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the resource does not exist');
|
||||
}
|
||||
|
||||
public function testIsNotFreshChangedResource()
|
||||
{
|
||||
$oldResource = new AutowireServiceResource(
|
||||
$this->class,
|
||||
$this->file,
|
||||
array('will_be_different')
|
||||
);
|
||||
|
||||
// test with a stale file *and* a resource that *will* be different than the actual
|
||||
$this->assertFalse($oldResource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the constructor arguments have changed');
|
||||
}
|
||||
|
||||
public function testIsFreshSameConstructorArgs()
|
||||
{
|
||||
$oldResource = AutowirePass::createResourceForClass(
|
||||
new \ReflectionClass(__NAMESPACE__.'\Foo')
|
||||
);
|
||||
|
||||
// test with a stale file *but* the resource will not be changed
|
||||
$this->assertTrue($oldResource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the constructor arguments have changed');
|
||||
}
|
||||
|
||||
public function testNotFreshIfClassNotFound()
|
||||
{
|
||||
$resource = new AutowireServiceResource(
|
||||
'Some\Non\Existent\Class',
|
||||
$this->file,
|
||||
array()
|
||||
);
|
||||
|
||||
$this->assertFalse($resource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the class no longer exists');
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
if (!file_exists($this->file)) {
|
||||
return;
|
||||
}
|
||||
|
||||
unlink($this->file);
|
||||
}
|
||||
|
||||
private function getStaleFileTime()
|
||||
{
|
||||
return $this->time - 10;
|
||||
}
|
||||
}
|
||||
|
||||
class Foo
|
||||
{
|
||||
public function __construct($foo)
|
||||
{
|
||||
}
|
||||
}
|
77
vendor/symfony/dependency-injection/Tests/Config/ContainerParametersResourceCheckerTest.php
vendored
Normal file
77
vendor/symfony/dependency-injection/Tests/Config/ContainerParametersResourceCheckerTest.php
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?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\Config;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\ResourceCheckerInterface;
|
||||
use Symfony\Component\DependencyInjection\Config\ContainerParametersResource;
|
||||
use Symfony\Component\DependencyInjection\Config\ContainerParametersResourceChecker;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
class ContainerParametersResourceCheckerTest extends TestCase
|
||||
{
|
||||
/** @var ContainerParametersResource */
|
||||
private $resource;
|
||||
|
||||
/** @var ResourceCheckerInterface */
|
||||
private $resourceChecker;
|
||||
|
||||
/** @var ContainerInterface */
|
||||
private $container;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->resource = new ContainerParametersResource(array('locales' => array('fr', 'en'), 'default_locale' => 'fr'));
|
||||
$this->container = $this->getMockBuilder(ContainerInterface::class)->getMock();
|
||||
$this->resourceChecker = new ContainerParametersResourceChecker($this->container);
|
||||
}
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$this->assertTrue($this->resourceChecker->supports($this->resource));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider isFreshProvider
|
||||
*/
|
||||
public function testIsFresh(callable $mockContainer, $expected)
|
||||
{
|
||||
$mockContainer($this->container);
|
||||
|
||||
$this->assertSame($expected, $this->resourceChecker->isFresh($this->resource, time()));
|
||||
}
|
||||
|
||||
public function isFreshProvider()
|
||||
{
|
||||
yield 'not fresh on missing parameter' => array(function (\PHPUnit_Framework_MockObject_MockObject $container) {
|
||||
$container->method('hasParameter')->with('locales')->willReturn(false);
|
||||
}, false);
|
||||
|
||||
yield 'not fresh on different value' => array(function (\PHPUnit_Framework_MockObject_MockObject $container) {
|
||||
$container->method('getParameter')->with('locales')->willReturn(array('nl', 'es'));
|
||||
}, false);
|
||||
|
||||
yield 'fresh on every identical parameters' => array(function (\PHPUnit_Framework_MockObject_MockObject $container) {
|
||||
$container->expects($this->exactly(2))->method('hasParameter')->willReturn(true);
|
||||
$container->expects($this->exactly(2))->method('getParameter')
|
||||
->withConsecutive(
|
||||
array($this->equalTo('locales')),
|
||||
array($this->equalTo('default_locale'))
|
||||
)
|
||||
->will($this->returnValueMap(array(
|
||||
array('locales', array('fr', 'en')),
|
||||
array('default_locale', 'fr'),
|
||||
)))
|
||||
;
|
||||
}, true);
|
||||
}
|
||||
}
|
43
vendor/symfony/dependency-injection/Tests/Config/ContainerParametersResourceTest.php
vendored
Normal file
43
vendor/symfony/dependency-injection/Tests/Config/ContainerParametersResourceTest.php
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?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\Config;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Config\ContainerParametersResource;
|
||||
|
||||
class ContainerParametersResourceTest extends TestCase
|
||||
{
|
||||
/** @var ContainerParametersResource */
|
||||
private $resource;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->resource = new ContainerParametersResource(array('locales' => array('fr', 'en'), 'default_locale' => 'fr'));
|
||||
}
|
||||
|
||||
public function testToString()
|
||||
{
|
||||
$this->assertSame('container_parameters_9893d3133814ab03cac3490f36dece77', (string) $this->resource);
|
||||
}
|
||||
|
||||
public function testSerializeUnserialize()
|
||||
{
|
||||
$unserialized = unserialize(serialize($this->resource));
|
||||
|
||||
$this->assertEquals($this->resource, $unserialized);
|
||||
}
|
||||
|
||||
public function testGetParameters()
|
||||
{
|
||||
$this->assertSame(array('locales' => array('fr', 'en'), 'default_locale' => 'fr'), $this->resource->getParameters());
|
||||
}
|
||||
}
|
1516
vendor/symfony/dependency-injection/Tests/ContainerBuilderTest.php
vendored
Normal file
1516
vendor/symfony/dependency-injection/Tests/ContainerBuilderTest.php
vendored
Normal file
File diff suppressed because it is too large
Load diff
689
vendor/symfony/dependency-injection/Tests/ContainerTest.php
vendored
Normal file
689
vendor/symfony/dependency-injection/Tests/ContainerTest.php
vendored
Normal file
|
@ -0,0 +1,689 @@
|
|||
<?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;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
|
||||
class ContainerTest extends TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$sc = new Container();
|
||||
$this->assertSame($sc, $sc->get('service_container'), '__construct() automatically registers itself as a service');
|
||||
|
||||
$sc = new Container(new ParameterBag(array('foo' => 'bar')));
|
||||
$this->assertEquals(array('foo' => 'bar'), $sc->getParameterBag()->all(), '__construct() takes an array of parameters as its first argument');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataForTestCamelize
|
||||
*/
|
||||
public function testCamelize($id, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, Container::camelize($id), sprintf('Container::camelize("%s")', $id));
|
||||
}
|
||||
|
||||
public function dataForTestCamelize()
|
||||
{
|
||||
return array(
|
||||
array('foo_bar', 'FooBar'),
|
||||
array('foo.bar', 'Foo_Bar'),
|
||||
array('foo.bar_baz', 'Foo_BarBaz'),
|
||||
array('foo._bar', 'Foo_Bar'),
|
||||
array('foo_.bar', 'Foo_Bar'),
|
||||
array('_foo', 'Foo'),
|
||||
array('.foo', '_Foo'),
|
||||
array('foo_', 'Foo'),
|
||||
array('foo.', 'Foo_'),
|
||||
array('foo\bar', 'Foo_Bar'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataForTestUnderscore
|
||||
*/
|
||||
public function testUnderscore($id, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, Container::underscore($id), sprintf('Container::underscore("%s")', $id));
|
||||
}
|
||||
|
||||
public function dataForTestUnderscore()
|
||||
{
|
||||
return array(
|
||||
array('FooBar', 'foo_bar'),
|
||||
array('Foo_Bar', 'foo.bar'),
|
||||
array('Foo_BarBaz', 'foo.bar_baz'),
|
||||
array('FooBar_BazQux', 'foo_bar.baz_qux'),
|
||||
array('_Foo', '.foo'),
|
||||
array('Foo_', 'foo.'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testCompile()
|
||||
{
|
||||
$sc = new Container(new ParameterBag(array('foo' => 'bar')));
|
||||
$this->assertFalse($sc->getParameterBag()->isResolved(), '->compile() resolves the parameter bag');
|
||||
$sc->compile();
|
||||
$this->assertTrue($sc->getParameterBag()->isResolved(), '->compile() resolves the parameter bag');
|
||||
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag', $sc->getParameterBag(), '->compile() changes the parameter bag to a FrozenParameterBag instance');
|
||||
$this->assertEquals(array('foo' => 'bar'), $sc->getParameterBag()->all(), '->compile() copies the current parameters to the new parameter bag');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation The Symfony\Component\DependencyInjection\Container::isFrozen() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the isCompiled() method instead.
|
||||
* @expectedDeprecation The Symfony\Component\DependencyInjection\Container::isFrozen() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the isCompiled() method instead.
|
||||
*/
|
||||
public function testIsFrozen()
|
||||
{
|
||||
$sc = new Container(new ParameterBag(array('foo' => 'bar')));
|
||||
$this->assertFalse($sc->isFrozen(), '->isFrozen() returns false if the parameters are not frozen');
|
||||
$sc->compile();
|
||||
$this->assertTrue($sc->isFrozen(), '->isFrozen() returns true if the parameters are frozen');
|
||||
}
|
||||
|
||||
public function testIsCompiled()
|
||||
{
|
||||
$sc = new Container(new ParameterBag(array('foo' => 'bar')));
|
||||
$this->assertFalse($sc->isCompiled(), '->isCompiled() returns false if the container is not compiled');
|
||||
$sc->compile();
|
||||
$this->assertTrue($sc->isCompiled(), '->isCompiled() returns true if the container is compiled');
|
||||
}
|
||||
|
||||
public function testIsCompiledWithFrozenParameters()
|
||||
{
|
||||
$sc = new Container(new FrozenParameterBag(array('foo' => 'bar')));
|
||||
$this->assertFalse($sc->isCompiled(), '->isCompiled() returns false if the container is not compiled but the parameter bag is already frozen');
|
||||
}
|
||||
|
||||
public function testGetParameterBag()
|
||||
{
|
||||
$sc = new Container();
|
||||
$this->assertEquals(array(), $sc->getParameterBag()->all(), '->getParameterBag() returns an empty array if no parameter has been defined');
|
||||
}
|
||||
|
||||
public function testGetSetParameter()
|
||||
{
|
||||
$sc = new Container(new ParameterBag(array('foo' => 'bar')));
|
||||
$sc->setParameter('bar', 'foo');
|
||||
$this->assertEquals('foo', $sc->getParameter('bar'), '->setParameter() sets the value of a new parameter');
|
||||
|
||||
$sc->setParameter('foo', 'baz');
|
||||
$this->assertEquals('baz', $sc->getParameter('foo'), '->setParameter() overrides previously set parameter');
|
||||
|
||||
try {
|
||||
$sc->getParameter('baba');
|
||||
$this->fail('->getParameter() thrown an \InvalidArgumentException if the key does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->getParameter() thrown an \InvalidArgumentException if the key does not exist');
|
||||
$this->assertEquals('You have requested a non-existent parameter "baba".', $e->getMessage(), '->getParameter() thrown an \InvalidArgumentException if the key does not exist');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "Foo" instead of "foo" is deprecated since Symfony 3.4.
|
||||
* @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "FOO" instead of "foo" is deprecated since Symfony 3.4.
|
||||
*/
|
||||
public function testGetSetParameterWithMixedCase()
|
||||
{
|
||||
$sc = new Container(new ParameterBag(array('foo' => 'bar')));
|
||||
|
||||
$sc->setParameter('Foo', 'baz1');
|
||||
$this->assertEquals('baz1', $sc->getParameter('foo'), '->setParameter() converts the key to lowercase');
|
||||
$this->assertEquals('baz1', $sc->getParameter('FOO'), '->getParameter() converts the key to lowercase');
|
||||
}
|
||||
|
||||
public function testGetServiceIds()
|
||||
{
|
||||
$sc = new Container();
|
||||
$sc->set('foo', $obj = new \stdClass());
|
||||
$sc->set('bar', $obj = new \stdClass());
|
||||
$this->assertEquals(array('service_container', 'foo', 'bar'), $sc->getServiceIds(), '->getServiceIds() returns all defined service ids');
|
||||
|
||||
$sc = new ProjectServiceContainer();
|
||||
$sc->set('foo', $obj = new \stdClass());
|
||||
$this->assertEquals(array('service_container', 'internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'internal_dependency', 'foo'), $sc->getServiceIds(), '->getServiceIds() returns defined service ids by factory methods in the method map, followed by service ids defined by set()');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
|
||||
*/
|
||||
public function testGetLegacyServiceIds()
|
||||
{
|
||||
$sc = new LegacyProjectServiceContainer();
|
||||
$sc->set('foo', $obj = new \stdClass());
|
||||
|
||||
$this->assertEquals(array('internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'service_container', 'foo'), $sc->getServiceIds(), '->getServiceIds() returns defined service ids by getXXXService() methods, followed by service ids defined by set()');
|
||||
}
|
||||
|
||||
public function testSet()
|
||||
{
|
||||
$sc = new Container();
|
||||
$sc->set('._. \\o/', $foo = new \stdClass());
|
||||
$this->assertSame($foo, $sc->get('._. \\o/'), '->set() sets a service');
|
||||
}
|
||||
|
||||
public function testSetWithNullResetTheService()
|
||||
{
|
||||
$sc = new Container();
|
||||
$sc->set('foo', null);
|
||||
$this->assertFalse($sc->has('foo'), '->set() with null service resets the service');
|
||||
}
|
||||
|
||||
public function testSetReplacesAlias()
|
||||
{
|
||||
$c = new ProjectServiceContainer();
|
||||
|
||||
$c->set('alias', $foo = new \stdClass());
|
||||
$this->assertSame($foo, $c->get('alias'), '->set() replaces an existing alias');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation The "bar" service is already initialized, unsetting it is deprecated since Symfony 3.3 and will fail in 4.0.
|
||||
*/
|
||||
public function testSetWithNullOnInitializedPredefinedService()
|
||||
{
|
||||
$sc = new Container();
|
||||
$sc->set('foo', new \stdClass());
|
||||
$sc->set('foo', null);
|
||||
$this->assertFalse($sc->has('foo'), '->set() with null service resets the service');
|
||||
|
||||
$sc = new ProjectServiceContainer();
|
||||
$sc->get('bar');
|
||||
$sc->set('bar', null);
|
||||
$this->assertTrue($sc->has('bar'), '->set() with null service resets the pre-defined service');
|
||||
}
|
||||
|
||||
public function testSetWithNullOnUninitializedPredefinedService()
|
||||
{
|
||||
$sc = new Container();
|
||||
$sc->set('foo', new \stdClass());
|
||||
$sc->get('foo', null);
|
||||
$sc->set('foo', null);
|
||||
$this->assertFalse($sc->has('foo'), '->set() with null service resets the service');
|
||||
|
||||
$sc = new ProjectServiceContainer();
|
||||
$sc->set('bar', null);
|
||||
$this->assertTrue($sc->has('bar'), '->set() with null service resets the pre-defined service');
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$sc = new ProjectServiceContainer();
|
||||
$sc->set('foo', $foo = new \stdClass());
|
||||
$this->assertSame($foo, $sc->get('foo'), '->get() returns the service for the given id');
|
||||
$this->assertSame($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
|
||||
$this->assertSame($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined');
|
||||
$this->assertSame($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined');
|
||||
|
||||
try {
|
||||
$sc->get('');
|
||||
$this->fail('->get() throws a \InvalidArgumentException exception if the service is empty');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException', $e, '->get() throws a ServiceNotFoundException exception if the service is empty');
|
||||
}
|
||||
$this->assertNull($sc->get('', ContainerInterface::NULL_ON_INVALID_REFERENCE), '->get() returns null if the service is empty');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Service identifiers will be made case sensitive in Symfony 4.0. Using "Foo" instead of "foo" is deprecated since Symfony 3.3.
|
||||
*/
|
||||
public function testGetInsensitivity()
|
||||
{
|
||||
$sc = new ProjectServiceContainer();
|
||||
$sc->set('foo', $foo = new \stdClass());
|
||||
$this->assertSame($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Service identifiers will be made case sensitive in Symfony 4.0. Using "foo" instead of "Foo" is deprecated since Symfony 3.3.
|
||||
*/
|
||||
public function testNormalizeIdKeepsCase()
|
||||
{
|
||||
$sc = new ProjectServiceContainer();
|
||||
$sc->normalizeId('Foo', true);
|
||||
$this->assertSame('Foo', $sc->normalizeId('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Service identifiers will be made case sensitive in Symfony 4.0. Using "Foo" instead of "foo" is deprecated since Symfony 3.3.
|
||||
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
|
||||
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
|
||||
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
|
||||
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
|
||||
*/
|
||||
public function testLegacyGet()
|
||||
{
|
||||
$sc = new LegacyProjectServiceContainer();
|
||||
$sc->set('foo', $foo = new \stdClass());
|
||||
|
||||
$this->assertSame($foo, $sc->get('foo'), '->get() returns the service for the given id');
|
||||
$this->assertSame($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase');
|
||||
$this->assertSame($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
|
||||
$this->assertSame($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined');
|
||||
$this->assertSame($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined');
|
||||
$this->assertSame($sc->__foo_baz, $sc->get('foo\\baz'), '->get() returns the service if a get*Method() is defined');
|
||||
|
||||
$sc->set('bar', $bar = new \stdClass());
|
||||
$this->assertSame($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()');
|
||||
|
||||
try {
|
||||
$sc->get('');
|
||||
$this->fail('->get() throws a \InvalidArgumentException exception if the service is empty');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException', $e, '->get() throws a ServiceNotFoundException exception if the service is empty');
|
||||
}
|
||||
$this->assertNull($sc->get('', ContainerInterface::NULL_ON_INVALID_REFERENCE), '->get() returns null if the service is empty');
|
||||
}
|
||||
|
||||
public function testGetThrowServiceNotFoundException()
|
||||
{
|
||||
$sc = new ProjectServiceContainer();
|
||||
$sc->set('foo', $foo = new \stdClass());
|
||||
$sc->set('baz', $foo = new \stdClass());
|
||||
|
||||
try {
|
||||
$sc->get('foo1');
|
||||
$this->fail('->get() throws an Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException if the key does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException', $e, '->get() throws an Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException if the key does not exist');
|
||||
$this->assertEquals('You have requested a non-existent service "foo1". Did you mean this: "foo"?', $e->getMessage(), '->get() throws an Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException with some advices');
|
||||
}
|
||||
|
||||
try {
|
||||
$sc->get('bag');
|
||||
$this->fail('->get() throws an Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException if the key does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException', $e, '->get() throws an Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException if the key does not exist');
|
||||
$this->assertEquals('You have requested a non-existent service "bag". Did you mean one of these: "bar", "baz"?', $e->getMessage(), '->get() throws an Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException with some advices');
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetCircularReference()
|
||||
{
|
||||
$sc = new ProjectServiceContainer();
|
||||
try {
|
||||
$sc->get('circular');
|
||||
$this->fail('->get() throws a ServiceCircularReferenceException if it contains circular reference');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException', $e, '->get() throws a ServiceCircularReferenceException if it contains circular reference');
|
||||
$this->assertStringStartsWith('Circular reference detected for service "circular"', $e->getMessage(), '->get() throws a \LogicException if it contains circular reference');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
|
||||
* @expectedExceptionMessage The "request" service is synthetic, it needs to be set at boot time before it can be used.
|
||||
*/
|
||||
public function testGetSyntheticServiceThrows()
|
||||
{
|
||||
require_once __DIR__.'/Fixtures/php/services9_compiled.php';
|
||||
|
||||
$container = new \ProjectServiceContainer();
|
||||
$container->get('request');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
|
||||
* @expectedExceptionMessage The "inlined" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.
|
||||
*/
|
||||
public function testGetRemovedServiceThrows()
|
||||
{
|
||||
require_once __DIR__.'/Fixtures/php/services9_compiled.php';
|
||||
|
||||
$container = new \ProjectServiceContainer();
|
||||
$container->get('inlined');
|
||||
}
|
||||
|
||||
public function testHas()
|
||||
{
|
||||
$sc = new ProjectServiceContainer();
|
||||
$sc->set('foo', new \stdClass());
|
||||
$this->assertFalse($sc->has('foo1'), '->has() returns false if the service does not exist');
|
||||
$this->assertTrue($sc->has('foo'), '->has() returns true if the service exists');
|
||||
$this->assertTrue($sc->has('bar'), '->has() returns true if a get*Method() is defined');
|
||||
$this->assertTrue($sc->has('foo_bar'), '->has() returns true if a get*Method() is defined');
|
||||
$this->assertTrue($sc->has('foo.baz'), '->has() returns true if a get*Method() is defined');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
|
||||
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
|
||||
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
|
||||
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
|
||||
*/
|
||||
public function testLegacyHas()
|
||||
{
|
||||
$sc = new LegacyProjectServiceContainer();
|
||||
$sc->set('foo', new \stdClass());
|
||||
|
||||
$this->assertFalse($sc->has('foo1'), '->has() returns false if the service does not exist');
|
||||
$this->assertTrue($sc->has('foo'), '->has() returns true if the service exists');
|
||||
$this->assertTrue($sc->has('bar'), '->has() returns true if a get*Method() is defined');
|
||||
$this->assertTrue($sc->has('foo_bar'), '->has() returns true if a get*Method() is defined');
|
||||
$this->assertTrue($sc->has('foo.baz'), '->has() returns true if a get*Method() is defined');
|
||||
$this->assertTrue($sc->has('foo\\baz'), '->has() returns true if a get*Method() is defined');
|
||||
}
|
||||
|
||||
public function testInitialized()
|
||||
{
|
||||
$sc = new ProjectServiceContainer();
|
||||
$sc->set('foo', new \stdClass());
|
||||
$this->assertTrue($sc->initialized('foo'), '->initialized() returns true if service is loaded');
|
||||
$this->assertFalse($sc->initialized('foo1'), '->initialized() returns false if service is not loaded');
|
||||
$this->assertFalse($sc->initialized('bar'), '->initialized() returns false if a service is defined, but not currently loaded');
|
||||
$this->assertFalse($sc->initialized('alias'), '->initialized() returns false if an aliased service is not initialized');
|
||||
|
||||
$sc->get('bar');
|
||||
$this->assertTrue($sc->initialized('alias'), '->initialized() returns true for alias if aliased service is initialized');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Checking for the initialization of the "internal" private service is deprecated since Symfony 3.4 and won't be supported anymore in Symfony 4.0.
|
||||
*/
|
||||
public function testInitializedWithPrivateService()
|
||||
{
|
||||
$sc = new ProjectServiceContainer();
|
||||
$sc->get('internal_dependency');
|
||||
$this->assertTrue($sc->initialized('internal'));
|
||||
}
|
||||
|
||||
public function testReset()
|
||||
{
|
||||
$c = new Container();
|
||||
$c->set('bar', new \stdClass());
|
||||
|
||||
$c->reset();
|
||||
|
||||
$this->assertNull($c->get('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
* @expectedExceptionMessage Something went terribly wrong!
|
||||
*/
|
||||
public function testGetThrowsException()
|
||||
{
|
||||
$c = new ProjectServiceContainer();
|
||||
|
||||
try {
|
||||
$c->get('throw_exception');
|
||||
} catch (\Exception $e) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
// Retry, to make sure that get*Service() will be called.
|
||||
$c->get('throw_exception');
|
||||
}
|
||||
|
||||
public function testGetThrowsExceptionOnServiceConfiguration()
|
||||
{
|
||||
$c = new ProjectServiceContainer();
|
||||
|
||||
try {
|
||||
$c->get('throws_exception_on_service_configuration');
|
||||
} catch (\Exception $e) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
$this->assertFalse($c->initialized('throws_exception_on_service_configuration'));
|
||||
|
||||
// Retry, to make sure that get*Service() will be called.
|
||||
try {
|
||||
$c->get('throws_exception_on_service_configuration');
|
||||
} catch (\Exception $e) {
|
||||
// Do nothing.
|
||||
}
|
||||
$this->assertFalse($c->initialized('throws_exception_on_service_configuration'));
|
||||
}
|
||||
|
||||
protected function getField($obj, $field)
|
||||
{
|
||||
$reflection = new \ReflectionProperty($obj, $field);
|
||||
$reflection->setAccessible(true);
|
||||
|
||||
return $reflection->getValue($obj);
|
||||
}
|
||||
|
||||
public function testAlias()
|
||||
{
|
||||
$c = new ProjectServiceContainer();
|
||||
|
||||
$this->assertTrue($c->has('alias'));
|
||||
$this->assertSame($c->get('alias'), $c->get('bar'));
|
||||
}
|
||||
|
||||
public function testThatCloningIsNotSupported()
|
||||
{
|
||||
$class = new \ReflectionClass('Symfony\Component\DependencyInjection\Container');
|
||||
$clone = $class->getMethod('__clone');
|
||||
$this->assertFalse($class->isCloneable());
|
||||
$this->assertTrue($clone->isPrivate());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation The "internal" service is private, unsetting it is deprecated since Symfony 3.2 and will fail in 4.0.
|
||||
*/
|
||||
public function testUnsetInternalPrivateServiceIsDeprecated()
|
||||
{
|
||||
$c = new ProjectServiceContainer();
|
||||
$c->set('internal', null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation The "internal" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0.
|
||||
*/
|
||||
public function testChangeInternalPrivateServiceIsDeprecated()
|
||||
{
|
||||
$c = new ProjectServiceContainer();
|
||||
$c->set('internal', $internal = new \stdClass());
|
||||
$this->assertSame($c->get('internal'), $internal);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation The "internal" service is private, checking for its existence is deprecated since Symfony 3.2 and will fail in 4.0.
|
||||
*/
|
||||
public function testCheckExistenceOfAnInternalPrivateServiceIsDeprecated()
|
||||
{
|
||||
$c = new ProjectServiceContainer();
|
||||
$c->get('internal_dependency');
|
||||
$this->assertTrue($c->has('internal'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation The "internal" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.
|
||||
*/
|
||||
public function testRequestAnInternalSharedPrivateServiceIsDeprecated()
|
||||
{
|
||||
$c = new ProjectServiceContainer();
|
||||
$c->get('internal_dependency');
|
||||
$c->get('internal');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation The "bar" service is already initialized, replacing it is deprecated since Symfony 3.3 and will fail in 4.0.
|
||||
*/
|
||||
public function testReplacingAPreDefinedServiceIsDeprecated()
|
||||
{
|
||||
$c = new ProjectServiceContainer();
|
||||
$c->set('bar', new \stdClass());
|
||||
$c->set('bar', $bar = new \stdClass());
|
||||
|
||||
$this->assertSame($bar, $c->get('bar'), '->set() replaces a pre-defined service');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation The "synthetic" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0.
|
||||
*/
|
||||
public function testSetWithPrivateSyntheticServiceThrowsDeprecation()
|
||||
{
|
||||
$c = new ProjectServiceContainer();
|
||||
$c->set('synthetic', new \stdClass());
|
||||
}
|
||||
}
|
||||
|
||||
class ProjectServiceContainer extends Container
|
||||
{
|
||||
public $__bar;
|
||||
public $__foo_bar;
|
||||
public $__foo_baz;
|
||||
public $__internal;
|
||||
protected $privates;
|
||||
protected $methodMap = array(
|
||||
'internal' => 'getInternalService',
|
||||
'bar' => 'getBarService',
|
||||
'foo_bar' => 'getFooBarService',
|
||||
'foo.baz' => 'getFoo_BazService',
|
||||
'circular' => 'getCircularService',
|
||||
'throw_exception' => 'getThrowExceptionService',
|
||||
'throws_exception_on_service_configuration' => 'getThrowsExceptionOnServiceConfigurationService',
|
||||
'internal_dependency' => 'getInternalDependencyService',
|
||||
);
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->__bar = new \stdClass();
|
||||
$this->__foo_bar = new \stdClass();
|
||||
$this->__foo_baz = new \stdClass();
|
||||
$this->__internal = new \stdClass();
|
||||
$this->privates = array(
|
||||
'internal' => true,
|
||||
'synthetic' => true,
|
||||
);
|
||||
$this->aliases = array('alias' => 'bar');
|
||||
$this->syntheticIds['synthetic'] = true;
|
||||
}
|
||||
|
||||
protected function getInternalService()
|
||||
{
|
||||
return $this->services['internal'] = $this->__internal;
|
||||
}
|
||||
|
||||
protected function getBarService()
|
||||
{
|
||||
return $this->services['bar'] = $this->__bar;
|
||||
}
|
||||
|
||||
protected function getFooBarService()
|
||||
{
|
||||
return $this->__foo_bar;
|
||||
}
|
||||
|
||||
protected function getFoo_BazService()
|
||||
{
|
||||
return $this->__foo_baz;
|
||||
}
|
||||
|
||||
protected function getCircularService()
|
||||
{
|
||||
return $this->get('circular');
|
||||
}
|
||||
|
||||
protected function getThrowExceptionService()
|
||||
{
|
||||
throw new \Exception('Something went terribly wrong!');
|
||||
}
|
||||
|
||||
protected function getThrowsExceptionOnServiceConfigurationService()
|
||||
{
|
||||
$this->services['throws_exception_on_service_configuration'] = $instance = new \stdClass();
|
||||
|
||||
throw new \Exception('Something was terribly wrong while trying to configure the service!');
|
||||
}
|
||||
|
||||
protected function getInternalDependencyService()
|
||||
{
|
||||
$this->services['internal_dependency'] = $instance = new \stdClass();
|
||||
|
||||
$instance->internal = isset($this->services['internal']) ? $this->services['internal'] : $this->getInternalService();
|
||||
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
|
||||
class LegacyProjectServiceContainer extends Container
|
||||
{
|
||||
public $__bar;
|
||||
public $__foo_bar;
|
||||
public $__foo_baz;
|
||||
public $__internal;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->__bar = new \stdClass();
|
||||
$this->__foo_bar = new \stdClass();
|
||||
$this->__foo_baz = new \stdClass();
|
||||
$this->__internal = new \stdClass();
|
||||
$this->privates = array('internal' => true);
|
||||
$this->aliases = array('alias' => 'bar');
|
||||
}
|
||||
|
||||
protected function getInternalService()
|
||||
{
|
||||
return $this->__internal;
|
||||
}
|
||||
|
||||
protected function getBarService()
|
||||
{
|
||||
return $this->__bar;
|
||||
}
|
||||
|
||||
protected function getFooBarService()
|
||||
{
|
||||
return $this->__foo_bar;
|
||||
}
|
||||
|
||||
protected function getFoo_BazService()
|
||||
{
|
||||
return $this->__foo_baz;
|
||||
}
|
||||
|
||||
protected function getCircularService()
|
||||
{
|
||||
return $this->get('circular');
|
||||
}
|
||||
|
||||
protected function getThrowExceptionService()
|
||||
{
|
||||
throw new \Exception('Something went terribly wrong!');
|
||||
}
|
||||
|
||||
protected function getThrowsExceptionOnServiceConfigurationService()
|
||||
{
|
||||
$this->services['throws_exception_on_service_configuration'] = $instance = new \stdClass();
|
||||
|
||||
throw new \Exception('Something was terribly wrong while trying to configure the service!');
|
||||
}
|
||||
}
|
95
vendor/symfony/dependency-injection/Tests/CrossCheckTest.php
vendored
Normal file
95
vendor/symfony/dependency-injection/Tests/CrossCheckTest.php
vendored
Normal file
|
@ -0,0 +1,95 @@
|
|||
<?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;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
class CrossCheckTest extends TestCase
|
||||
{
|
||||
protected static $fixturesPath;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$fixturesPath = __DIR__.'/Fixtures/';
|
||||
|
||||
require_once self::$fixturesPath.'/includes/classes.php';
|
||||
require_once self::$fixturesPath.'/includes/foo.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider crossCheckLoadersDumpers
|
||||
*/
|
||||
public function testCrossCheck($fixture, $type)
|
||||
{
|
||||
$loaderClass = 'Symfony\\Component\\DependencyInjection\\Loader\\'.ucfirst($type).'FileLoader';
|
||||
$dumperClass = 'Symfony\\Component\\DependencyInjection\\Dumper\\'.ucfirst($type).'Dumper';
|
||||
|
||||
$tmp = tempnam(sys_get_temp_dir(), 'sf');
|
||||
|
||||
copy(self::$fixturesPath.'/'.$type.'/'.$fixture, $tmp);
|
||||
|
||||
$container1 = new ContainerBuilder();
|
||||
$loader1 = new $loaderClass($container1, new FileLocator());
|
||||
$loader1->load($tmp);
|
||||
|
||||
$dumper = new $dumperClass($container1);
|
||||
file_put_contents($tmp, $dumper->dump());
|
||||
|
||||
$container2 = new ContainerBuilder();
|
||||
$loader2 = new $loaderClass($container2, new FileLocator());
|
||||
$loader2->load($tmp);
|
||||
|
||||
unlink($tmp);
|
||||
|
||||
$this->assertEquals($container2->getAliases(), $container1->getAliases(), 'loading a dump from a previously loaded container returns the same container');
|
||||
$this->assertEquals($container2->getDefinitions(), $container1->getDefinitions(), 'loading a dump from a previously loaded container returns the same container');
|
||||
$this->assertEquals($container2->getParameterBag()->all(), $container1->getParameterBag()->all(), '->getParameterBag() returns the same value for both containers');
|
||||
|
||||
$r = new \ReflectionProperty(ContainerBuilder::class, 'normalizedIds');
|
||||
$r->setAccessible(true);
|
||||
$r->setValue($container2, array());
|
||||
$r->setValue($container1, array());
|
||||
|
||||
$this->assertEquals(serialize($container2), serialize($container1), 'loading a dump from a previously loaded container returns the same container');
|
||||
|
||||
$services1 = array();
|
||||
foreach ($container1 as $id => $service) {
|
||||
$services1[$id] = serialize($service);
|
||||
}
|
||||
$services2 = array();
|
||||
foreach ($container2 as $id => $service) {
|
||||
$services2[$id] = serialize($service);
|
||||
}
|
||||
|
||||
unset($services1['service_container'], $services2['service_container']);
|
||||
|
||||
$this->assertEquals($services2, $services1, 'Iterator on the containers returns the same services');
|
||||
}
|
||||
|
||||
public function crossCheckLoadersDumpers()
|
||||
{
|
||||
return array(
|
||||
array('services1.xml', 'xml'),
|
||||
array('services2.xml', 'xml'),
|
||||
array('services6.xml', 'xml'),
|
||||
array('services8.xml', 'xml'),
|
||||
array('services9.xml', 'xml'),
|
||||
array('services1.yml', 'yaml'),
|
||||
array('services2.yml', 'yaml'),
|
||||
array('services6.yml', 'yaml'),
|
||||
array('services8.yml', 'yaml'),
|
||||
array('services9.yml', 'yaml'),
|
||||
);
|
||||
}
|
||||
}
|
132
vendor/symfony/dependency-injection/Tests/DefinitionDecoratorTest.php
vendored
Normal file
132
vendor/symfony/dependency-injection/Tests/DefinitionDecoratorTest.php
vendored
Normal file
|
@ -0,0 +1,132 @@
|
|||
<?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;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class DefinitionDecoratorTest extends TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$def = new DefinitionDecorator('foo');
|
||||
|
||||
$this->assertEquals('foo', $def->getParent());
|
||||
$this->assertEquals(array(), $def->getChanges());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyTests
|
||||
*/
|
||||
public function testSetProperty($property, $changeKey)
|
||||
{
|
||||
$def = new DefinitionDecorator('foo');
|
||||
|
||||
$getter = 'get'.ucfirst($property);
|
||||
$setter = 'set'.ucfirst($property);
|
||||
|
||||
$this->assertNull($def->$getter());
|
||||
$this->assertSame($def, $def->$setter('foo'));
|
||||
$this->assertEquals('foo', $def->$getter());
|
||||
$this->assertEquals(array($changeKey => true), $def->getChanges());
|
||||
}
|
||||
|
||||
public function getPropertyTests()
|
||||
{
|
||||
return array(
|
||||
array('class', 'class'),
|
||||
array('factory', 'factory'),
|
||||
array('configurator', 'configurator'),
|
||||
array('file', 'file'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetPublic()
|
||||
{
|
||||
$def = new DefinitionDecorator('foo');
|
||||
|
||||
$this->assertTrue($def->isPublic());
|
||||
$this->assertSame($def, $def->setPublic(false));
|
||||
$this->assertFalse($def->isPublic());
|
||||
$this->assertEquals(array('public' => true), $def->getChanges());
|
||||
}
|
||||
|
||||
public function testSetLazy()
|
||||
{
|
||||
$def = new DefinitionDecorator('foo');
|
||||
|
||||
$this->assertFalse($def->isLazy());
|
||||
$this->assertSame($def, $def->setLazy(false));
|
||||
$this->assertFalse($def->isLazy());
|
||||
$this->assertEquals(array('lazy' => true), $def->getChanges());
|
||||
}
|
||||
|
||||
public function testSetAutowired()
|
||||
{
|
||||
$def = new DefinitionDecorator('foo');
|
||||
|
||||
$this->assertFalse($def->isAutowired());
|
||||
$this->assertSame($def, $def->setAutowired(true));
|
||||
$this->assertTrue($def->isAutowired());
|
||||
$this->assertSame(array('autowired' => true), $def->getChanges());
|
||||
}
|
||||
|
||||
public function testSetArgument()
|
||||
{
|
||||
$def = new DefinitionDecorator('foo');
|
||||
|
||||
$this->assertEquals(array(), $def->getArguments());
|
||||
$this->assertSame($def, $def->replaceArgument(0, 'foo'));
|
||||
$this->assertEquals(array('index_0' => 'foo'), $def->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testReplaceArgumentShouldRequireIntegerIndex()
|
||||
{
|
||||
$def = new DefinitionDecorator('foo');
|
||||
|
||||
$def->replaceArgument('0', 'foo');
|
||||
}
|
||||
|
||||
public function testReplaceArgument()
|
||||
{
|
||||
$def = new DefinitionDecorator('foo');
|
||||
|
||||
$def->setArguments(array(0 => 'foo', 1 => 'bar'));
|
||||
$this->assertEquals('foo', $def->getArgument(0));
|
||||
$this->assertEquals('bar', $def->getArgument(1));
|
||||
|
||||
$this->assertSame($def, $def->replaceArgument(1, 'baz'));
|
||||
$this->assertEquals('foo', $def->getArgument(0));
|
||||
$this->assertEquals('baz', $def->getArgument(1));
|
||||
|
||||
$this->assertEquals(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz'), $def->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \OutOfBoundsException
|
||||
*/
|
||||
public function testGetArgumentShouldCheckBounds()
|
||||
{
|
||||
$def = new DefinitionDecorator('foo');
|
||||
|
||||
$def->setArguments(array(0 => 'foo'));
|
||||
$def->replaceArgument(0, 'foo');
|
||||
|
||||
$def->getArgument(1);
|
||||
}
|
||||
}
|
399
vendor/symfony/dependency-injection/Tests/DefinitionTest.php
vendored
Normal file
399
vendor/symfony/dependency-injection/Tests/DefinitionTest.php
vendored
Normal file
|
@ -0,0 +1,399 @@
|
|||
<?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;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
class DefinitionTest extends TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertEquals('stdClass', $def->getClass(), '__construct() takes the class name as its first argument');
|
||||
$this->assertSame(array('class' => true), $def->getChanges());
|
||||
|
||||
$def = new Definition('stdClass', array('foo'));
|
||||
$this->assertEquals(array('foo'), $def->getArguments(), '__construct() takes an optional array of arguments as its second argument');
|
||||
}
|
||||
|
||||
public function testSetGetFactory()
|
||||
{
|
||||
$def = new Definition();
|
||||
|
||||
$this->assertSame($def, $def->setFactory('foo'), '->setFactory() implements a fluent interface');
|
||||
$this->assertEquals('foo', $def->getFactory(), '->getFactory() returns the factory');
|
||||
|
||||
$def->setFactory('Foo::bar');
|
||||
$this->assertEquals(array('Foo', 'bar'), $def->getFactory(), '->setFactory() converts string static method call to the array');
|
||||
$this->assertSame(array('factory' => true), $def->getChanges());
|
||||
}
|
||||
|
||||
public function testSetGetClass()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertSame($def, $def->setClass('foo'), '->setClass() implements a fluent interface');
|
||||
$this->assertEquals('foo', $def->getClass(), '->getClass() returns the class name');
|
||||
}
|
||||
|
||||
public function testSetGetDecoratedService()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertNull($def->getDecoratedService());
|
||||
$def->setDecoratedService('foo', 'foo.renamed', 5);
|
||||
$this->assertEquals(array('foo', 'foo.renamed', 5), $def->getDecoratedService());
|
||||
$def->setDecoratedService(null);
|
||||
$this->assertNull($def->getDecoratedService());
|
||||
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertNull($def->getDecoratedService());
|
||||
$def->setDecoratedService('foo', 'foo.renamed');
|
||||
$this->assertEquals(array('foo', 'foo.renamed', 0), $def->getDecoratedService());
|
||||
$def->setDecoratedService(null);
|
||||
$this->assertNull($def->getDecoratedService());
|
||||
|
||||
$def = new Definition('stdClass');
|
||||
$def->setDecoratedService('foo');
|
||||
$this->assertEquals(array('foo', null, 0), $def->getDecoratedService());
|
||||
$def->setDecoratedService(null);
|
||||
$this->assertNull($def->getDecoratedService());
|
||||
|
||||
$def = new Definition('stdClass');
|
||||
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$this->expectExceptionMessage('The decorated service inner name for "foo" must be different than the service name itself.');
|
||||
} else {
|
||||
$this->setExpectedException('InvalidArgumentException', 'The decorated service inner name for "foo" must be different than the service name itself.');
|
||||
}
|
||||
|
||||
$def->setDecoratedService('foo', 'foo');
|
||||
}
|
||||
|
||||
public function testArguments()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertSame($def, $def->setArguments(array('foo')), '->setArguments() implements a fluent interface');
|
||||
$this->assertEquals(array('foo'), $def->getArguments(), '->getArguments() returns the arguments');
|
||||
$this->assertSame($def, $def->addArgument('bar'), '->addArgument() implements a fluent interface');
|
||||
$this->assertEquals(array('foo', 'bar'), $def->getArguments(), '->addArgument() adds an argument');
|
||||
}
|
||||
|
||||
public function testMethodCalls()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertSame($def, $def->setMethodCalls(array(array('foo', array('foo')))), '->setMethodCalls() implements a fluent interface');
|
||||
$this->assertEquals(array(array('foo', array('foo'))), $def->getMethodCalls(), '->getMethodCalls() returns the methods to call');
|
||||
$this->assertSame($def, $def->addMethodCall('bar', array('bar')), '->addMethodCall() implements a fluent interface');
|
||||
$this->assertEquals(array(array('foo', array('foo')), array('bar', array('bar'))), $def->getMethodCalls(), '->addMethodCall() adds a method to call');
|
||||
$this->assertTrue($def->hasMethodCall('bar'), '->hasMethodCall() returns true if first argument is a method to call registered');
|
||||
$this->assertFalse($def->hasMethodCall('no_registered'), '->hasMethodCall() returns false if first argument is not a method to call registered');
|
||||
$this->assertSame($def, $def->removeMethodCall('bar'), '->removeMethodCall() implements a fluent interface');
|
||||
$this->assertEquals(array(array('foo', array('foo'))), $def->getMethodCalls(), '->removeMethodCall() removes a method to call');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Method name cannot be empty.
|
||||
*/
|
||||
public function testExceptionOnEmptyMethodCall()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$def->addMethodCall('');
|
||||
}
|
||||
|
||||
public function testSetGetFile()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertSame($def, $def->setFile('foo'), '->setFile() implements a fluent interface');
|
||||
$this->assertEquals('foo', $def->getFile(), '->getFile() returns the file to include');
|
||||
}
|
||||
|
||||
public function testSetIsShared()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertTrue($def->isShared(), '->isShared() returns true by default');
|
||||
$this->assertSame($def, $def->setShared(false), '->setShared() implements a fluent interface');
|
||||
$this->assertFalse($def->isShared(), '->isShared() returns false if the instance must not be shared');
|
||||
}
|
||||
|
||||
public function testSetIsPublic()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertTrue($def->isPublic(), '->isPublic() returns true by default');
|
||||
$this->assertSame($def, $def->setPublic(false), '->setPublic() implements a fluent interface');
|
||||
$this->assertFalse($def->isPublic(), '->isPublic() returns false if the instance must not be public.');
|
||||
}
|
||||
|
||||
public function testSetIsSynthetic()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertFalse($def->isSynthetic(), '->isSynthetic() returns false by default');
|
||||
$this->assertSame($def, $def->setSynthetic(true), '->setSynthetic() implements a fluent interface');
|
||||
$this->assertTrue($def->isSynthetic(), '->isSynthetic() returns true if the service is synthetic.');
|
||||
}
|
||||
|
||||
public function testSetIsLazy()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertFalse($def->isLazy(), '->isLazy() returns false by default');
|
||||
$this->assertSame($def, $def->setLazy(true), '->setLazy() implements a fluent interface');
|
||||
$this->assertTrue($def->isLazy(), '->isLazy() returns true if the service is lazy.');
|
||||
}
|
||||
|
||||
public function testSetIsAbstract()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertFalse($def->isAbstract(), '->isAbstract() returns false by default');
|
||||
$this->assertSame($def, $def->setAbstract(true), '->setAbstract() implements a fluent interface');
|
||||
$this->assertTrue($def->isAbstract(), '->isAbstract() returns true if the instance must not be public.');
|
||||
}
|
||||
|
||||
public function testSetIsDeprecated()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertFalse($def->isDeprecated(), '->isDeprecated() returns false by default');
|
||||
$this->assertSame($def, $def->setDeprecated(true), '->setDeprecated() implements a fluent interface');
|
||||
$this->assertTrue($def->isDeprecated(), '->isDeprecated() returns true if the instance should not be used anymore.');
|
||||
$this->assertSame('The "deprecated_service" service is deprecated. You should stop using it, as it will soon be removed.', $def->getDeprecationMessage('deprecated_service'), '->getDeprecationMessage() should return a formatted message template');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidDeprecationMessageProvider
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function testSetDeprecatedWithInvalidDeprecationTemplate($message)
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$def->setDeprecated(false, $message);
|
||||
}
|
||||
|
||||
public function invalidDeprecationMessageProvider()
|
||||
{
|
||||
return array(
|
||||
"With \rs" => array("invalid \r message %service_id%"),
|
||||
"With \ns" => array("invalid \n message %service_id%"),
|
||||
'With */s' => array('invalid */ message %service_id%'),
|
||||
'message not containing require %service_id% variable' => array('this is deprecated'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetGetConfigurator()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertSame($def, $def->setConfigurator('foo'), '->setConfigurator() implements a fluent interface');
|
||||
$this->assertEquals('foo', $def->getConfigurator(), '->getConfigurator() returns the configurator');
|
||||
}
|
||||
|
||||
public function testClearTags()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertSame($def, $def->clearTags(), '->clearTags() implements a fluent interface');
|
||||
$def->addTag('foo', array('foo' => 'bar'));
|
||||
$def->clearTags();
|
||||
$this->assertEquals(array(), $def->getTags(), '->clearTags() removes all current tags');
|
||||
}
|
||||
|
||||
public function testClearTag()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertSame($def, $def->clearTags(), '->clearTags() implements a fluent interface');
|
||||
$def->addTag('1foo1', array('foo1' => 'bar1'));
|
||||
$def->addTag('2foo2', array('foo2' => 'bar2'));
|
||||
$def->addTag('3foo3', array('foo3' => 'bar3'));
|
||||
$def->clearTag('2foo2');
|
||||
$this->assertTrue($def->hasTag('1foo1'));
|
||||
$this->assertFalse($def->hasTag('2foo2'));
|
||||
$this->assertTrue($def->hasTag('3foo3'));
|
||||
$def->clearTag('1foo1');
|
||||
$this->assertFalse($def->hasTag('1foo1'));
|
||||
$this->assertTrue($def->hasTag('3foo3'));
|
||||
}
|
||||
|
||||
public function testTags()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertEquals(array(), $def->getTag('foo'), '->getTag() returns an empty array if the tag is not defined');
|
||||
$this->assertFalse($def->hasTag('foo'));
|
||||
$this->assertSame($def, $def->addTag('foo'), '->addTag() implements a fluent interface');
|
||||
$this->assertTrue($def->hasTag('foo'));
|
||||
$this->assertEquals(array(array()), $def->getTag('foo'), '->getTag() returns attributes for a tag name');
|
||||
$def->addTag('foo', array('foo' => 'bar'));
|
||||
$this->assertEquals(array(array(), array('foo' => 'bar')), $def->getTag('foo'), '->addTag() can adds the same tag several times');
|
||||
$def->addTag('bar', array('bar' => 'bar'));
|
||||
$this->assertEquals($def->getTags(), array(
|
||||
'foo' => array(array(), array('foo' => 'bar')),
|
||||
'bar' => array(array('bar' => 'bar')),
|
||||
), '->getTags() returns all tags');
|
||||
}
|
||||
|
||||
public function testSetArgument()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
|
||||
$def->addArgument('foo');
|
||||
$this->assertSame(array('foo'), $def->getArguments());
|
||||
|
||||
$this->assertSame($def, $def->replaceArgument(0, 'moo'));
|
||||
$this->assertSame(array('moo'), $def->getArguments());
|
||||
|
||||
$def->addArgument('moo');
|
||||
$def
|
||||
->replaceArgument(0, 'foo')
|
||||
->replaceArgument(1, 'bar')
|
||||
;
|
||||
$this->assertSame(array('foo', 'bar'), $def->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \OutOfBoundsException
|
||||
*/
|
||||
public function testGetArgumentShouldCheckBounds()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
|
||||
$def->addArgument('foo');
|
||||
$def->getArgument(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \OutOfBoundsException
|
||||
* @expectedExceptionMessage The index "1" is not in the range [0, 0].
|
||||
*/
|
||||
public function testReplaceArgumentShouldCheckBounds()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
|
||||
$def->addArgument('foo');
|
||||
$def->replaceArgument(1, 'bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \OutOfBoundsException
|
||||
* @expectedExceptionMessage Cannot replace arguments if none have been configured yet.
|
||||
*/
|
||||
public function testReplaceArgumentWithoutExistingArgumentsShouldCheckBounds()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$def->replaceArgument(0, 'bar');
|
||||
}
|
||||
|
||||
public function testSetGetProperties()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
|
||||
$this->assertEquals(array(), $def->getProperties());
|
||||
$this->assertSame($def, $def->setProperties(array('foo' => 'bar')));
|
||||
$this->assertEquals(array('foo' => 'bar'), $def->getProperties());
|
||||
}
|
||||
|
||||
public function testSetProperty()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
|
||||
$this->assertEquals(array(), $def->getProperties());
|
||||
$this->assertSame($def, $def->setProperty('foo', 'bar'));
|
||||
$this->assertEquals(array('foo' => 'bar'), $def->getProperties());
|
||||
}
|
||||
|
||||
public function testAutowired()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertFalse($def->isAutowired());
|
||||
|
||||
$def->setAutowired(true);
|
||||
$this->assertTrue($def->isAutowired());
|
||||
|
||||
$def->setAutowired(false);
|
||||
$this->assertFalse($def->isAutowired());
|
||||
}
|
||||
|
||||
public function testChangesNoChanges()
|
||||
{
|
||||
$def = new Definition();
|
||||
|
||||
$this->assertSame(array(), $def->getChanges());
|
||||
}
|
||||
|
||||
public function testGetChangesWithChanges()
|
||||
{
|
||||
$def = new Definition('stdClass', array('fooarg'));
|
||||
|
||||
$def->setAbstract(true);
|
||||
$def->setAutowired(true);
|
||||
$def->setConfigurator('configuration_func');
|
||||
$def->setDecoratedService(null);
|
||||
$def->setDeprecated(true);
|
||||
$def->setFactory('factory_func');
|
||||
$def->setFile('foo.php');
|
||||
$def->setLazy(true);
|
||||
$def->setPublic(true);
|
||||
$def->setShared(true);
|
||||
$def->setSynthetic(true);
|
||||
// changes aren't tracked for these, class or arguments
|
||||
$def->setInstanceofConditionals(array());
|
||||
$def->addTag('foo_tag');
|
||||
$def->addMethodCall('methodCall');
|
||||
$def->setProperty('fooprop', true);
|
||||
$def->setAutoconfigured(true);
|
||||
|
||||
$this->assertSame(array(
|
||||
'class' => true,
|
||||
'autowired' => true,
|
||||
'configurator' => true,
|
||||
'decorated_service' => true,
|
||||
'deprecated' => true,
|
||||
'factory' => true,
|
||||
'file' => true,
|
||||
'lazy' => true,
|
||||
'public' => true,
|
||||
'shared' => true,
|
||||
'autoconfigured' => true,
|
||||
), $def->getChanges());
|
||||
|
||||
$def->setChanges(array());
|
||||
$this->assertSame(array(), $def->getChanges());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testTypes()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
|
||||
$this->assertEquals(array(), $def->getAutowiringTypes());
|
||||
$this->assertSame($def, $def->setAutowiringTypes(array('Foo')));
|
||||
$this->assertEquals(array('Foo'), $def->getAutowiringTypes());
|
||||
$this->assertSame($def, $def->addAutowiringType('Bar'));
|
||||
$this->assertTrue($def->hasAutowiringType('Bar'));
|
||||
$this->assertSame($def, $def->removeAutowiringType('Foo'));
|
||||
$this->assertEquals(array('Bar'), $def->getAutowiringTypes());
|
||||
}
|
||||
|
||||
public function testShouldAutoconfigure()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertFalse($def->isAutoconfigured());
|
||||
$def->setAutoconfigured(true);
|
||||
$this->assertTrue($def->isAutoconfigured());
|
||||
}
|
||||
|
||||
public function testAddError()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertEmpty($def->getErrors());
|
||||
$def->addError('First error');
|
||||
$def->addError('Second error');
|
||||
$this->assertSame(array('First error', 'Second error'), $def->getErrors());
|
||||
}
|
||||
}
|
74
vendor/symfony/dependency-injection/Tests/Dumper/GraphvizDumperTest.php
vendored
Normal file
74
vendor/symfony/dependency-injection/Tests/Dumper/GraphvizDumperTest.php
vendored
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?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\Dumper;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Dumper\GraphvizDumper;
|
||||
|
||||
class GraphvizDumperTest extends TestCase
|
||||
{
|
||||
protected static $fixturesPath;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$fixturesPath = __DIR__.'/../Fixtures/';
|
||||
}
|
||||
|
||||
public function testDump()
|
||||
{
|
||||
$dumper = new GraphvizDumper($container = new ContainerBuilder());
|
||||
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/graphviz/services1.dot', $dumper->dump(), '->dump() dumps an empty container as an empty dot file');
|
||||
|
||||
$container = include self::$fixturesPath.'/containers/container9.php';
|
||||
$dumper = new GraphvizDumper($container);
|
||||
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services9.dot')), $dumper->dump(), '->dump() dumps services');
|
||||
|
||||
$container = include self::$fixturesPath.'/containers/container10.php';
|
||||
$dumper = new GraphvizDumper($container);
|
||||
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services10.dot')), $dumper->dump(), '->dump() dumps services');
|
||||
|
||||
$container = include self::$fixturesPath.'/containers/container10.php';
|
||||
$dumper = new GraphvizDumper($container);
|
||||
$this->assertEquals($dumper->dump(array(
|
||||
'graph' => array('ratio' => 'normal'),
|
||||
'node' => array('fontsize' => 13, 'fontname' => 'Verdana', 'shape' => 'square'),
|
||||
'edge' => array('fontsize' => 12, 'fontname' => 'Verdana', 'color' => 'white', 'arrowhead' => 'closed', 'arrowsize' => 1),
|
||||
'node.instance' => array('fillcolor' => 'green', 'style' => 'empty'),
|
||||
'node.definition' => array('fillcolor' => 'grey'),
|
||||
'node.missing' => array('fillcolor' => 'red', 'style' => 'empty'),
|
||||
)), str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services10-1.dot')), '->dump() dumps services');
|
||||
}
|
||||
|
||||
public function testDumpWithFrozenContainer()
|
||||
{
|
||||
$container = include self::$fixturesPath.'/containers/container13.php';
|
||||
$dumper = new GraphvizDumper($container);
|
||||
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services13.dot')), $dumper->dump(), '->dump() dumps services');
|
||||
}
|
||||
|
||||
public function testDumpWithFrozenCustomClassContainer()
|
||||
{
|
||||
$container = include self::$fixturesPath.'/containers/container14.php';
|
||||
$dumper = new GraphvizDumper($container);
|
||||
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services14.dot')), $dumper->dump(), '->dump() dumps services');
|
||||
}
|
||||
|
||||
public function testDumpWithUnresolvedParameter()
|
||||
{
|
||||
$container = include self::$fixturesPath.'/containers/container17.php';
|
||||
$dumper = new GraphvizDumper($container);
|
||||
|
||||
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services17.dot')), $dumper->dump(), '->dump() dumps services');
|
||||
}
|
||||
}
|
1134
vendor/symfony/dependency-injection/Tests/Dumper/PhpDumperTest.php
vendored
Normal file
1134
vendor/symfony/dependency-injection/Tests/Dumper/PhpDumperTest.php
vendored
Normal file
File diff suppressed because it is too large
Load diff
210
vendor/symfony/dependency-injection/Tests/Dumper/XmlDumperTest.php
vendored
Normal file
210
vendor/symfony/dependency-injection/Tests/Dumper/XmlDumperTest.php
vendored
Normal file
|
@ -0,0 +1,210 @@
|
|||
<?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\Dumper;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Dumper\XmlDumper;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class XmlDumperTest extends TestCase
|
||||
{
|
||||
protected static $fixturesPath;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$fixturesPath = realpath(__DIR__.'/../Fixtures/');
|
||||
}
|
||||
|
||||
public function testDump()
|
||||
{
|
||||
$dumper = new XmlDumper(new ContainerBuilder());
|
||||
|
||||
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/xml/services1.xml', $dumper->dump(), '->dump() dumps an empty container as an empty XML file');
|
||||
}
|
||||
|
||||
public function testExportParameters()
|
||||
{
|
||||
$container = include self::$fixturesPath.'//containers/container8.php';
|
||||
$dumper = new XmlDumper($container);
|
||||
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/xml/services8.xml', $dumper->dump(), '->dump() dumps parameters');
|
||||
}
|
||||
|
||||
public function testAddParameters()
|
||||
{
|
||||
$container = include self::$fixturesPath.'//containers/container8.php';
|
||||
$dumper = new XmlDumper($container);
|
||||
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/xml/services8.xml', $dumper->dump(), '->dump() dumps parameters');
|
||||
}
|
||||
|
||||
public function testAddService()
|
||||
{
|
||||
$container = include self::$fixturesPath.'/containers/container9.php';
|
||||
$dumper = new XmlDumper($container);
|
||||
|
||||
$this->assertEquals(str_replace('%path%', self::$fixturesPath.\DIRECTORY_SEPARATOR.'includes'.\DIRECTORY_SEPARATOR, file_get_contents(self::$fixturesPath.'/xml/services9.xml')), $dumper->dump(), '->dump() dumps services');
|
||||
|
||||
$dumper = new XmlDumper($container = new ContainerBuilder());
|
||||
$container->register('foo', 'FooClass')->addArgument(new \stdClass())->setPublic(true);
|
||||
try {
|
||||
$dumper->dump();
|
||||
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\RuntimeException', $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
|
||||
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
|
||||
}
|
||||
}
|
||||
|
||||
public function testDumpAnonymousServices()
|
||||
{
|
||||
$container = include self::$fixturesPath.'/containers/container11.php';
|
||||
$dumper = new XmlDumper($container);
|
||||
$this->assertEquals('<?xml version="1.0" encoding="utf-8"?>
|
||||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
<services>
|
||||
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true"/>
|
||||
<service id="foo" class="FooClass" public="true">
|
||||
<argument type="service">
|
||||
<service class="BarClass">
|
||||
<argument type="service">
|
||||
<service class="BazClass"/>
|
||||
</argument>
|
||||
</service>
|
||||
</argument>
|
||||
</service>
|
||||
<service id="Psr\Container\ContainerInterface" alias="service_container" public="false"/>
|
||||
<service id="Symfony\Component\DependencyInjection\ContainerInterface" alias="service_container" public="false"/>
|
||||
</services>
|
||||
</container>
|
||||
', $dumper->dump());
|
||||
}
|
||||
|
||||
public function testDumpEntities()
|
||||
{
|
||||
$container = include self::$fixturesPath.'/containers/container12.php';
|
||||
$dumper = new XmlDumper($container);
|
||||
$this->assertEquals("<?xml version=\"1.0\" encoding=\"utf-8\"?>
|
||||
<container xmlns=\"http://symfony.com/schema/dic/services\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd\">
|
||||
<services>
|
||||
<service id=\"service_container\" class=\"Symfony\Component\DependencyInjection\ContainerInterface\" public=\"true\" synthetic=\"true\"/>
|
||||
<service id=\"foo\" class=\"FooClass\Foo\" public=\"true\">
|
||||
<tag name=\"foo"bar\bar\" foo=\"foo"barřž€\"/>
|
||||
<argument>foo<>&bar</argument>
|
||||
</service>
|
||||
<service id=\"Psr\Container\ContainerInterface\" alias=\"service_container\" public=\"false\"/>
|
||||
<service id=\"Symfony\Component\DependencyInjection\ContainerInterface\" alias=\"service_container\" public=\"false\"/>
|
||||
</services>
|
||||
</container>
|
||||
", $dumper->dump());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDecoratedServicesData
|
||||
*/
|
||||
public function testDumpDecoratedServices($expectedXmlDump, $container)
|
||||
{
|
||||
$dumper = new XmlDumper($container);
|
||||
$this->assertEquals($expectedXmlDump, $dumper->dump());
|
||||
}
|
||||
|
||||
public function provideDecoratedServicesData()
|
||||
{
|
||||
$fixturesPath = realpath(__DIR__.'/../Fixtures/');
|
||||
|
||||
return array(
|
||||
array("<?xml version=\"1.0\" encoding=\"utf-8\"?>
|
||||
<container xmlns=\"http://symfony.com/schema/dic/services\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd\">
|
||||
<services>
|
||||
<service id=\"service_container\" class=\"Symfony\Component\DependencyInjection\ContainerInterface\" public=\"true\" synthetic=\"true\"/>
|
||||
<service id=\"foo\" class=\"FooClass\Foo\" public=\"true\" decorates=\"bar\" decoration-inner-name=\"bar.woozy\"/>
|
||||
<service id=\"Psr\Container\ContainerInterface\" alias=\"service_container\" public=\"false\"/>
|
||||
<service id=\"Symfony\Component\DependencyInjection\ContainerInterface\" alias=\"service_container\" public=\"false\"/>
|
||||
</services>
|
||||
</container>
|
||||
", include $fixturesPath.'/containers/container15.php'),
|
||||
array("<?xml version=\"1.0\" encoding=\"utf-8\"?>
|
||||
<container xmlns=\"http://symfony.com/schema/dic/services\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd\">
|
||||
<services>
|
||||
<service id=\"service_container\" class=\"Symfony\Component\DependencyInjection\ContainerInterface\" public=\"true\" synthetic=\"true\"/>
|
||||
<service id=\"foo\" class=\"FooClass\Foo\" public=\"true\" decorates=\"bar\"/>
|
||||
<service id=\"Psr\Container\ContainerInterface\" alias=\"service_container\" public=\"false\"/>
|
||||
<service id=\"Symfony\Component\DependencyInjection\ContainerInterface\" alias=\"service_container\" public=\"false\"/>
|
||||
</services>
|
||||
</container>
|
||||
", include $fixturesPath.'/containers/container16.php'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideCompiledContainerData
|
||||
*/
|
||||
public function testCompiledContainerCanBeDumped($containerFile)
|
||||
{
|
||||
$fixturesPath = __DIR__.'/../Fixtures';
|
||||
$container = require $fixturesPath.'/containers/'.$containerFile.'.php';
|
||||
$container->compile();
|
||||
$dumper = new XmlDumper($container);
|
||||
$dumper->dump();
|
||||
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function provideCompiledContainerData()
|
||||
{
|
||||
return array(
|
||||
array('container8'),
|
||||
array('container9'),
|
||||
array('container11'),
|
||||
array('container12'),
|
||||
array('container14'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testDumpInlinedServices()
|
||||
{
|
||||
$container = include self::$fixturesPath.'/containers/container21.php';
|
||||
$dumper = new XmlDumper($container);
|
||||
|
||||
$this->assertEquals(file_get_contents(self::$fixturesPath.'/xml/services21.xml'), $dumper->dump());
|
||||
}
|
||||
|
||||
public function testDumpAutowireData()
|
||||
{
|
||||
$container = include self::$fixturesPath.'/containers/container24.php';
|
||||
$dumper = new XmlDumper($container);
|
||||
|
||||
$this->assertEquals(file_get_contents(self::$fixturesPath.'/xml/services24.xml'), $dumper->dump());
|
||||
}
|
||||
|
||||
public function testDumpLoad()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
|
||||
$loader->load('services_dump_load.xml');
|
||||
|
||||
$this->assertEquals(array(new Reference('bar', ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE)), $container->getDefinition('foo')->getArguments());
|
||||
|
||||
$dumper = new XmlDumper($container);
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/xml/services_dump_load.xml', $dumper->dump());
|
||||
}
|
||||
|
||||
public function testDumpAbstractServices()
|
||||
{
|
||||
$container = include self::$fixturesPath.'/containers/container_abstract.php';
|
||||
$dumper = new XmlDumper($container);
|
||||
|
||||
$this->assertEquals(file_get_contents(self::$fixturesPath.'/xml/services_abstract.xml'), $dumper->dump());
|
||||
}
|
||||
}
|
104
vendor/symfony/dependency-injection/Tests/Dumper/YamlDumperTest.php
vendored
Normal file
104
vendor/symfony/dependency-injection/Tests/Dumper/YamlDumperTest.php
vendored
Normal file
|
@ -0,0 +1,104 @@
|
|||
<?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\Dumper;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Dumper\YamlDumper;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\Yaml\Parser;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class YamlDumperTest extends TestCase
|
||||
{
|
||||
protected static $fixturesPath;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$fixturesPath = realpath(__DIR__.'/../Fixtures/');
|
||||
}
|
||||
|
||||
public function testDump()
|
||||
{
|
||||
$dumper = new YamlDumper($container = new ContainerBuilder());
|
||||
|
||||
$this->assertEqualYamlStructure(file_get_contents(self::$fixturesPath.'/yaml/services1.yml'), $dumper->dump(), '->dump() dumps an empty container as an empty YAML file');
|
||||
}
|
||||
|
||||
public function testAddParameters()
|
||||
{
|
||||
$container = include self::$fixturesPath.'/containers/container8.php';
|
||||
$dumper = new YamlDumper($container);
|
||||
$this->assertEqualYamlStructure(file_get_contents(self::$fixturesPath.'/yaml/services8.yml'), $dumper->dump(), '->dump() dumps parameters');
|
||||
}
|
||||
|
||||
public function testAddService()
|
||||
{
|
||||
$container = include self::$fixturesPath.'/containers/container9.php';
|
||||
$dumper = new YamlDumper($container);
|
||||
$this->assertEqualYamlStructure(str_replace('%path%', self::$fixturesPath.\DIRECTORY_SEPARATOR.'includes'.\DIRECTORY_SEPARATOR, file_get_contents(self::$fixturesPath.'/yaml/services9.yml')), $dumper->dump(), '->dump() dumps services');
|
||||
|
||||
$dumper = new YamlDumper($container = new ContainerBuilder());
|
||||
$container->register('foo', 'FooClass')->addArgument(new \stdClass())->setPublic(true);
|
||||
try {
|
||||
$dumper->dump();
|
||||
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\RuntimeException', $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
|
||||
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
|
||||
}
|
||||
}
|
||||
|
||||
public function testDumpAutowireData()
|
||||
{
|
||||
$container = include self::$fixturesPath.'/containers/container24.php';
|
||||
$dumper = new YamlDumper($container);
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services24.yml', $dumper->dump());
|
||||
}
|
||||
|
||||
public function testDumpLoad()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
|
||||
$loader->load('services_dump_load.yml');
|
||||
|
||||
$this->assertEquals(array(new Reference('bar', ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE)), $container->getDefinition('foo')->getArguments());
|
||||
|
||||
$dumper = new YamlDumper($container);
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services_dump_load.yml', $dumper->dump());
|
||||
}
|
||||
|
||||
public function testInlineServices()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('foo', 'Class1')
|
||||
->setPublic(true)
|
||||
->addArgument((new Definition('Class2'))
|
||||
->addArgument(new Definition('Class2'))
|
||||
)
|
||||
;
|
||||
|
||||
$dumper = new YamlDumper($container);
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services_inline.yml', $dumper->dump());
|
||||
}
|
||||
|
||||
private function assertEqualYamlStructure($expected, $yaml, $message = '')
|
||||
{
|
||||
$parser = new Parser();
|
||||
|
||||
$this->assertEquals($parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS), $parser->parse($yaml, Yaml::PARSE_CUSTOM_TAGS), $message);
|
||||
}
|
||||
}
|
304
vendor/symfony/dependency-injection/Tests/EnvVarProcessorTest.php
vendored
Normal file
304
vendor/symfony/dependency-injection/Tests/EnvVarProcessorTest.php
vendored
Normal file
|
@ -0,0 +1,304 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\EnvVarProcessor;
|
||||
|
||||
class EnvVarProcessorTest extends TestCase
|
||||
{
|
||||
const TEST_CONST = 'test';
|
||||
|
||||
/**
|
||||
* @dataProvider validStrings
|
||||
*/
|
||||
public function testGetEnvString($value, $processed)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setParameter('env(foo)', $value);
|
||||
$container->compile();
|
||||
|
||||
$processor = new EnvVarProcessor($container);
|
||||
|
||||
$result = $processor->getEnv('string', 'foo', function () {
|
||||
$this->fail('Should not be called');
|
||||
});
|
||||
|
||||
$this->assertSame($processed, $result);
|
||||
}
|
||||
|
||||
public function validStrings()
|
||||
{
|
||||
return array(
|
||||
array('hello', 'hello'),
|
||||
array('true', 'true'),
|
||||
array('false', 'false'),
|
||||
array('null', 'null'),
|
||||
array('1', '1'),
|
||||
array('0', '0'),
|
||||
array('1.1', '1.1'),
|
||||
array('1e1', '1e1'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validBools
|
||||
*/
|
||||
public function testGetEnvBool($value, $processed)
|
||||
{
|
||||
$processor = new EnvVarProcessor(new Container());
|
||||
|
||||
$result = $processor->getEnv('bool', 'foo', function ($name) use ($value) {
|
||||
$this->assertSame('foo', $name);
|
||||
|
||||
return $value;
|
||||
});
|
||||
|
||||
$this->assertSame($processed, $result);
|
||||
}
|
||||
|
||||
public function validBools()
|
||||
{
|
||||
return array(
|
||||
array('true', true),
|
||||
array('false', false),
|
||||
array('null', false),
|
||||
array('1', true),
|
||||
array('0', false),
|
||||
array('1.1', true),
|
||||
array('1e1', true),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validInts
|
||||
*/
|
||||
public function testGetEnvInt($value, $processed)
|
||||
{
|
||||
$processor = new EnvVarProcessor(new Container());
|
||||
|
||||
$result = $processor->getEnv('int', 'foo', function ($name) use ($value) {
|
||||
$this->assertSame('foo', $name);
|
||||
|
||||
return $value;
|
||||
});
|
||||
|
||||
$this->assertSame($processed, $result);
|
||||
}
|
||||
|
||||
public function validInts()
|
||||
{
|
||||
return array(
|
||||
array('1', 1),
|
||||
array('1.1', 1),
|
||||
array('1e1', 10),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Non-numeric env var
|
||||
* @dataProvider invalidInts
|
||||
*/
|
||||
public function testGetEnvIntInvalid($value)
|
||||
{
|
||||
$processor = new EnvVarProcessor(new Container());
|
||||
|
||||
$processor->getEnv('int', 'foo', function ($name) use ($value) {
|
||||
$this->assertSame('foo', $name);
|
||||
|
||||
return $value;
|
||||
});
|
||||
}
|
||||
|
||||
public function invalidInts()
|
||||
{
|
||||
return array(
|
||||
array('foo'),
|
||||
array('true'),
|
||||
array('null'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validFloats
|
||||
*/
|
||||
public function testGetEnvFloat($value, $processed)
|
||||
{
|
||||
$processor = new EnvVarProcessor(new Container());
|
||||
|
||||
$result = $processor->getEnv('float', 'foo', function ($name) use ($value) {
|
||||
$this->assertSame('foo', $name);
|
||||
|
||||
return $value;
|
||||
});
|
||||
|
||||
$this->assertSame($processed, $result);
|
||||
}
|
||||
|
||||
public function validFloats()
|
||||
{
|
||||
return array(
|
||||
array('1', 1.0),
|
||||
array('1.1', 1.1),
|
||||
array('1e1', 10.0),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Non-numeric env var
|
||||
* @dataProvider invalidFloats
|
||||
*/
|
||||
public function testGetEnvFloatInvalid($value)
|
||||
{
|
||||
$processor = new EnvVarProcessor(new Container());
|
||||
|
||||
$processor->getEnv('float', 'foo', function ($name) use ($value) {
|
||||
$this->assertSame('foo', $name);
|
||||
|
||||
return $value;
|
||||
});
|
||||
}
|
||||
|
||||
public function invalidFloats()
|
||||
{
|
||||
return array(
|
||||
array('foo'),
|
||||
array('true'),
|
||||
array('null'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validConsts
|
||||
*/
|
||||
public function testGetEnvConst($value, $processed)
|
||||
{
|
||||
$processor = new EnvVarProcessor(new Container());
|
||||
|
||||
$result = $processor->getEnv('const', 'foo', function ($name) use ($value) {
|
||||
$this->assertSame('foo', $name);
|
||||
|
||||
return $value;
|
||||
});
|
||||
|
||||
$this->assertSame($processed, $result);
|
||||
}
|
||||
|
||||
public function validConsts()
|
||||
{
|
||||
return array(
|
||||
array('Symfony\Component\DependencyInjection\Tests\EnvVarProcessorTest::TEST_CONST', self::TEST_CONST),
|
||||
array('E_ERROR', E_ERROR),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessage undefined constant
|
||||
* @dataProvider invalidConsts
|
||||
*/
|
||||
public function testGetEnvConstInvalid($value)
|
||||
{
|
||||
$processor = new EnvVarProcessor(new Container());
|
||||
|
||||
$processor->getEnv('const', 'foo', function ($name) use ($value) {
|
||||
$this->assertSame('foo', $name);
|
||||
|
||||
return $value;
|
||||
});
|
||||
}
|
||||
|
||||
public function invalidConsts()
|
||||
{
|
||||
return array(
|
||||
array('Symfony\Component\DependencyInjection\Tests\EnvVarProcessorTest::UNDEFINED_CONST'),
|
||||
array('UNDEFINED_CONST'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetEnvBase64()
|
||||
{
|
||||
$processor = new EnvVarProcessor(new Container());
|
||||
|
||||
$result = $processor->getEnv('base64', 'foo', function ($name) {
|
||||
$this->assertSame('foo', $name);
|
||||
|
||||
return base64_encode('hello');
|
||||
});
|
||||
|
||||
$this->assertSame('hello', $result);
|
||||
}
|
||||
|
||||
public function testGetEnvJson()
|
||||
{
|
||||
$processor = new EnvVarProcessor(new Container());
|
||||
|
||||
$result = $processor->getEnv('json', 'foo', function ($name) {
|
||||
$this->assertSame('foo', $name);
|
||||
|
||||
return json_encode(array(1));
|
||||
});
|
||||
|
||||
$this->assertSame(array(1), $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Syntax error
|
||||
*/
|
||||
public function testGetEnvInvalidJson()
|
||||
{
|
||||
$processor = new EnvVarProcessor(new Container());
|
||||
|
||||
$processor->getEnv('json', 'foo', function ($name) {
|
||||
$this->assertSame('foo', $name);
|
||||
|
||||
return 'invalid_json';
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Invalid JSON env var
|
||||
* @dataProvider otherJsonValues
|
||||
*/
|
||||
public function testGetEnvJsonOther($value)
|
||||
{
|
||||
$processor = new EnvVarProcessor(new Container());
|
||||
|
||||
$processor->getEnv('json', 'foo', function ($name) use ($value) {
|
||||
$this->assertSame('foo', $name);
|
||||
|
||||
return json_encode($value);
|
||||
});
|
||||
}
|
||||
|
||||
public function otherJsonValues()
|
||||
{
|
||||
return array(
|
||||
array(1),
|
||||
array(1.1),
|
||||
array(true),
|
||||
array(false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Unsupported env var prefix
|
||||
*/
|
||||
public function testGetEnvUnknown()
|
||||
{
|
||||
$processor = new EnvVarProcessor(new Container());
|
||||
|
||||
$processor->getEnv('unknown', 'foo', function ($name) {
|
||||
$this->assertSame('foo', $name);
|
||||
|
||||
return 'foo';
|
||||
});
|
||||
}
|
||||
}
|
59
vendor/symfony/dependency-injection/Tests/Extension/ExtensionTest.php
vendored
Normal file
59
vendor/symfony/dependency-injection/Tests/Extension/ExtensionTest.php
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?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\Extension;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||
|
||||
class ExtensionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getResolvedEnabledFixtures
|
||||
*/
|
||||
public function testIsConfigEnabledReturnsTheResolvedValue($enabled)
|
||||
{
|
||||
$extension = new EnableableExtension();
|
||||
$this->assertSame($enabled, $extension->isConfigEnabled(new ContainerBuilder(), array('enabled' => $enabled)));
|
||||
}
|
||||
|
||||
public function getResolvedEnabledFixtures()
|
||||
{
|
||||
return array(
|
||||
array(true),
|
||||
array(false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage The config array has no 'enabled' key.
|
||||
*/
|
||||
public function testIsConfigEnabledOnNonEnableableConfig()
|
||||
{
|
||||
$extension = new EnableableExtension();
|
||||
|
||||
$extension->isConfigEnabled(new ContainerBuilder(), array());
|
||||
}
|
||||
}
|
||||
|
||||
class EnableableExtension extends Extension
|
||||
{
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
}
|
||||
|
||||
public function isConfigEnabled(ContainerBuilder $container, array $config)
|
||||
{
|
||||
return parent::isConfigEnabled($container, $config);
|
||||
}
|
||||
}
|
23
vendor/symfony/dependency-injection/Tests/Fixtures/Bar.php
vendored
Normal file
23
vendor/symfony/dependency-injection/Tests/Fixtures/Bar.php
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?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\Fixtures;
|
||||
|
||||
class Bar implements BarInterface
|
||||
{
|
||||
public function __construct($quz = null, \NonExistent $nonExistent = null, BarInterface $decorated = null, array $foo = array())
|
||||
{
|
||||
}
|
||||
|
||||
public static function create(\NonExistent $nonExistent = null, $factory = null)
|
||||
{
|
||||
}
|
||||
}
|
16
vendor/symfony/dependency-injection/Tests/Fixtures/BarInterface.php
vendored
Normal file
16
vendor/symfony/dependency-injection/Tests/Fixtures/BarInterface.php
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?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\Fixtures;
|
||||
|
||||
interface BarInterface
|
||||
{
|
||||
}
|
22
vendor/symfony/dependency-injection/Tests/Fixtures/CaseSensitiveClass.php
vendored
Normal file
22
vendor/symfony/dependency-injection/Tests/Fixtures/CaseSensitiveClass.php
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?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\Fixtures;
|
||||
|
||||
class CaseSensitiveClass
|
||||
{
|
||||
public $identifier;
|
||||
|
||||
public function __construct($identifier = null)
|
||||
{
|
||||
$this->identifier = $identifier;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container;
|
||||
|
||||
class ConstructorWithMandatoryArgumentsContainer
|
||||
{
|
||||
public function __construct($mandatoryArgument)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container;
|
||||
|
||||
class ConstructorWithOptionalArgumentsContainer
|
||||
{
|
||||
public function __construct($optionalArgument = 'foo')
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container;
|
||||
|
||||
class ConstructorWithoutArgumentsContainer
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
}
|
9
vendor/symfony/dependency-injection/Tests/Fixtures/Container/NoConstructorContainer.php
vendored
Normal file
9
vendor/symfony/dependency-injection/Tests/Fixtures/Container/NoConstructorContainer.php
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
|
||||
class NoConstructorContainer extends Container
|
||||
{
|
||||
}
|
18
vendor/symfony/dependency-injection/Tests/Fixtures/CustomDefinition.php
vendored
Normal file
18
vendor/symfony/dependency-injection/Tests/Fixtures/CustomDefinition.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\Fixtures;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
class CustomDefinition extends Definition
|
||||
{
|
||||
}
|
18
vendor/symfony/dependency-injection/Tests/Fixtures/DeprecatedClass.php
vendored
Normal file
18
vendor/symfony/dependency-injection/Tests/Fixtures/DeprecatedClass.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\Fixtures;
|
||||
|
||||
@trigger_error('deprecated', E_USER_DEPRECATED);
|
||||
|
||||
class DeprecatedClass
|
||||
{
|
||||
}
|
44
vendor/symfony/dependency-injection/Tests/Fixtures/FactoryDummy.php
vendored
Normal file
44
vendor/symfony/dependency-injection/Tests/Fixtures/FactoryDummy.php
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?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\Fixtures;
|
||||
|
||||
class FactoryDummy extends FactoryParent
|
||||
{
|
||||
public static function createFactory(): FactoryDummy
|
||||
{
|
||||
}
|
||||
|
||||
public function create(): \stdClass
|
||||
{
|
||||
}
|
||||
|
||||
// Not supported by hhvm
|
||||
public function createBuiltin(): int
|
||||
{
|
||||
}
|
||||
|
||||
public static function createSelf(): self
|
||||
{
|
||||
}
|
||||
|
||||
public static function createParent(): parent
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class FactoryParent
|
||||
{
|
||||
}
|
||||
|
||||
function factoryFunction(): FactoryDummy
|
||||
{
|
||||
}
|
21
vendor/symfony/dependency-injection/Tests/Fixtures/NamedArgumentsDummy.php
vendored
Normal file
21
vendor/symfony/dependency-injection/Tests/Fixtures/NamedArgumentsDummy.php
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
|
||||
|
||||
/**
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class NamedArgumentsDummy
|
||||
{
|
||||
public function __construct(CaseSensitiveClass $c, $apiKey, $hostName)
|
||||
{
|
||||
}
|
||||
|
||||
public function setApiKey($apiKey)
|
||||
{
|
||||
}
|
||||
|
||||
public function setSensitiveClass(CaseSensitiveClass $c)
|
||||
{
|
||||
}
|
||||
}
|
7
vendor/symfony/dependency-injection/Tests/Fixtures/ParentNotExists.php
vendored
Normal file
7
vendor/symfony/dependency-injection/Tests/Fixtures/ParentNotExists.php
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
|
||||
|
||||
class ParentNotExists extends \NotExists
|
||||
{
|
||||
}
|
7
vendor/symfony/dependency-injection/Tests/Fixtures/Prototype/BadClasses/MissingParent.php
vendored
Normal file
7
vendor/symfony/dependency-injection/Tests/Fixtures/Prototype/BadClasses/MissingParent.php
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses;
|
||||
|
||||
class MissingParent extends MissingClass
|
||||
{
|
||||
}
|
14
vendor/symfony/dependency-injection/Tests/Fixtures/Prototype/Foo.php
vendored
Normal file
14
vendor/symfony/dependency-injection/Tests/Fixtures/Prototype/Foo.php
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype;
|
||||
|
||||
class Foo implements FooInterface, Sub\BarInterface
|
||||
{
|
||||
public function __construct($bar = null)
|
||||
{
|
||||
}
|
||||
|
||||
public function setFoo(self $foo)
|
||||
{
|
||||
}
|
||||
}
|
7
vendor/symfony/dependency-injection/Tests/Fixtures/Prototype/FooInterface.php
vendored
Normal file
7
vendor/symfony/dependency-injection/Tests/Fixtures/Prototype/FooInterface.php
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype;
|
||||
|
||||
interface FooInterface
|
||||
{
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\OtherDir\AnotherSub;
|
||||
|
||||
class DeeperBaz
|
||||
{
|
||||
}
|
7
vendor/symfony/dependency-injection/Tests/Fixtures/Prototype/OtherDir/Baz.php
vendored
Normal file
7
vendor/symfony/dependency-injection/Tests/Fixtures/Prototype/OtherDir/Baz.php
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\OtherDir;
|
||||
|
||||
class Baz
|
||||
{
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\OtherDir\Component1\Dir1;
|
||||
|
||||
class Service1
|
||||
{
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\OtherDir\Component1\Dir2;
|
||||
|
||||
class Service2
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\OtherDir\Component1\Dir3;
|
||||
|
||||
class Service3
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\OtherDir\Component2\Dir1;
|
||||
|
||||
class Service4
|
||||
{
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\OtherDir\Component2\Dir2;
|
||||
|
||||
class Service5
|
||||
{
|
||||
|
||||
}
|
7
vendor/symfony/dependency-injection/Tests/Fixtures/Prototype/Sub/Bar.php
vendored
Normal file
7
vendor/symfony/dependency-injection/Tests/Fixtures/Prototype/Sub/Bar.php
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub;
|
||||
|
||||
class Bar implements BarInterface
|
||||
{
|
||||
}
|
7
vendor/symfony/dependency-injection/Tests/Fixtures/Prototype/Sub/BarInterface.php
vendored
Normal file
7
vendor/symfony/dependency-injection/Tests/Fixtures/Prototype/Sub/BarInterface.php
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub;
|
||||
|
||||
interface BarInterface
|
||||
{
|
||||
}
|
7
vendor/symfony/dependency-injection/Tests/Fixtures/Prototype/Sub/NoLoadAbstractBar.php
vendored
Normal file
7
vendor/symfony/dependency-injection/Tests/Fixtures/Prototype/Sub/NoLoadAbstractBar.php
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub;
|
||||
|
||||
abstract class NoLoadAbstractBar
|
||||
{
|
||||
}
|
7
vendor/symfony/dependency-injection/Tests/Fixtures/Prototype/Sub/NoLoadBarInterface.php
vendored
Normal file
7
vendor/symfony/dependency-injection/Tests/Fixtures/Prototype/Sub/NoLoadBarInterface.php
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub;
|
||||
|
||||
interface NoLoadBarInterface
|
||||
{
|
||||
}
|
7
vendor/symfony/dependency-injection/Tests/Fixtures/Prototype/Sub/NoLoadBarTrait.php
vendored
Normal file
7
vendor/symfony/dependency-injection/Tests/Fixtures/Prototype/Sub/NoLoadBarTrait.php
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub;
|
||||
|
||||
trait NoLoadBarTrait
|
||||
{
|
||||
}
|
24
vendor/symfony/dependency-injection/Tests/Fixtures/SimilarArgumentsDummy.php
vendored
Normal file
24
vendor/symfony/dependency-injection/Tests/Fixtures/SimilarArgumentsDummy.php
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?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\Fixtures;
|
||||
|
||||
class SimilarArgumentsDummy
|
||||
{
|
||||
public $class1;
|
||||
public $class2;
|
||||
|
||||
public function __construct(CaseSensitiveClass $class1, $token, CaseSensitiveClass $class2)
|
||||
{
|
||||
$this->class1 = $class1;
|
||||
$this->class2 = $class2;
|
||||
}
|
||||
}
|
29
vendor/symfony/dependency-injection/Tests/Fixtures/StubbedTranslator.php
vendored
Normal file
29
vendor/symfony/dependency-injection/Tests/Fixtures/StubbedTranslator.php
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?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\Fixtures;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* @author Iltar van der Berg <kjarli@gmail.com>
|
||||
*/
|
||||
class StubbedTranslator
|
||||
{
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function addResource($format, $resource, $locale, $domain = null)
|
||||
{
|
||||
}
|
||||
}
|
22
vendor/symfony/dependency-injection/Tests/Fixtures/TestServiceSubscriber.php
vendored
Normal file
22
vendor/symfony/dependency-injection/Tests/Fixtures/TestServiceSubscriber.php
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
|
||||
|
||||
class TestServiceSubscriber implements ServiceSubscriberInterface
|
||||
{
|
||||
public function __construct($container)
|
||||
{
|
||||
}
|
||||
|
||||
public static function getSubscribedServices()
|
||||
{
|
||||
return array(
|
||||
__CLASS__,
|
||||
'?'.CustomDefinition::class,
|
||||
'bar' => CustomDefinition::class,
|
||||
'baz' => '?'.CustomDefinition::class,
|
||||
);
|
||||
}
|
||||
}
|
1
vendor/symfony/dependency-injection/Tests/Fixtures/array.json
vendored
Normal file
1
vendor/symfony/dependency-injection/Tests/Fixtures/array.json
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
[123, "abc"]
|
10
vendor/symfony/dependency-injection/Tests/Fixtures/config/basic.expected.yml
vendored
Normal file
10
vendor/symfony/dependency-injection/Tests/Fixtures/config/basic.expected.yml
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
services:
|
||||
service_container:
|
||||
class: Symfony\Component\DependencyInjection\ContainerInterface
|
||||
public: true
|
||||
synthetic: true
|
||||
App\BarService:
|
||||
class: App\BarService
|
||||
public: true
|
||||
arguments: [!service { class: FooClass }]
|
11
vendor/symfony/dependency-injection/Tests/Fixtures/config/basic.php
vendored
Normal file
11
vendor/symfony/dependency-injection/Tests/Fixtures/config/basic.php
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
|
||||
|
||||
use App\BarService;
|
||||
|
||||
return function (ContainerConfigurator $c) {
|
||||
$s = $c->services();
|
||||
$s->set(BarService::class)
|
||||
->args(array(inline('FooClass')));
|
||||
};
|
15
vendor/symfony/dependency-injection/Tests/Fixtures/config/child.expected.yml
vendored
Normal file
15
vendor/symfony/dependency-injection/Tests/Fixtures/config/child.expected.yml
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
services:
|
||||
service_container:
|
||||
class: Symfony\Component\DependencyInjection\ContainerInterface
|
||||
public: true
|
||||
synthetic: true
|
||||
foo:
|
||||
class: Class2
|
||||
public: true
|
||||
file: file.php
|
||||
lazy: true
|
||||
arguments: [!service { class: Class1, public: false }]
|
||||
bar:
|
||||
alias: foo
|
||||
public: true
|
22
vendor/symfony/dependency-injection/Tests/Fixtures/config/child.php
vendored
Normal file
22
vendor/symfony/dependency-injection/Tests/Fixtures/config/child.php
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
|
||||
|
||||
use App\BarService;
|
||||
|
||||
return function (ContainerConfigurator $c) {
|
||||
$c->services()
|
||||
->set('bar', 'Class1')
|
||||
->set(BarService::class)
|
||||
->abstract(true)
|
||||
->lazy()
|
||||
->set('foo')
|
||||
->parent(BarService::class)
|
||||
->decorate('bar', 'b', 1)
|
||||
->args(array(ref('b')))
|
||||
->class('Class2')
|
||||
->file('file.php')
|
||||
->parent('bar')
|
||||
->parent(BarService::class)
|
||||
;
|
||||
};
|
27
vendor/symfony/dependency-injection/Tests/Fixtures/config/defaults.expected.yml
vendored
Normal file
27
vendor/symfony/dependency-injection/Tests/Fixtures/config/defaults.expected.yml
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
|
||||
services:
|
||||
service_container:
|
||||
class: Symfony\Component\DependencyInjection\ContainerInterface
|
||||
public: true
|
||||
synthetic: true
|
||||
App\BarService:
|
||||
class: App\BarService
|
||||
public: true
|
||||
arguments: [!service { class: FooClass }]
|
||||
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
|
||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
||||
public: true
|
||||
tags:
|
||||
- { name: t, a: b }
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
arguments: ['@bar']
|
||||
bar:
|
||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
||||
public: false
|
||||
tags:
|
||||
- { name: t, a: b }
|
||||
autowire: true
|
||||
calls:
|
||||
- [setFoo, ['@bar']]
|
||||
|
21
vendor/symfony/dependency-injection/Tests/Fixtures/config/defaults.php
vendored
Normal file
21
vendor/symfony/dependency-injection/Tests/Fixtures/config/defaults.php
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo;
|
||||
|
||||
return function (ContainerConfigurator $c) {
|
||||
$c->import('basic.php');
|
||||
|
||||
$s = $c->services()->defaults()
|
||||
->public()
|
||||
->private()
|
||||
->autoconfigure()
|
||||
->autowire()
|
||||
->tag('t', array('a' => 'b'))
|
||||
->bind(Foo::class, ref('bar'))
|
||||
->private();
|
||||
|
||||
$s->set(Foo::class)->args(array(ref('bar')))->public();
|
||||
$s->set('bar', Foo::class)->call('setFoo')->autoconfigure(false);
|
||||
};
|
9
vendor/symfony/dependency-injection/Tests/Fixtures/config/factory_short_notation.php
vendored
Normal file
9
vendor/symfony/dependency-injection/Tests/Fixtures/config/factory_short_notation.php
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
|
||||
|
||||
return function (ContainerConfigurator $c) {
|
||||
$c->services()
|
||||
->set('service', \stdClass::class)
|
||||
->factory('factory:method');
|
||||
};
|
21
vendor/symfony/dependency-injection/Tests/Fixtures/config/instanceof.expected.yml
vendored
Normal file
21
vendor/symfony/dependency-injection/Tests/Fixtures/config/instanceof.expected.yml
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
|
||||
services:
|
||||
service_container:
|
||||
class: Symfony\Component\DependencyInjection\ContainerInterface
|
||||
public: true
|
||||
synthetic: true
|
||||
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
|
||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
||||
public: true
|
||||
tags:
|
||||
- { name: tag, k: v }
|
||||
lazy: true
|
||||
properties: { p: 1 }
|
||||
calls:
|
||||
- [setFoo, ['@foo']]
|
||||
|
||||
shared: false
|
||||
configurator: c
|
||||
foo:
|
||||
class: App\FooService
|
||||
public: true
|
22
vendor/symfony/dependency-injection/Tests/Fixtures/config/instanceof.php
vendored
Normal file
22
vendor/symfony/dependency-injection/Tests/Fixtures/config/instanceof.php
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
|
||||
|
||||
use App\FooService;
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype;
|
||||
|
||||
return function (ContainerConfigurator $c) {
|
||||
$s = $c->services();
|
||||
$s->instanceof(Prototype\Foo::class)
|
||||
->property('p', 0)
|
||||
->call('setFoo', array(ref('foo')))
|
||||
->tag('tag', array('k' => 'v'))
|
||||
->share(false)
|
||||
->lazy()
|
||||
->configurator('c')
|
||||
->property('p', 1);
|
||||
|
||||
$s->load(Prototype::class.'\\', '../Prototype')->exclude('../Prototype/*/*');
|
||||
|
||||
$s->set('foo', FooService::class);
|
||||
};
|
19
vendor/symfony/dependency-injection/Tests/Fixtures/config/php7.expected.yml
vendored
Normal file
19
vendor/symfony/dependency-injection/Tests/Fixtures/config/php7.expected.yml
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
parameters:
|
||||
foo: Foo
|
||||
bar: Bar
|
||||
|
||||
services:
|
||||
service_container:
|
||||
class: Symfony\Component\DependencyInjection\ContainerInterface
|
||||
public: true
|
||||
synthetic: true
|
||||
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
|
||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
||||
public: true
|
||||
arguments: ['@bar']
|
||||
bar:
|
||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
||||
public: true
|
||||
calls:
|
||||
- [setFoo, { }]
|
||||
|
19
vendor/symfony/dependency-injection/Tests/Fixtures/config/php7.php
vendored
Normal file
19
vendor/symfony/dependency-injection/Tests/Fixtures/config/php7.php
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo;
|
||||
|
||||
return function (ContainerConfigurator $c) {
|
||||
$c->parameters()
|
||||
('foo', 'Foo')
|
||||
('bar', 'Bar')
|
||||
;
|
||||
$c->services()
|
||||
(Foo::class)
|
||||
->arg('$bar', ref('bar'))
|
||||
->public()
|
||||
('bar', Foo::class)
|
||||
->call('setFoo')
|
||||
;
|
||||
};
|
25
vendor/symfony/dependency-injection/Tests/Fixtures/config/prototype.expected.yml
vendored
Normal file
25
vendor/symfony/dependency-injection/Tests/Fixtures/config/prototype.expected.yml
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
|
||||
services:
|
||||
service_container:
|
||||
class: Symfony\Component\DependencyInjection\ContainerInterface
|
||||
public: true
|
||||
synthetic: true
|
||||
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
|
||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
||||
public: true
|
||||
tags:
|
||||
- { name: foo }
|
||||
- { name: baz }
|
||||
deprecated: '%service_id%'
|
||||
arguments: [1]
|
||||
factory: f
|
||||
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar:
|
||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar
|
||||
public: true
|
||||
tags:
|
||||
- { name: foo }
|
||||
- { name: baz }
|
||||
deprecated: '%service_id%'
|
||||
lazy: true
|
||||
arguments: [1]
|
||||
factory: f
|
22
vendor/symfony/dependency-injection/Tests/Fixtures/config/prototype.php
vendored
Normal file
22
vendor/symfony/dependency-injection/Tests/Fixtures/config/prototype.php
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype;
|
||||
|
||||
return function (ContainerConfigurator $c) {
|
||||
$di = $c->services()->defaults()
|
||||
->tag('baz');
|
||||
$di->load(Prototype::class.'\\', '../Prototype')
|
||||
->autoconfigure()
|
||||
->exclude('../Prototype/{OtherDir,BadClasses}')
|
||||
->factory('f')
|
||||
->deprecate('%service_id%')
|
||||
->args(array(0))
|
||||
->args(array(1))
|
||||
->autoconfigure(false)
|
||||
->tag('foo')
|
||||
->parent('foo');
|
||||
$di->set('foo')->lazy()->abstract();
|
||||
$di->get(Prototype\Foo::class)->lazy(false);
|
||||
};
|
128
vendor/symfony/dependency-injection/Tests/Fixtures/config/services9.php
vendored
Normal file
128
vendor/symfony/dependency-injection/Tests/Fixtures/config/services9.php
vendored
Normal file
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
|
||||
|
||||
use Bar\FooClass;
|
||||
use Symfony\Component\DependencyInjection\Parameter;
|
||||
|
||||
require_once __DIR__.'/../includes/classes.php';
|
||||
require_once __DIR__.'/../includes/foo.php';
|
||||
|
||||
return function (ContainerConfigurator $c) {
|
||||
$p = $c->parameters();
|
||||
$p->set('baz_class', 'BazClass');
|
||||
$p->set('foo_class', FooClass::class)
|
||||
->set('foo', 'bar');
|
||||
|
||||
$s = $c->services();
|
||||
$s->set('foo')
|
||||
->args(array('foo', ref('foo.baz'), array('%foo%' => 'foo is %foo%', 'foobar' => '%foo%'), true, ref('service_container')))
|
||||
->class(FooClass::class)
|
||||
->tag('foo', array('foo' => 'foo'))
|
||||
->tag('foo', array('bar' => 'bar', 'baz' => 'baz'))
|
||||
->factory(array(FooClass::class, 'getInstance'))
|
||||
->property('foo', 'bar')
|
||||
->property('moo', ref('foo.baz'))
|
||||
->property('qux', array('%foo%' => 'foo is %foo%', 'foobar' => '%foo%'))
|
||||
->call('setBar', array(ref('bar')))
|
||||
->call('initialize')
|
||||
->configurator('sc_configure');
|
||||
|
||||
$s->set('foo.baz', '%baz_class%')
|
||||
->factory(array('%baz_class%', 'getInstance'))
|
||||
->configurator(array('%baz_class%', 'configureStatic1'));
|
||||
|
||||
$s->set('bar', FooClass::class)
|
||||
->args(array('foo', ref('foo.baz'), new Parameter('foo_bar')))
|
||||
->configurator(array(ref('foo.baz'), 'configure'));
|
||||
|
||||
$s->set('foo_bar', '%foo_class%')
|
||||
->args(array(ref('deprecated_service')))
|
||||
->share(false);
|
||||
|
||||
$s->set('method_call1', 'Bar\FooClass')
|
||||
->file(realpath(__DIR__.'/../includes/foo.php'))
|
||||
->call('setBar', array(ref('foo')))
|
||||
->call('setBar', array(ref('foo2')->nullOnInvalid()))
|
||||
->call('setBar', array(ref('foo3')->ignoreOnInvalid()))
|
||||
->call('setBar', array(ref('foobaz')->ignoreOnInvalid()))
|
||||
->call('setBar', array(expr('service("foo").foo() ~ (container.hasParameter("foo") ? parameter("foo") : "default")')));
|
||||
|
||||
$s->set('foo_with_inline', 'Foo')
|
||||
->call('setBar', array(ref('inlined')));
|
||||
|
||||
$s->set('inlined', 'Bar')
|
||||
->property('pub', 'pub')
|
||||
->call('setBaz', array(ref('baz')))
|
||||
->private();
|
||||
|
||||
$s->set('baz', 'Baz')
|
||||
->call('setFoo', array(ref('foo_with_inline')));
|
||||
|
||||
$s->set('request', 'Request')
|
||||
->synthetic();
|
||||
|
||||
$s->set('configurator_service', 'ConfClass')
|
||||
->private()
|
||||
->call('setFoo', array(ref('baz')));
|
||||
|
||||
$s->set('configured_service', 'stdClass')
|
||||
->configurator(array(ref('configurator_service'), 'configureStdClass'));
|
||||
|
||||
$s->set('configurator_service_simple', 'ConfClass')
|
||||
->args(array('bar'))
|
||||
->private();
|
||||
|
||||
$s->set('configured_service_simple', 'stdClass')
|
||||
->configurator(array(ref('configurator_service_simple'), 'configureStdClass'));
|
||||
|
||||
$s->set('decorated', 'stdClass');
|
||||
|
||||
$s->set('decorator_service', 'stdClass')
|
||||
->decorate('decorated');
|
||||
|
||||
$s->set('decorator_service_with_name', 'stdClass')
|
||||
->decorate('decorated', 'decorated.pif-pouf');
|
||||
|
||||
$s->set('deprecated_service', 'stdClass')
|
||||
->deprecate();
|
||||
|
||||
$s->set('new_factory', 'FactoryClass')
|
||||
->property('foo', 'bar')
|
||||
->private();
|
||||
|
||||
$s->set('factory_service', 'Bar')
|
||||
->factory(array(ref('foo.baz'), 'getInstance'));
|
||||
|
||||
$s->set('new_factory_service', 'FooBarBaz')
|
||||
->property('foo', 'bar')
|
||||
->factory(array(ref('new_factory'), 'getInstance'));
|
||||
|
||||
$s->set('service_from_static_method', 'Bar\FooClass')
|
||||
->factory(array('Bar\FooClass', 'getInstance'));
|
||||
|
||||
$s->set('factory_simple', 'SimpleFactoryClass')
|
||||
->deprecate()
|
||||
->args(array('foo'))
|
||||
->private();
|
||||
|
||||
$s->set('factory_service_simple', 'Bar')
|
||||
->factory(array(ref('factory_simple'), 'getInstance'));
|
||||
|
||||
$s->set('lazy_context', 'LazyContext')
|
||||
->args(array(iterator(array('k1' => ref('foo.baz'), 'k2' => ref('service_container'))), iterator(array())));
|
||||
|
||||
$s->set('lazy_context_ignore_invalid_ref', 'LazyContext')
|
||||
->args(array(iterator(array(ref('foo.baz'), ref('invalid')->ignoreOnInvalid())), iterator(array())));
|
||||
|
||||
$s->set('tagged_iterator_foo', 'Bar')
|
||||
->private()
|
||||
->tag('foo');
|
||||
|
||||
$s->set('tagged_iterator', 'Bar')
|
||||
->public()
|
||||
->args(array(tagged('foo')));
|
||||
|
||||
$s->alias('alias_for_foo', 'foo')->private()->public();
|
||||
$s->alias('alias_for_alias', ref('alias_for_foo'));
|
||||
};
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
|
||||
|
||||
return function (ContainerConfigurator $c) {
|
||||
$c->services()
|
||||
->set('parent_service', \stdClass::class)
|
||||
->set('child_service')->parent('parent_service')->autoconfigure(true);
|
||||
};
|
17
vendor/symfony/dependency-injection/Tests/Fixtures/containers/CustomContainer.php
vendored
Normal file
17
vendor/symfony/dependency-injection/Tests/Fixtures/containers/CustomContainer.php
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\containers;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
|
||||
class CustomContainer extends Container
|
||||
{
|
||||
public function getBarService()
|
||||
{
|
||||
}
|
||||
|
||||
public function getFoobarService()
|
||||
{
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue