Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
99
vendor/symfony/http-kernel/Tests/DependencyInjection/AddAnnotatedClassesToCachePassTest.php
vendored
Normal file
99
vendor/symfony/http-kernel/Tests/DependencyInjection/AddAnnotatedClassesToCachePassTest.php
vendored
Normal file
|
@ -0,0 +1,99 @@
|
|||
<?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\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\AddAnnotatedClassesToCachePass;
|
||||
|
||||
class AddAnnotatedClassesToCachePassTest extends TestCase
|
||||
{
|
||||
public function testExpandClasses()
|
||||
{
|
||||
$r = new \ReflectionClass(AddAnnotatedClassesToCachePass::class);
|
||||
$pass = $r->newInstanceWithoutConstructor();
|
||||
$r = new \ReflectionMethod(AddAnnotatedClassesToCachePass::class, 'expandClasses');
|
||||
$r->setAccessible(true);
|
||||
$expand = $r->getClosure($pass);
|
||||
|
||||
$this->assertSame('Foo', $expand(array('Foo'), array())[0]);
|
||||
$this->assertSame('Foo', $expand(array('\\Foo'), array())[0]);
|
||||
$this->assertSame('Foo', $expand(array('Foo'), array('\\Foo'))[0]);
|
||||
$this->assertSame('Foo', $expand(array('Foo'), array('Foo'))[0]);
|
||||
$this->assertSame('Foo', $expand(array('\\Foo'), array('\\Foo\\Bar'))[0]);
|
||||
$this->assertSame('Foo', $expand(array('Foo'), array('\\Foo\\Bar'))[0]);
|
||||
$this->assertSame('Foo', $expand(array('\\Foo'), array('\\Foo\\Bar\\Acme'))[0]);
|
||||
|
||||
$this->assertSame('Foo\\Bar', $expand(array('Foo\\'), array('\\Foo\\Bar'))[0]);
|
||||
$this->assertSame('Foo\\Bar\\Acme', $expand(array('Foo\\'), array('\\Foo\\Bar\\Acme'))[0]);
|
||||
$this->assertEmpty($expand(array('Foo\\'), array('\\Foo')));
|
||||
|
||||
$this->assertSame('Acme\\Foo\\Bar', $expand(array('**\\Foo\\'), array('\\Acme\\Foo\\Bar'))[0]);
|
||||
$this->assertEmpty($expand(array('**\\Foo\\'), array('\\Foo\\Bar')));
|
||||
$this->assertEmpty($expand(array('**\\Foo\\'), array('\\Acme\\Foo')));
|
||||
$this->assertEmpty($expand(array('**\\Foo\\'), array('\\Foo')));
|
||||
|
||||
$this->assertSame('Acme\\Foo', $expand(array('**\\Foo'), array('\\Acme\\Foo'))[0]);
|
||||
$this->assertEmpty($expand(array('**\\Foo'), array('\\Acme\\Foo\\AcmeBundle')));
|
||||
$this->assertEmpty($expand(array('**\\Foo'), array('\\Acme\\FooBar\\AcmeBundle')));
|
||||
|
||||
$this->assertSame('Foo\\Acme\\Bar', $expand(array('Foo\\*\\Bar'), array('\\Foo\\Acme\\Bar'))[0]);
|
||||
$this->assertEmpty($expand(array('Foo\\*\\Bar'), array('\\Foo\\Acme\\Bundle\\Bar')));
|
||||
|
||||
$this->assertSame('Foo\\Acme\\Bar', $expand(array('Foo\\**\\Bar'), array('\\Foo\\Acme\\Bar'))[0]);
|
||||
$this->assertSame('Foo\\Acme\\Bundle\\Bar', $expand(array('Foo\\**\\Bar'), array('\\Foo\\Acme\\Bundle\\Bar'))[0]);
|
||||
|
||||
$this->assertSame('Acme\\Bar', $expand(array('*\\Bar'), array('\\Acme\\Bar'))[0]);
|
||||
$this->assertEmpty($expand(array('*\\Bar'), array('\\Bar')));
|
||||
$this->assertEmpty($expand(array('*\\Bar'), array('\\Foo\\Acme\\Bar')));
|
||||
|
||||
$this->assertSame('Foo\\Acme\\Bar', $expand(array('**\\Bar'), array('\\Foo\\Acme\\Bar'))[0]);
|
||||
$this->assertSame('Foo\\Acme\\Bundle\\Bar', $expand(array('**\\Bar'), array('\\Foo\\Acme\\Bundle\\Bar'))[0]);
|
||||
$this->assertEmpty($expand(array('**\\Bar'), array('\\Bar')));
|
||||
|
||||
$this->assertSame('Foo\\Bar', $expand(array('Foo\\*'), array('\\Foo\\Bar'))[0]);
|
||||
$this->assertEmpty($expand(array('Foo\\*'), array('\\Foo\\Acme\\Bar')));
|
||||
|
||||
$this->assertSame('Foo\\Bar', $expand(array('Foo\\**'), array('\\Foo\\Bar'))[0]);
|
||||
$this->assertSame('Foo\\Acme\\Bar', $expand(array('Foo\\**'), array('\\Foo\\Acme\\Bar'))[0]);
|
||||
|
||||
$this->assertSame(array('Foo\\Bar'), $expand(array('Foo\\*'), array('Foo\\Bar', 'Foo\\BarTest')));
|
||||
$this->assertSame(array('Foo\\Bar', 'Foo\\BarTest'), $expand(array('Foo\\*', 'Foo\\*Test'), array('Foo\\Bar', 'Foo\\BarTest')));
|
||||
|
||||
$this->assertSame(
|
||||
'Acme\\FooBundle\\Controller\\DefaultController',
|
||||
$expand(array('**Bundle\\Controller\\'), array('\\Acme\\FooBundle\\Controller\\DefaultController'))[0]
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'FooBundle\\Controller\\DefaultController',
|
||||
$expand(array('**Bundle\\Controller\\'), array('\\FooBundle\\Controller\\DefaultController'))[0]
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'Acme\\FooBundle\\Controller\\Bar\\DefaultController',
|
||||
$expand(array('**Bundle\\Controller\\'), array('\\Acme\\FooBundle\\Controller\\Bar\\DefaultController'))[0]
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'Bundle\\Controller\\Bar\\DefaultController',
|
||||
$expand(array('**Bundle\\Controller\\'), array('\\Bundle\\Controller\\Bar\\DefaultController'))[0]
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'Acme\\Bundle\\Controller\\Bar\\DefaultController',
|
||||
$expand(array('**Bundle\\Controller\\'), array('\\Acme\\Bundle\\Controller\\Bar\\DefaultController'))[0]
|
||||
);
|
||||
|
||||
$this->assertSame('Foo\\Bar', $expand(array('Foo\\Bar'), array())[0]);
|
||||
$this->assertSame('Foo\\Acme\\Bar', $expand(array('Foo\\**'), array('\\Foo\\Acme\\Bar'))[0]);
|
||||
}
|
||||
}
|
67
vendor/symfony/http-kernel/Tests/DependencyInjection/ControllerArgumentValueResolverPassTest.php
vendored
Normal file
67
vendor/symfony/http-kernel/Tests/DependencyInjection/ControllerArgumentValueResolverPassTest.php
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?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\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass;
|
||||
|
||||
class ControllerArgumentValueResolverPassTest extends TestCase
|
||||
{
|
||||
public function testServicesAreOrderedAccordingToPriority()
|
||||
{
|
||||
$services = array(
|
||||
'n3' => array(array()),
|
||||
'n1' => array(array('priority' => 200)),
|
||||
'n2' => array(array('priority' => 100)),
|
||||
);
|
||||
|
||||
$expected = array(
|
||||
new Reference('n1'),
|
||||
new Reference('n2'),
|
||||
new Reference('n3'),
|
||||
);
|
||||
|
||||
$definition = new Definition(ArgumentResolver::class, array(null, array()));
|
||||
$container = new ContainerBuilder();
|
||||
$container->setDefinition('argument_resolver', $definition);
|
||||
|
||||
foreach ($services as $id => list($tag)) {
|
||||
$container->register($id)->addTag('controller.argument_value_resolver', $tag);
|
||||
}
|
||||
|
||||
(new ControllerArgumentValueResolverPass())->process($container);
|
||||
$this->assertEquals($expected, $definition->getArgument(1)->getValues());
|
||||
}
|
||||
|
||||
public function testReturningEmptyArrayWhenNoService()
|
||||
{
|
||||
$definition = new Definition(ArgumentResolver::class, array(null, array()));
|
||||
$container = new ContainerBuilder();
|
||||
$container->setDefinition('argument_resolver', $definition);
|
||||
|
||||
(new ControllerArgumentValueResolverPass())->process($container);
|
||||
$this->assertEquals(array(), $definition->getArgument(1)->getValues());
|
||||
}
|
||||
|
||||
public function testNoArgumentResolver()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
(new ControllerArgumentValueResolverPass())->process($container);
|
||||
|
||||
$this->assertFalse($container->hasDefinition('argument_resolver'));
|
||||
}
|
||||
}
|
71
vendor/symfony/http-kernel/Tests/DependencyInjection/FragmentRendererPassTest.php
vendored
Normal file
71
vendor/symfony/http-kernel/Tests/DependencyInjection/FragmentRendererPassTest.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\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\ServiceLocator;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass;
|
||||
use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;
|
||||
|
||||
class FragmentRendererPassTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Tests that content rendering not implementing FragmentRendererInterface
|
||||
* triggers an exception.
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testContentRendererWithoutInterface()
|
||||
{
|
||||
$builder = new ContainerBuilder();
|
||||
$fragmentHandlerDefinition = $builder->register('fragment.handler');
|
||||
$builder->register('my_content_renderer', 'Symfony\Component\DependencyInjection\Definition')
|
||||
->addTag('kernel.fragment_renderer', array('alias' => 'foo'));
|
||||
|
||||
$pass = new FragmentRendererPass();
|
||||
$pass->process($builder);
|
||||
|
||||
$this->assertEquals(array(array('addRendererService', array('foo', 'my_content_renderer'))), $fragmentHandlerDefinition->getMethodCalls());
|
||||
}
|
||||
|
||||
public function testValidContentRenderer()
|
||||
{
|
||||
$builder = new ContainerBuilder();
|
||||
$fragmentHandlerDefinition = $builder->register('fragment.handler')
|
||||
->addArgument(null);
|
||||
$builder->register('my_content_renderer', 'Symfony\Component\HttpKernel\Tests\DependencyInjection\RendererService')
|
||||
->addTag('kernel.fragment_renderer', array('alias' => 'foo'));
|
||||
|
||||
$pass = new FragmentRendererPass();
|
||||
$pass->process($builder);
|
||||
|
||||
$serviceLocatorDefinition = $builder->getDefinition((string) $fragmentHandlerDefinition->getArgument(0));
|
||||
$this->assertSame(ServiceLocator::class, $serviceLocatorDefinition->getClass());
|
||||
$this->assertEquals(array('foo' => new ServiceClosureArgument(new Reference('my_content_renderer'))), $serviceLocatorDefinition->getArgument(0));
|
||||
}
|
||||
}
|
||||
|
||||
class RendererService implements FragmentRendererInterface
|
||||
{
|
||||
public function render($uri, Request $request = null, array $options = array())
|
||||
{
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'test';
|
||||
}
|
||||
}
|
66
vendor/symfony/http-kernel/Tests/DependencyInjection/LazyLoadingFragmentHandlerTest.php
vendored
Normal file
66
vendor/symfony/http-kernel/Tests/DependencyInjection/LazyLoadingFragmentHandlerTest.php
vendored
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?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\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler;
|
||||
|
||||
class LazyLoadingFragmentHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation The Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler::addRendererService() method is deprecated since Symfony 3.3 and will be removed in 4.0.
|
||||
*/
|
||||
public function testRenderWithLegacyMapping()
|
||||
{
|
||||
$renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock();
|
||||
$renderer->expects($this->once())->method('getName')->will($this->returnValue('foo'));
|
||||
$renderer->expects($this->any())->method('render')->will($this->returnValue(new Response()));
|
||||
|
||||
$requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
|
||||
$requestStack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue(Request::create('/')));
|
||||
|
||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
|
||||
$container->expects($this->once())->method('get')->will($this->returnValue($renderer));
|
||||
|
||||
$handler = new LazyLoadingFragmentHandler($container, $requestStack, false);
|
||||
$handler->addRendererService('foo', 'foo');
|
||||
|
||||
$handler->render('/foo', 'foo');
|
||||
|
||||
// second call should not lazy-load anymore (see once() above on the get() method)
|
||||
$handler->render('/foo', 'foo');
|
||||
}
|
||||
|
||||
public function testRender()
|
||||
{
|
||||
$renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock();
|
||||
$renderer->expects($this->once())->method('getName')->will($this->returnValue('foo'));
|
||||
$renderer->expects($this->any())->method('render')->will($this->returnValue(new Response()));
|
||||
|
||||
$requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
|
||||
$requestStack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue(Request::create('/')));
|
||||
|
||||
$container = $this->getMockBuilder('Psr\Container\ContainerInterface')->getMock();
|
||||
$container->expects($this->once())->method('has')->with('foo')->willReturn(true);
|
||||
$container->expects($this->once())->method('get')->will($this->returnValue($renderer));
|
||||
|
||||
$handler = new LazyLoadingFragmentHandler($container, $requestStack, false);
|
||||
|
||||
$handler->render('/foo', 'foo');
|
||||
|
||||
// second call should not lazy-load anymore (see once() above on the get() method)
|
||||
$handler->render('/foo', 'foo');
|
||||
}
|
||||
}
|
56
vendor/symfony/http-kernel/Tests/DependencyInjection/LoggerPassTest.php
vendored
Normal file
56
vendor/symfony/http-kernel/Tests/DependencyInjection/LoggerPassTest.php
vendored
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?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\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\LoggerPass;
|
||||
use Symfony\Component\HttpKernel\Log\Logger;
|
||||
|
||||
/**
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class LoggerPassTest extends TestCase
|
||||
{
|
||||
public function testAlwaysSetAutowiringAlias()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('logger', 'Foo');
|
||||
|
||||
(new LoggerPass())->process($container);
|
||||
|
||||
$this->assertFalse($container->getAlias(LoggerInterface::class)->isPublic());
|
||||
}
|
||||
|
||||
public function testDoNotOverrideExistingLogger()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('logger', 'Foo');
|
||||
|
||||
(new LoggerPass())->process($container);
|
||||
|
||||
$this->assertSame('Foo', $container->getDefinition('logger')->getClass());
|
||||
}
|
||||
|
||||
public function testRegisterLogger()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setParameter('kernel.debug', false);
|
||||
|
||||
(new LoggerPass())->process($container);
|
||||
|
||||
$definition = $container->getDefinition('logger');
|
||||
$this->assertSame(Logger::class, $definition->getClass());
|
||||
$this->assertFalse($definition->isPublic());
|
||||
}
|
||||
}
|
50
vendor/symfony/http-kernel/Tests/DependencyInjection/MergeExtensionConfigurationPassTest.php
vendored
Normal file
50
vendor/symfony/http-kernel/Tests/DependencyInjection/MergeExtensionConfigurationPassTest.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\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
|
||||
|
||||
class MergeExtensionConfigurationPassTest extends TestCase
|
||||
{
|
||||
public function testAutoloadMainExtension()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->registerExtension(new LoadedExtension());
|
||||
$container->registerExtension(new NotLoadedExtension());
|
||||
$container->loadFromExtension('loaded', array());
|
||||
|
||||
$configPass = new MergeExtensionConfigurationPass(array('loaded', 'not_loaded'));
|
||||
$configPass->process($container);
|
||||
|
||||
$this->assertTrue($container->hasDefinition('loaded.foo'));
|
||||
$this->assertTrue($container->hasDefinition('not_loaded.bar'));
|
||||
}
|
||||
}
|
||||
|
||||
class LoadedExtension extends Extension
|
||||
{
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$container->register('loaded.foo');
|
||||
}
|
||||
}
|
||||
|
||||
class NotLoadedExtension extends Extension
|
||||
{
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$container->register('not_loaded.bar');
|
||||
}
|
||||
}
|
413
vendor/symfony/http-kernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php
vendored
Normal file
413
vendor/symfony/http-kernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php
vendored
Normal file
|
@ -0,0 +1,413 @@
|
|||
<?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\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\ServiceLocator;
|
||||
use Symfony\Component\DependencyInjection\TypedReference;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass;
|
||||
|
||||
class RegisterControllerArgumentLocatorsPassTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Class "Symfony\Component\HttpKernel\Tests\DependencyInjection\NotFound" used for service "foo" cannot be found.
|
||||
*/
|
||||
public function testInvalidClass()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('foo', NotFound::class)
|
||||
->addTag('controller.service_arguments')
|
||||
;
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Missing "action" attribute on tag "controller.service_arguments" {"argument":"bar"} for service "foo".
|
||||
*/
|
||||
public function testNoAction()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('foo', RegisterTestController::class)
|
||||
->addTag('controller.service_arguments', array('argument' => 'bar'))
|
||||
;
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Missing "argument" attribute on tag "controller.service_arguments" {"action":"fooAction"} for service "foo".
|
||||
*/
|
||||
public function testNoArgument()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('foo', RegisterTestController::class)
|
||||
->addTag('controller.service_arguments', array('action' => 'fooAction'))
|
||||
;
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Missing "id" attribute on tag "controller.service_arguments" {"action":"fooAction","argument":"bar"} for service "foo".
|
||||
*/
|
||||
public function testNoService()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('foo', RegisterTestController::class)
|
||||
->addTag('controller.service_arguments', array('action' => 'fooAction', 'argument' => 'bar'))
|
||||
;
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Invalid "action" attribute on tag "controller.service_arguments" for service "foo": no public "barAction()" method found on class "Symfony\Component\HttpKernel\Tests\DependencyInjection\RegisterTestController".
|
||||
*/
|
||||
public function testInvalidMethod()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('foo', RegisterTestController::class)
|
||||
->addTag('controller.service_arguments', array('action' => 'barAction', 'argument' => 'bar', 'id' => 'bar_service'))
|
||||
;
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Invalid "controller.service_arguments" tag for service "foo": method "fooAction()" has no "baz" argument on class "Symfony\Component\HttpKernel\Tests\DependencyInjection\RegisterTestController".
|
||||
*/
|
||||
public function testInvalidArgument()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('foo', RegisterTestController::class)
|
||||
->addTag('controller.service_arguments', array('action' => 'fooAction', 'argument' => 'baz', 'id' => 'bar'))
|
||||
;
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testAllActions()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('foo', RegisterTestController::class)
|
||||
->addTag('controller.service_arguments')
|
||||
;
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
|
||||
$this->assertEquals(array('foo:fooAction'), array_keys($locator));
|
||||
$this->assertInstanceof(ServiceClosureArgument::class, $locator['foo:fooAction']);
|
||||
|
||||
$locator = $container->getDefinition((string) $locator['foo:fooAction']->getValues()[0]);
|
||||
|
||||
$this->assertSame(ServiceLocator::class, $locator->getClass());
|
||||
$this->assertFalse($locator->isPublic());
|
||||
|
||||
$expected = array('bar' => new ServiceClosureArgument(new TypedReference(ControllerDummy::class, ControllerDummy::class, RegisterTestController::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
|
||||
$this->assertEquals($expected, $locator->getArgument(0));
|
||||
}
|
||||
|
||||
public function testExplicitArgument()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('foo', RegisterTestController::class)
|
||||
->addTag('controller.service_arguments', array('action' => 'fooAction', 'argument' => 'bar', 'id' => 'bar'))
|
||||
->addTag('controller.service_arguments', array('action' => 'fooAction', 'argument' => 'bar', 'id' => 'baz')) // should be ignored, the first wins
|
||||
;
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
$locator = $container->getDefinition((string) $locator['foo:fooAction']->getValues()[0]);
|
||||
|
||||
$expected = array('bar' => new ServiceClosureArgument(new TypedReference('bar', ControllerDummy::class, RegisterTestController::class)));
|
||||
$this->assertEquals($expected, $locator->getArgument(0));
|
||||
}
|
||||
|
||||
public function testOptionalArgument()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('foo', RegisterTestController::class)
|
||||
->addTag('controller.service_arguments', array('action' => 'fooAction', 'argument' => 'bar', 'id' => '?bar'))
|
||||
;
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
$locator = $container->getDefinition((string) $locator['foo:fooAction']->getValues()[0]);
|
||||
|
||||
$expected = array('bar' => new ServiceClosureArgument(new TypedReference('bar', ControllerDummy::class, RegisterTestController::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
|
||||
$this->assertEquals($expected, $locator->getArgument(0));
|
||||
}
|
||||
|
||||
public function testSkipSetContainer()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('foo', ContainerAwareRegisterTestController::class)
|
||||
->addTag('controller.service_arguments');
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
$this->assertSame(array('foo:fooAction'), array_keys($locator));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Cannot determine controller argument for "Symfony\Component\HttpKernel\Tests\DependencyInjection\NonExistentClassController::fooAction()": the $nonExistent argument is type-hinted with the non-existent class or interface: "Symfony\Component\HttpKernel\Tests\DependencyInjection\NonExistentClass". Did you forget to add a use statement?
|
||||
*/
|
||||
public function testExceptionOnNonExistentTypeHint()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('foo', NonExistentClassController::class)
|
||||
->addTag('controller.service_arguments');
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Cannot determine controller argument for "Symfony\Component\HttpKernel\Tests\DependencyInjection\NonExistentClassDifferentNamespaceController::fooAction()": the $nonExistent argument is type-hinted with the non-existent class or interface: "Acme\NonExistentClass".
|
||||
*/
|
||||
public function testExceptionOnNonExistentTypeHintDifferentNamespace()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('foo', NonExistentClassDifferentNamespaceController::class)
|
||||
->addTag('controller.service_arguments');
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testNoExceptionOnNonExistentTypeHintOptionalArg()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('foo', NonExistentClassOptionalController::class)
|
||||
->addTag('controller.service_arguments');
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
$this->assertSame(array('foo:barAction', 'foo:fooAction'), array_keys($locator));
|
||||
}
|
||||
|
||||
public function testArgumentWithNoTypeHintIsOk()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('foo', ArgumentWithoutTypeController::class)
|
||||
->addTag('controller.service_arguments');
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
$this->assertEmpty(array_keys($locator));
|
||||
}
|
||||
|
||||
public function testControllersAreMadePublic()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('foo', ArgumentWithoutTypeController::class)
|
||||
->setPublic(false)
|
||||
->addTag('controller.service_arguments');
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertTrue($container->getDefinition('foo')->isPublic());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideBindings
|
||||
*/
|
||||
public function testBindings($bindingName)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('foo', RegisterTestController::class)
|
||||
->setBindings(array($bindingName => new Reference('foo')))
|
||||
->addTag('controller.service_arguments');
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
|
||||
$locator = $container->getDefinition((string) $locator['foo:fooAction']->getValues()[0]);
|
||||
|
||||
$expected = array('bar' => new ServiceClosureArgument(new Reference('foo')));
|
||||
$this->assertEquals($expected, $locator->getArgument(0));
|
||||
}
|
||||
|
||||
public function provideBindings()
|
||||
{
|
||||
return array(array(ControllerDummy::class), array('$bar'));
|
||||
}
|
||||
|
||||
public function testDoNotBindScalarValueToControllerArgument()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('foo', ArgumentWithoutTypeController::class)
|
||||
->setBindings(array('$someArg' => '%foo%'))
|
||||
->addTag('controller.service_arguments');
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
$this->assertEmpty($locator);
|
||||
}
|
||||
|
||||
public function testBindingsOnChildDefinitions()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('parent', ArgumentWithoutTypeController::class);
|
||||
|
||||
$container->setDefinition('child', (new ChildDefinition('parent'))
|
||||
->setBindings(array('$someArg' => new Reference('parent')))
|
||||
->addTag('controller.service_arguments')
|
||||
);
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
$this->assertInstanceOf(ServiceClosureArgument::class, $locator['child:fooAction']);
|
||||
|
||||
$locator = $container->getDefinition((string) $locator['child:fooAction']->getValues()[0])->getArgument(0);
|
||||
$this->assertInstanceOf(ServiceClosureArgument::class, $locator['someArg']);
|
||||
$this->assertEquals(new Reference('parent'), $locator['someArg']->getValues()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
class RegisterTestController
|
||||
{
|
||||
public function __construct(ControllerDummy $bar)
|
||||
{
|
||||
}
|
||||
|
||||
public function fooAction(ControllerDummy $bar)
|
||||
{
|
||||
}
|
||||
|
||||
protected function barAction(ControllerDummy $bar)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class ContainerAwareRegisterTestController implements ContainerAwareInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
public function fooAction(ControllerDummy $bar)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class ControllerDummy
|
||||
{
|
||||
}
|
||||
|
||||
class NonExistentClassController
|
||||
{
|
||||
public function fooAction(NonExistentClass $nonExistent)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class NonExistentClassDifferentNamespaceController
|
||||
{
|
||||
public function fooAction(\Acme\NonExistentClass $nonExistent)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class NonExistentClassOptionalController
|
||||
{
|
||||
public function fooAction(NonExistentClass $nonExistent = null)
|
||||
{
|
||||
}
|
||||
|
||||
public function barAction(NonExistentClass $nonExistent = null, $bar)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class ArgumentWithoutTypeController
|
||||
{
|
||||
public function fooAction($someArg)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
<?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\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveInvalidReferencesPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\RemoveEmptyControllerArgumentLocatorsPass;
|
||||
|
||||
class RemoveEmptyControllerArgumentLocatorsPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('stdClass', 'stdClass');
|
||||
$container->register(parent::class, 'stdClass');
|
||||
$container->register('c1', RemoveTestController1::class)->addTag('controller.service_arguments');
|
||||
$container->register('c2', RemoveTestController2::class)->addTag('controller.service_arguments')
|
||||
->addMethodCall('setTestCase', array(new Reference('c1')));
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$controllers = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
|
||||
$this->assertCount(2, $container->getDefinition((string) $controllers['c1:fooAction']->getValues()[0])->getArgument(0));
|
||||
$this->assertCount(1, $container->getDefinition((string) $controllers['c2:setTestCase']->getValues()[0])->getArgument(0));
|
||||
$this->assertCount(1, $container->getDefinition((string) $controllers['c2:fooAction']->getValues()[0])->getArgument(0));
|
||||
|
||||
(new ResolveInvalidReferencesPass())->process($container);
|
||||
|
||||
$this->assertCount(1, $container->getDefinition((string) $controllers['c2:setTestCase']->getValues()[0])->getArgument(0));
|
||||
$this->assertSame(array(), $container->getDefinition((string) $controllers['c2:fooAction']->getValues()[0])->getArgument(0));
|
||||
|
||||
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
|
||||
|
||||
$controllers = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
|
||||
$this->assertSame(array('c1:fooAction'), array_keys($controllers));
|
||||
$this->assertSame(array('bar'), array_keys($container->getDefinition((string) $controllers['c1:fooAction']->getValues()[0])->getArgument(0)));
|
||||
|
||||
$expectedLog = array(
|
||||
'Symfony\Component\HttpKernel\DependencyInjection\RemoveEmptyControllerArgumentLocatorsPass: Removing service-argument resolver for controller "c2:fooAction": no corresponding services exist for the referenced types.',
|
||||
'Symfony\Component\HttpKernel\DependencyInjection\RemoveEmptyControllerArgumentLocatorsPass: Removing method "setTestCase" of service "c2" from controller candidates: the method is called at instantiation, thus cannot be an action.',
|
||||
);
|
||||
|
||||
$this->assertSame($expectedLog, $container->getCompiler()->getLog());
|
||||
}
|
||||
|
||||
public function testSameIdClass()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register(RegisterTestController::class, RegisterTestController::class)
|
||||
->addTag('controller.service_arguments')
|
||||
;
|
||||
|
||||
(new RegisterControllerArgumentLocatorsPass())->process($container);
|
||||
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
|
||||
|
||||
$expected = array(
|
||||
RegisterTestController::class.':fooAction',
|
||||
RegisterTestController::class.'::fooAction',
|
||||
);
|
||||
$this->assertEquals($expected, array_keys($container->getDefinition((string) $resolver->getArgument(0))->getArgument(0)));
|
||||
}
|
||||
|
||||
public function testInvoke()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register('invokable', InvokableRegisterTestController::class)
|
||||
->addTag('controller.service_arguments')
|
||||
;
|
||||
|
||||
(new RegisterControllerArgumentLocatorsPass())->process($container);
|
||||
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
|
||||
|
||||
$this->assertEquals(
|
||||
array('invokable:__invoke', 'invokable'),
|
||||
array_keys($container->getDefinition((string) $resolver->getArgument(0))->getArgument(0))
|
||||
);
|
||||
}
|
||||
|
||||
public function testInvokeSameIdClass()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument(array());
|
||||
|
||||
$container->register(InvokableRegisterTestController::class, InvokableRegisterTestController::class)
|
||||
->addTag('controller.service_arguments')
|
||||
;
|
||||
|
||||
(new RegisterControllerArgumentLocatorsPass())->process($container);
|
||||
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
|
||||
|
||||
$expected = array(
|
||||
InvokableRegisterTestController::class.':__invoke',
|
||||
InvokableRegisterTestController::class.'::__invoke',
|
||||
InvokableRegisterTestController::class,
|
||||
);
|
||||
$this->assertEquals($expected, array_keys($container->getDefinition((string) $resolver->getArgument(0))->getArgument(0)));
|
||||
}
|
||||
}
|
||||
|
||||
class RemoveTestController1
|
||||
{
|
||||
public function fooAction(\stdClass $bar, ClassNotInContainer $baz)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class RemoveTestController2
|
||||
{
|
||||
public function setTestCase(TestCase $test)
|
||||
{
|
||||
}
|
||||
|
||||
public function fooAction(ClassNotInContainer $bar)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class InvokableRegisterTestController
|
||||
{
|
||||
public function __invoke(\stdClass $bar)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class ClassNotInContainer
|
||||
{
|
||||
}
|
78
vendor/symfony/http-kernel/Tests/DependencyInjection/ResettableServicePassTest.php
vendored
Normal file
78
vendor/symfony/http-kernel/Tests/DependencyInjection/ResettableServicePassTest.php
vendored
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\ResettableServicePass;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\ClearableService;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\ResettableService;
|
||||
|
||||
class ResettableServicePassTest extends TestCase
|
||||
{
|
||||
public function testCompilerPass()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('one', ResettableService::class)
|
||||
->setPublic(true)
|
||||
->addTag('kernel.reset', array('method' => 'reset'));
|
||||
$container->register('two', ClearableService::class)
|
||||
->setPublic(true)
|
||||
->addTag('kernel.reset', array('method' => 'clear'));
|
||||
|
||||
$container->register('services_resetter', ServicesResetter::class)
|
||||
->setPublic(true)
|
||||
->setArguments(array(null, array()));
|
||||
$container->addCompilerPass(new ResettableServicePass());
|
||||
|
||||
$container->compile();
|
||||
|
||||
$definition = $container->getDefinition('services_resetter');
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
new IteratorArgument(array(
|
||||
'one' => new Reference('one', ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE),
|
||||
'two' => new Reference('two', ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE),
|
||||
)),
|
||||
array(
|
||||
'one' => 'reset',
|
||||
'two' => 'clear',
|
||||
),
|
||||
),
|
||||
$definition->getArguments()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Tag kernel.reset requires the "method" attribute to be set.
|
||||
*/
|
||||
public function testMissingMethod()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register(ResettableService::class)
|
||||
->addTag('kernel.reset');
|
||||
$container->register('services_resetter', ServicesResetter::class)
|
||||
->setArguments(array(null, array()));
|
||||
$container->addCompilerPass(new ResettableServicePass());
|
||||
|
||||
$container->compile();
|
||||
}
|
||||
|
||||
public function testCompilerPassWithoutResetters()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('services_resetter', ServicesResetter::class)
|
||||
->setArguments(array(null, array()));
|
||||
$container->addCompilerPass(new ResettableServicePass());
|
||||
|
||||
$container->compile();
|
||||
|
||||
$this->assertFalse($container->has('services_resetter'));
|
||||
}
|
||||
}
|
42
vendor/symfony/http-kernel/Tests/DependencyInjection/ServicesResetterTest.php
vendored
Normal file
42
vendor/symfony/http-kernel/Tests/DependencyInjection/ServicesResetterTest.php
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?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\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\ClearableService;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\ResettableService;
|
||||
|
||||
class ServicesResetterTest extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
ResettableService::$counter = 0;
|
||||
ClearableService::$counter = 0;
|
||||
}
|
||||
|
||||
public function testResetServices()
|
||||
{
|
||||
$resetter = new ServicesResetter(new \ArrayIterator(array(
|
||||
'id1' => new ResettableService(),
|
||||
'id2' => new ClearableService(),
|
||||
)), array(
|
||||
'id1' => 'reset',
|
||||
'id2' => 'clear',
|
||||
));
|
||||
|
||||
$resetter->reset();
|
||||
|
||||
$this->assertEquals(1, ResettableService::$counter);
|
||||
$this->assertEquals(1, ClearableService::$counter);
|
||||
}
|
||||
}
|
Reference in a new issue