mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +02:00
N°2651 rollback gitignore for lib tests dirs
Too dangerous ! We'll work properly on this but for 2.8
This commit is contained in:
@@ -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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class AddCacheWarmerPassTest extends TestCase
|
||||
{
|
||||
public function testThatCacheWarmersAreProcessedInPriorityOrder()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$cacheWarmerDefinition = $container->register('cache_warmer')->addArgument([]);
|
||||
$container->register('my_cache_warmer_service1')->addTag('kernel.cache_warmer', ['priority' => 100]);
|
||||
$container->register('my_cache_warmer_service2')->addTag('kernel.cache_warmer', ['priority' => 200]);
|
||||
$container->register('my_cache_warmer_service3')->addTag('kernel.cache_warmer');
|
||||
|
||||
$addCacheWarmerPass = new AddCacheWarmerPass();
|
||||
$addCacheWarmerPass->process($container);
|
||||
|
||||
$this->assertEquals(
|
||||
[
|
||||
new Reference('my_cache_warmer_service2'),
|
||||
new Reference('my_cache_warmer_service1'),
|
||||
new Reference('my_cache_warmer_service3'),
|
||||
],
|
||||
$cacheWarmerDefinition->getArgument(0)
|
||||
);
|
||||
}
|
||||
|
||||
public function testThatCompilerPassIsIgnoredIfThereIsNoCacheWarmerDefinition()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$addCacheWarmerPass = new AddCacheWarmerPass();
|
||||
$addCacheWarmerPass->process($container);
|
||||
|
||||
// we just check that the pass does not break if no cache warmer is registered
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testThatCacheWarmersMightBeNotDefined()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$cacheWarmerDefinition = $container->register('cache_warmer')->addArgument([]);
|
||||
|
||||
$addCacheWarmerPass = new AddCacheWarmerPass();
|
||||
$addCacheWarmerPass->process($container);
|
||||
|
||||
$this->assertSame([], $cacheWarmerDefinition->getArgument(0));
|
||||
}
|
||||
}
|
||||
@@ -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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class AddConsoleCommandPassTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider visibilityProvider
|
||||
*/
|
||||
public function testProcess($public)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new AddConsoleCommandPass());
|
||||
$container->setParameter('my-command.class', 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\MyCommand');
|
||||
|
||||
$definition = new Definition('%my-command.class%');
|
||||
$definition->setPublic($public);
|
||||
$definition->addTag('console.command');
|
||||
$container->setDefinition('my-command', $definition);
|
||||
|
||||
$container->compile();
|
||||
|
||||
$alias = 'console.command.symfony_bundle_frameworkbundle_tests_dependencyinjection_compiler_mycommand';
|
||||
|
||||
if ($public) {
|
||||
$this->assertFalse($container->hasAlias($alias));
|
||||
$id = 'my-command';
|
||||
} else {
|
||||
$id = $alias;
|
||||
// The alias is replaced by a Definition by the ReplaceAliasByActualDefinitionPass
|
||||
// in case the original service is private
|
||||
$this->assertFalse($container->hasDefinition('my-command'));
|
||||
$this->assertTrue($container->hasDefinition($alias));
|
||||
}
|
||||
|
||||
$this->assertTrue($container->hasParameter('console.command.ids'));
|
||||
$this->assertSame([$alias => $id], $container->getParameter('console.command.ids'));
|
||||
}
|
||||
|
||||
public function visibilityProvider()
|
||||
{
|
||||
return [
|
||||
[true],
|
||||
[false],
|
||||
];
|
||||
}
|
||||
|
||||
public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$this->expectExceptionMessage('The service "my-command" tagged "console.command" must not be abstract.');
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new AddConsoleCommandPass());
|
||||
|
||||
$definition = new Definition('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\MyCommand');
|
||||
$definition->addTag('console.command');
|
||||
$definition->setAbstract(true);
|
||||
$container->setDefinition('my-command', $definition);
|
||||
|
||||
$container->compile();
|
||||
}
|
||||
|
||||
public function testProcessThrowAnExceptionIfTheServiceIsNotASubclassOfCommand()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$this->expectExceptionMessage('The service "my-command" tagged "console.command" must be a subclass of "Symfony\Component\Console\Command\Command".');
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new AddConsoleCommandPass());
|
||||
|
||||
$definition = new Definition('SplObjectStorage');
|
||||
$definition->addTag('console.command');
|
||||
$container->setDefinition('my-command', $definition);
|
||||
|
||||
$container->compile();
|
||||
}
|
||||
|
||||
public function testProcessPrivateServicesWithSameCommand()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$className = 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\MyCommand';
|
||||
|
||||
$definition1 = new Definition($className);
|
||||
$definition1->addTag('console.command')->setPublic(false);
|
||||
|
||||
$definition2 = new Definition($className);
|
||||
$definition2->addTag('console.command')->setPublic(false);
|
||||
|
||||
$container->setDefinition('my-command1', $definition1);
|
||||
$container->setDefinition('my-command2', $definition2);
|
||||
|
||||
(new AddConsoleCommandPass())->process($container);
|
||||
|
||||
$alias1 = 'console.command.symfony_bundle_frameworkbundle_tests_dependencyinjection_compiler_mycommand';
|
||||
$alias2 = $alias1.'_my-command2';
|
||||
$this->assertTrue($container->hasAlias($alias1));
|
||||
$this->assertTrue($container->hasAlias($alias2));
|
||||
}
|
||||
}
|
||||
|
||||
class MyCommand extends Command
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\ServiceLocator;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class AddConstraintValidatorsPassTest extends TestCase
|
||||
{
|
||||
public function testThatConstraintValidatorServicesAreProcessed()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$validatorFactory = $container->register('validator.validator_factory')
|
||||
->addArgument([]);
|
||||
|
||||
$container->register('my_constraint_validator_service1', Validator1::class)
|
||||
->addTag('validator.constraint_validator', ['alias' => 'my_constraint_validator_alias1']);
|
||||
$container->register('my_constraint_validator_service2', Validator2::class)
|
||||
->addTag('validator.constraint_validator');
|
||||
|
||||
$addConstraintValidatorsPass = new AddConstraintValidatorsPass();
|
||||
$addConstraintValidatorsPass->process($container);
|
||||
|
||||
$expected = (new Definition(ServiceLocator::class, [[
|
||||
Validator1::class => new ServiceClosureArgument(new Reference('my_constraint_validator_service1')),
|
||||
'my_constraint_validator_alias1' => new ServiceClosureArgument(new Reference('my_constraint_validator_service1')),
|
||||
Validator2::class => new ServiceClosureArgument(new Reference('my_constraint_validator_service2')),
|
||||
]]))->addTag('container.service_locator')->setPublic(false);
|
||||
$this->assertEquals($expected, $container->getDefinition((string) $validatorFactory->getArgument(0)));
|
||||
}
|
||||
|
||||
public function testAbstractConstraintValidator()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$this->expectExceptionMessage('The service "my_abstract_constraint_validator" tagged "validator.constraint_validator" must not be abstract.');
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('validator.validator_factory')
|
||||
->addArgument([]);
|
||||
|
||||
$container->register('my_abstract_constraint_validator')
|
||||
->setAbstract(true)
|
||||
->addTag('validator.constraint_validator');
|
||||
|
||||
$addConstraintValidatorsPass = new AddConstraintValidatorsPass();
|
||||
$addConstraintValidatorsPass->process($container);
|
||||
}
|
||||
|
||||
public function testThatCompilerPassIsIgnoredIfThereIsNoConstraintValidatorFactoryDefinition()
|
||||
{
|
||||
$addConstraintValidatorsPass = new AddConstraintValidatorsPass();
|
||||
$addConstraintValidatorsPass->process(new ContainerBuilder());
|
||||
|
||||
// we just check that the pass does not fail if no constraint validator factory is registered
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
}
|
||||
@@ -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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class AddExpressionLanguageProvidersPassTest extends TestCase
|
||||
{
|
||||
public function testProcessForRouter()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
|
||||
|
||||
$definition = new Definition('\stdClass');
|
||||
$definition->addTag('routing.expression_language_provider');
|
||||
$container->setDefinition('some_routing_provider', $definition->setPublic(true));
|
||||
|
||||
$container->register('router', '\stdClass')->setPublic(true);
|
||||
$container->compile();
|
||||
|
||||
$router = $container->getDefinition('router');
|
||||
$calls = $router->getMethodCalls();
|
||||
$this->assertCount(1, $calls);
|
||||
$this->assertEquals('addExpressionLanguageProvider', $calls[0][0]);
|
||||
$this->assertEquals(new Reference('some_routing_provider'), $calls[0][1][0]);
|
||||
}
|
||||
|
||||
public function testProcessForRouterAlias()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
|
||||
|
||||
$definition = new Definition('\stdClass');
|
||||
$definition->addTag('routing.expression_language_provider');
|
||||
$container->setDefinition('some_routing_provider', $definition->setPublic(true));
|
||||
|
||||
$container->register('my_router', '\stdClass')->setPublic(true);
|
||||
$container->setAlias('router', 'my_router');
|
||||
$container->compile();
|
||||
|
||||
$router = $container->getDefinition('my_router');
|
||||
$calls = $router->getMethodCalls();
|
||||
$this->assertCount(1, $calls);
|
||||
$this->assertEquals('addExpressionLanguageProvider', $calls[0][0]);
|
||||
$this->assertEquals(new Reference('some_routing_provider'), $calls[0][1][0]);
|
||||
}
|
||||
|
||||
public function testProcessForSecurity()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
|
||||
|
||||
$definition = new Definition('\stdClass');
|
||||
$definition->addTag('security.expression_language_provider');
|
||||
$container->setDefinition('some_security_provider', $definition->setPublic(true));
|
||||
|
||||
$container->register('security.expression_language', '\stdClass')->setPublic(true);
|
||||
$container->compile();
|
||||
|
||||
$calls = $container->getDefinition('security.expression_language')->getMethodCalls();
|
||||
$this->assertCount(1, $calls);
|
||||
$this->assertEquals('registerProvider', $calls[0][0]);
|
||||
$this->assertEquals(new Reference('some_security_provider'), $calls[0][1][0]);
|
||||
}
|
||||
|
||||
public function testProcessForSecurityAlias()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
|
||||
|
||||
$definition = new Definition('\stdClass');
|
||||
$definition->addTag('security.expression_language_provider');
|
||||
$container->setDefinition('some_security_provider', $definition->setPublic(true));
|
||||
|
||||
$container->register('my_security.expression_language', '\stdClass')->setPublic(true);
|
||||
$container->setAlias('security.expression_language', 'my_security.expression_language');
|
||||
$container->compile();
|
||||
|
||||
$calls = $container->getDefinition('my_security.expression_language')->getMethodCalls();
|
||||
$this->assertCount(1, $calls);
|
||||
$this->assertEquals('registerProvider', $calls[0][0]);
|
||||
$this->assertEquals(new Reference('some_security_provider'), $calls[0][1][0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CacheCollectorPass;
|
||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
|
||||
use Symfony\Component\Cache\Adapter\TraceableAdapter;
|
||||
use Symfony\Component\Cache\Adapter\TraceableTagAwareAdapter;
|
||||
use Symfony\Component\Cache\DataCollector\CacheDataCollector;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class CacheCollectorPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('fs', FilesystemAdapter::class)
|
||||
->addTag('cache.pool');
|
||||
$container
|
||||
->register('tagged_fs', TagAwareAdapter::class)
|
||||
->addArgument(new Reference('fs'))
|
||||
->addTag('cache.pool');
|
||||
|
||||
$collector = $container->register('data_collector.cache', CacheDataCollector::class);
|
||||
(new CacheCollectorPass())->process($container);
|
||||
|
||||
$this->assertEquals([
|
||||
['addInstance', ['fs', new Reference('fs')]],
|
||||
['addInstance', ['tagged_fs', new Reference('tagged_fs')]],
|
||||
], $collector->getMethodCalls());
|
||||
|
||||
$this->assertSame(TraceableAdapter::class, $container->findDefinition('fs')->getClass());
|
||||
$this->assertSame(TraceableTagAwareAdapter::class, $container->getDefinition('tagged_fs')->getClass());
|
||||
$this->assertFalse($collector->isPublic(), 'The "data_collector.cache" should be private after processing');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolClearerPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\RemoveUnusedDefinitionsPass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\RepeatedPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer;
|
||||
|
||||
class CachePoolClearerPassTest extends TestCase
|
||||
{
|
||||
public function testPoolRefsAreWeak()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setParameter('kernel.debug', false);
|
||||
$container->setParameter('kernel.name', 'app');
|
||||
$container->setParameter('kernel.environment', 'prod');
|
||||
$container->setParameter('kernel.root_dir', 'foo');
|
||||
|
||||
$globalClearer = new Definition(Psr6CacheClearer::class);
|
||||
$container->setDefinition('cache.global_clearer', $globalClearer);
|
||||
|
||||
$publicPool = new Definition();
|
||||
$publicPool->addArgument('namespace');
|
||||
$publicPool->addTag('cache.pool', ['clearer' => 'clearer_alias']);
|
||||
$container->setDefinition('public.pool', $publicPool);
|
||||
|
||||
$privatePool = new Definition();
|
||||
$privatePool->setPublic(false);
|
||||
$privatePool->addArgument('namespace');
|
||||
$privatePool->addTag('cache.pool', ['clearer' => 'clearer_alias']);
|
||||
$container->setDefinition('private.pool', $privatePool);
|
||||
|
||||
$clearer = new Definition();
|
||||
$container->setDefinition('clearer', $clearer);
|
||||
$container->setAlias('clearer_alias', 'clearer');
|
||||
|
||||
$pass = new RemoveUnusedDefinitionsPass();
|
||||
$pass->setRepeatedPass(new RepeatedPass([$pass]));
|
||||
foreach ([new CachePoolPass(), $pass, new CachePoolClearerPass()] as $pass) {
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
$this->assertEquals([['public.pool' => new Reference('public.pool')]], $clearer->getArguments());
|
||||
$this->assertEquals([['public.pool' => new Reference('public.pool')]], $globalClearer->getArguments());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class CachePoolPassTest extends TestCase
|
||||
{
|
||||
private $cachePoolPass;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->cachePoolPass = new CachePoolPass();
|
||||
}
|
||||
|
||||
public function testNamespaceArgumentIsReplaced()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setParameter('kernel.debug', false);
|
||||
$container->setParameter('kernel.name', 'app');
|
||||
$container->setParameter('kernel.environment', 'prod');
|
||||
$container->setParameter('kernel.root_dir', 'foo');
|
||||
$adapter = new Definition();
|
||||
$adapter->setAbstract(true);
|
||||
$adapter->addTag('cache.pool');
|
||||
$container->setDefinition('app.cache_adapter', $adapter);
|
||||
$container->setAlias('app.cache_adapter_alias', 'app.cache_adapter');
|
||||
$cachePool = new ChildDefinition('app.cache_adapter_alias');
|
||||
$cachePool->addArgument(null);
|
||||
$cachePool->addTag('cache.pool');
|
||||
$container->setDefinition('app.cache_pool', $cachePool);
|
||||
|
||||
$this->cachePoolPass->process($container);
|
||||
|
||||
$this->assertSame('D07rhFx97S', $cachePool->getArgument(0));
|
||||
}
|
||||
|
||||
public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setParameter('kernel.environment', 'prod');
|
||||
$container->setParameter('kernel.name', 'app');
|
||||
$container->setParameter('kernel.root_dir', 'foo');
|
||||
|
||||
$container->register('cache.adapter.array', ArrayAdapter::class)->addArgument(0);
|
||||
|
||||
$cachePool = new ChildDefinition('cache.adapter.array');
|
||||
$cachePool->addTag('cache.pool');
|
||||
$container->setDefinition('app.cache_pool', $cachePool);
|
||||
|
||||
$this->cachePoolPass->process($container);
|
||||
|
||||
$this->assertCount(0, $container->getDefinition('app.cache_pool')->getArguments());
|
||||
}
|
||||
|
||||
public function testArgsAreReplaced()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setParameter('kernel.debug', false);
|
||||
$container->setParameter('kernel.name', 'app');
|
||||
$container->setParameter('kernel.environment', 'prod');
|
||||
$container->setParameter('cache.prefix.seed', 'foo');
|
||||
$cachePool = new Definition();
|
||||
$cachePool->addTag('cache.pool', [
|
||||
'provider' => 'foobar',
|
||||
'default_lifetime' => 3,
|
||||
]);
|
||||
$cachePool->addArgument(null);
|
||||
$cachePool->addArgument(null);
|
||||
$cachePool->addArgument(null);
|
||||
$container->setDefinition('app.cache_pool', $cachePool);
|
||||
|
||||
$this->cachePoolPass->process($container);
|
||||
|
||||
$this->assertInstanceOf(Reference::class, $cachePool->getArgument(0));
|
||||
$this->assertSame('foobar', (string) $cachePool->getArgument(0));
|
||||
$this->assertSame('itantF+pIq', $cachePool->getArgument(1));
|
||||
$this->assertSame(3, $cachePool->getArgument(2));
|
||||
}
|
||||
|
||||
public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Invalid "cache.pool" tag for service "app.cache_pool": accepted attributes are');
|
||||
$container = new ContainerBuilder();
|
||||
$container->setParameter('kernel.debug', false);
|
||||
$container->setParameter('kernel.name', 'app');
|
||||
$container->setParameter('kernel.environment', 'prod');
|
||||
$container->setParameter('kernel.root_dir', 'foo');
|
||||
$adapter = new Definition();
|
||||
$adapter->setAbstract(true);
|
||||
$adapter->addTag('cache.pool');
|
||||
$container->setDefinition('app.cache_adapter', $adapter);
|
||||
$cachePool = new ChildDefinition('app.cache_adapter');
|
||||
$cachePool->addTag('cache.pool', ['foobar' => 123]);
|
||||
$container->setDefinition('app.cache_pool', $cachePool);
|
||||
|
||||
$this->cachePoolPass->process($container);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPrunerPass;
|
||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
|
||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class CachePoolPrunerPassTest extends TestCase
|
||||
{
|
||||
public function testCompilerPassReplacesCommandArgument()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('console.command.cache_pool_prune')->addArgument([]);
|
||||
$container->register('pool.foo', FilesystemAdapter::class)->addTag('cache.pool');
|
||||
$container->register('pool.bar', PhpFilesAdapter::class)->addTag('cache.pool');
|
||||
|
||||
$pass = new CachePoolPrunerPass();
|
||||
$pass->process($container);
|
||||
|
||||
$expected = [
|
||||
'pool.foo' => new Reference('pool.foo'),
|
||||
'pool.bar' => new Reference('pool.bar'),
|
||||
];
|
||||
$argument = $container->getDefinition('console.command.cache_pool_prune')->getArgument(0);
|
||||
|
||||
$this->assertInstanceOf(IteratorArgument::class, $argument);
|
||||
$this->assertEquals($expected, $argument->getValues());
|
||||
}
|
||||
|
||||
public function testCompilePassIsIgnoredIfCommandDoesNotExist()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definitionsBefore = \count($container->getDefinitions());
|
||||
$aliasesBefore = \count($container->getAliases());
|
||||
|
||||
$pass = new CachePoolPrunerPass();
|
||||
$pass->process($container);
|
||||
|
||||
// the container is untouched (i.e. no new definitions or aliases)
|
||||
$this->assertCount($definitionsBefore, $container->getDefinitions());
|
||||
$this->assertCount($aliasesBefore, $container->getAliases());
|
||||
}
|
||||
|
||||
public function testCompilerPassThrowsOnInvalidDefinitionClass()
|
||||
{
|
||||
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Class "Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\NotFound" used for service "pool.not-found" cannot be found.');
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('console.command.cache_pool_prune')->addArgument([]);
|
||||
$container->register('pool.not-found', NotFound::class)->addTag('cache.pool');
|
||||
|
||||
$pass = new CachePoolPrunerPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
}
|
||||
@@ -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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass;
|
||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ConfigCachePassTest extends TestCase
|
||||
{
|
||||
public function testThatCheckersAreProcessedInPriorityOrder()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definition = $container->register('config_cache_factory')->addArgument(null);
|
||||
$container->register('checker_2')->addTag('config_cache.resource_checker', ['priority' => 100]);
|
||||
$container->register('checker_1')->addTag('config_cache.resource_checker', ['priority' => 200]);
|
||||
$container->register('checker_3')->addTag('config_cache.resource_checker');
|
||||
|
||||
$pass = new ConfigCachePass();
|
||||
$pass->process($container);
|
||||
|
||||
$expected = new IteratorArgument([
|
||||
new Reference('checker_1'),
|
||||
new Reference('checker_2'),
|
||||
new Reference('checker_3'),
|
||||
]);
|
||||
$this->assertEquals($expected, $definition->getArgument(0));
|
||||
}
|
||||
|
||||
public function testThatCheckersCanBeMissing()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definitionsBefore = \count($container->getDefinitions());
|
||||
$aliasesBefore = \count($container->getAliases());
|
||||
|
||||
$pass = new ConfigCachePass();
|
||||
$pass->process($container);
|
||||
|
||||
// the container is untouched (i.e. no new definitions or aliases)
|
||||
$this->assertCount($definitionsBefore, $container->getDefinitions());
|
||||
$this->assertCount($aliasesBefore, $container->getAliases());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ControllerArgumentValueResolverPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ControllerArgumentValueResolverPassTest extends TestCase
|
||||
{
|
||||
public function testServicesAreOrderedAccordingToPriority()
|
||||
{
|
||||
$services = [
|
||||
'n3' => [[]],
|
||||
'n1' => [['priority' => 200]],
|
||||
'n2' => [['priority' => 100]],
|
||||
];
|
||||
|
||||
$expected = [
|
||||
new Reference('n1'),
|
||||
new Reference('n2'),
|
||||
new Reference('n3'),
|
||||
];
|
||||
|
||||
$definition = new Definition(ArgumentResolver::class, [null, []]);
|
||||
$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, [null, []]);
|
||||
$container = new ContainerBuilder();
|
||||
$container->setDefinition('argument_resolver', $definition);
|
||||
|
||||
(new ControllerArgumentValueResolverPass())->process($container);
|
||||
$this->assertEquals([], $definition->getArgument(1)->getValues());
|
||||
}
|
||||
|
||||
public function testNoArgumentResolver()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
(new ControllerArgumentValueResolverPass())->process($container);
|
||||
|
||||
$this->assertFalse($container->hasDefinition('argument_resolver'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
class DataCollectorTranslatorPassTest extends TestCase
|
||||
{
|
||||
private $container;
|
||||
private $dataCollectorTranslatorPass;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->container = new ContainerBuilder();
|
||||
$this->dataCollectorTranslatorPass = new DataCollectorTranslatorPass();
|
||||
|
||||
$this->container->setParameter('translator_implementing_bag', 'Symfony\Component\Translation\Translator');
|
||||
$this->container->setParameter('translator_not_implementing_bag', 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TranslatorWithTranslatorBag');
|
||||
|
||||
$this->container->register('translator.data_collector', 'Symfony\Component\Translation\DataCollectorTranslator')
|
||||
->setPublic(false)
|
||||
->setDecoratedService('translator')
|
||||
->setArguments([new Reference('translator.data_collector.inner')])
|
||||
;
|
||||
|
||||
$this->container->register('data_collector.translation', 'Symfony\Component\Translation\DataCollector\TranslationDataCollector')
|
||||
->setArguments([new Reference('translator.data_collector')])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getImplementingTranslatorBagInterfaceTranslatorClassNames
|
||||
*/
|
||||
public function testProcessKeepsDataCollectorTranslatorIfItImplementsTranslatorBagInterface($class)
|
||||
{
|
||||
$this->container->register('translator', $class);
|
||||
|
||||
$this->dataCollectorTranslatorPass->process($this->container);
|
||||
|
||||
$this->assertTrue($this->container->hasDefinition('translator.data_collector'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getImplementingTranslatorBagInterfaceTranslatorClassNames
|
||||
*/
|
||||
public function testProcessKeepsDataCollectorIfTranslatorImplementsTranslatorBagInterface($class)
|
||||
{
|
||||
$this->container->register('translator', $class);
|
||||
|
||||
$this->dataCollectorTranslatorPass->process($this->container);
|
||||
|
||||
$this->assertTrue($this->container->hasDefinition('data_collector.translation'));
|
||||
}
|
||||
|
||||
public function getImplementingTranslatorBagInterfaceTranslatorClassNames()
|
||||
{
|
||||
return [
|
||||
['Symfony\Component\Translation\Translator'],
|
||||
['%translator_implementing_bag%'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getNotImplementingTranslatorBagInterfaceTranslatorClassNames
|
||||
*/
|
||||
public function testProcessRemovesDataCollectorTranslatorIfItDoesNotImplementTranslatorBagInterface($class)
|
||||
{
|
||||
$this->container->register('translator', $class);
|
||||
|
||||
$this->dataCollectorTranslatorPass->process($this->container);
|
||||
|
||||
$this->assertFalse($this->container->hasDefinition('translator.data_collector'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getNotImplementingTranslatorBagInterfaceTranslatorClassNames
|
||||
*/
|
||||
public function testProcessRemovesDataCollectorIfTranslatorDoesNotImplementTranslatorBagInterface($class)
|
||||
{
|
||||
$this->container->register('translator', $class);
|
||||
|
||||
$this->dataCollectorTranslatorPass->process($this->container);
|
||||
|
||||
$this->assertFalse($this->container->hasDefinition('data_collector.translation'));
|
||||
}
|
||||
|
||||
public function getNotImplementingTranslatorBagInterfaceTranslatorClassNames()
|
||||
{
|
||||
return [
|
||||
['Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TranslatorWithTranslatorBag'],
|
||||
['%translator_not_implementing_bag%'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class TranslatorWithTranslatorBag implements TranslatorInterface
|
||||
{
|
||||
public function trans($id, array $parameters = [], $domain = null, $locale = null)
|
||||
{
|
||||
}
|
||||
|
||||
public function transChoice($id, $number, array $parameters = [], $domain = null, $locale = null)
|
||||
{
|
||||
}
|
||||
|
||||
public function setLocale($locale)
|
||||
{
|
||||
}
|
||||
|
||||
public function getLocale()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
<?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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class FormPassTest extends TestCase
|
||||
{
|
||||
public function testDoNothingIfFormExtensionNotLoaded()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new FormPass());
|
||||
|
||||
$container->compile();
|
||||
|
||||
$this->assertFalse($container->hasDefinition('form.extension'));
|
||||
}
|
||||
|
||||
public function testAddTaggedTypes()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new FormPass());
|
||||
|
||||
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension');
|
||||
$extDefinition->setPublic(true);
|
||||
$extDefinition->setArguments([
|
||||
new Reference('service_container'),
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
]);
|
||||
|
||||
$container->setDefinition('form.extension', $extDefinition);
|
||||
$container->register('my.type1', __CLASS__.'_Type1')->addTag('form.type')->setPublic(true);
|
||||
$container->register('my.type2', __CLASS__.'_Type2')->addTag('form.type')->setPublic(true);
|
||||
|
||||
$container->compile();
|
||||
|
||||
$extDefinition = $container->getDefinition('form.extension');
|
||||
|
||||
$this->assertEquals([
|
||||
__CLASS__.'_Type1' => 'my.type1',
|
||||
__CLASS__.'_Type2' => 'my.type2',
|
||||
], $extDefinition->getArgument(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider addTaggedTypeExtensionsDataProvider
|
||||
*/
|
||||
public function testAddTaggedTypeExtensions(array $extensions, array $expectedRegisteredExtensions)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new FormPass());
|
||||
|
||||
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension', [
|
||||
new Reference('service_container'),
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
]);
|
||||
$extDefinition->setPublic(true);
|
||||
|
||||
$container->setDefinition('form.extension', $extDefinition);
|
||||
|
||||
foreach ($extensions as $serviceId => $tag) {
|
||||
$container->register($serviceId, 'stdClass')->addTag('form.type_extension', $tag);
|
||||
}
|
||||
|
||||
$container->compile();
|
||||
|
||||
$extDefinition = $container->getDefinition('form.extension');
|
||||
$this->assertSame($expectedRegisteredExtensions, $extDefinition->getArgument(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function addTaggedTypeExtensionsDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
[
|
||||
'my.type_extension1' => ['extended_type' => 'type1'],
|
||||
'my.type_extension2' => ['extended_type' => 'type1'],
|
||||
'my.type_extension3' => ['extended_type' => 'type2'],
|
||||
],
|
||||
[
|
||||
'type1' => ['my.type_extension1', 'my.type_extension2'],
|
||||
'type2' => ['my.type_extension3'],
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
'my.type_extension1' => ['extended_type' => 'type1', 'priority' => 1],
|
||||
'my.type_extension2' => ['extended_type' => 'type1', 'priority' => 2],
|
||||
'my.type_extension3' => ['extended_type' => 'type1', 'priority' => -1],
|
||||
'my.type_extension4' => ['extended_type' => 'type2', 'priority' => 2],
|
||||
'my.type_extension5' => ['extended_type' => 'type2', 'priority' => 1],
|
||||
'my.type_extension6' => ['extended_type' => 'type2', 'priority' => 1],
|
||||
],
|
||||
[
|
||||
'type1' => ['my.type_extension2', 'my.type_extension1', 'my.type_extension3'],
|
||||
'type2' => ['my.type_extension4', 'my.type_extension5', 'my.type_extension6'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testAddTaggedFormTypeExtensionWithoutExtendedTypeAttribute()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$this->expectExceptionMessage('extended-type attribute, none was configured for the "my.type_extension" service');
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new FormPass());
|
||||
|
||||
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension', [
|
||||
new Reference('service_container'),
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
]);
|
||||
$extDefinition->setPublic(true);
|
||||
|
||||
$container->setDefinition('form.extension', $extDefinition);
|
||||
$container->register('my.type_extension', 'stdClass')
|
||||
->addTag('form.type_extension');
|
||||
|
||||
$container->compile();
|
||||
}
|
||||
|
||||
public function testAddTaggedGuessers()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new FormPass());
|
||||
|
||||
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension');
|
||||
$extDefinition->setPublic(true);
|
||||
$extDefinition->setArguments([
|
||||
new Reference('service_container'),
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
]);
|
||||
|
||||
$definition1 = new Definition('stdClass');
|
||||
$definition1->addTag('form.type_guesser');
|
||||
$definition2 = new Definition('stdClass');
|
||||
$definition2->addTag('form.type_guesser');
|
||||
|
||||
$container->setDefinition('form.extension', $extDefinition);
|
||||
$container->setDefinition('my.guesser1', $definition1);
|
||||
$container->setDefinition('my.guesser2', $definition2);
|
||||
|
||||
$container->compile();
|
||||
|
||||
$extDefinition = $container->getDefinition('form.extension');
|
||||
|
||||
$this->assertSame([
|
||||
'my.guesser1',
|
||||
'my.guesser2',
|
||||
], $extDefinition->getArgument(3));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider privateTaggedServicesProvider
|
||||
*/
|
||||
public function testPrivateTaggedServices($id, $tagName)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new FormPass());
|
||||
|
||||
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension');
|
||||
$extDefinition->setArguments([
|
||||
new Reference('service_container'),
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
]);
|
||||
|
||||
$container->setDefinition('form.extension', $extDefinition);
|
||||
$container->register($id, 'stdClass')->setPublic(false)->addTag($tagName, ['extended_type' => 'Foo']);
|
||||
|
||||
$container->compile();
|
||||
$this->assertTrue($container->getDefinition($id)->isPublic());
|
||||
}
|
||||
|
||||
public function privateTaggedServicesProvider()
|
||||
{
|
||||
return [
|
||||
['my.type', 'form.type'],
|
||||
['my.type_extension', 'form.type_extension'],
|
||||
['my.guesser', 'form.type_guesser'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class LoggingTranslatorPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setParameter('translator.logging', true);
|
||||
$container->setParameter('translator.class', 'Symfony\Component\Translation\Translator');
|
||||
$container->register('monolog.logger');
|
||||
$container->setAlias('logger', 'monolog.logger');
|
||||
$container->register('translator.default', '%translator.class%');
|
||||
$container->register('translator.logging', '%translator.class%');
|
||||
$container->setAlias('translator', 'translator.default');
|
||||
$translationWarmerDefinition = $container->register('translation.warmer')
|
||||
->addArgument(new Reference('translator'))
|
||||
->addTag('container.service_subscriber', ['id' => 'translator'])
|
||||
->addTag('container.service_subscriber', ['id' => 'foo']);
|
||||
|
||||
$pass = new LoggingTranslatorPass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertEquals(
|
||||
['container.service_subscriber' => [
|
||||
['id' => 'foo'],
|
||||
['key' => 'translator', 'id' => 'translator.logging.inner'],
|
||||
]],
|
||||
$translationWarmerDefinition->getTags()
|
||||
);
|
||||
}
|
||||
|
||||
public function testThatCompilerPassIsIgnoredIfThereIsNotLoggerDefinition()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('identity_translator');
|
||||
$container->setAlias('translator', 'identity_translator');
|
||||
|
||||
$definitionsBefore = \count($container->getDefinitions());
|
||||
$aliasesBefore = \count($container->getAliases());
|
||||
|
||||
$pass = new LoggingTranslatorPass();
|
||||
$pass->process($container);
|
||||
|
||||
// the container is untouched (i.e. no new definitions or aliases)
|
||||
$this->assertCount($definitionsBefore, $container->getDefinitions());
|
||||
$this->assertCount($aliasesBefore, $container->getAliases());
|
||||
}
|
||||
|
||||
public function testThatCompilerPassIsIgnoredIfThereIsNotTranslatorDefinition()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('monolog.logger');
|
||||
$container->setAlias('logger', 'monolog.logger');
|
||||
|
||||
$definitionsBefore = \count($container->getDefinitions());
|
||||
$aliasesBefore = \count($container->getAliases());
|
||||
|
||||
$pass = new LoggingTranslatorPass();
|
||||
$pass->process($container);
|
||||
|
||||
// the container is untouched (i.e. no new definitions or aliases)
|
||||
$this->assertCount($definitionsBefore, $container->getDefinitions());
|
||||
$this->assertCount($aliasesBefore, $container->getAliases());
|
||||
}
|
||||
}
|
||||
@@ -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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
class ProfilerPassTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Tests that collectors that specify a template but no "id" will throw
|
||||
* an exception (both are needed if the template is specified).
|
||||
*
|
||||
* Thus, a fully-valid tag looks something like this:
|
||||
*
|
||||
* <tag name="data_collector" template="YourBundle:Collector:templatename" id="your_collector_name" />
|
||||
*/
|
||||
public function testTemplateNoIdThrowsException()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$builder = new ContainerBuilder();
|
||||
$builder->register('profiler', 'ProfilerClass');
|
||||
$builder->register('my_collector_service')
|
||||
->addTag('data_collector', ['template' => 'foo']);
|
||||
|
||||
$profilerPass = new ProfilerPass();
|
||||
$profilerPass->process($builder);
|
||||
}
|
||||
|
||||
public function testValidCollector()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$profilerDefinition = $container->register('profiler', 'ProfilerClass');
|
||||
$container->register('my_collector_service')
|
||||
->addTag('data_collector', ['template' => 'foo', 'id' => 'my_collector']);
|
||||
|
||||
$profilerPass = new ProfilerPass();
|
||||
$profilerPass->process($container);
|
||||
|
||||
$this->assertSame(['my_collector_service' => ['my_collector', 'foo']], $container->getParameter('data_collector.templates'));
|
||||
|
||||
// grab the method calls off of the "profiler" definition
|
||||
$methodCalls = $profilerDefinition->getMethodCalls();
|
||||
$this->assertCount(1, $methodCalls);
|
||||
$this->assertEquals('add', $methodCalls[0][0]); // grab the method part of the first call
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass;
|
||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class PropertyInfoPassTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideTags
|
||||
*/
|
||||
public function testServicesAreOrderedAccordingToPriority($index, $tag)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definition = $container->register('property_info')->setArguments([null, null, null, null]);
|
||||
$container->register('n2')->addTag($tag, ['priority' => 100]);
|
||||
$container->register('n1')->addTag($tag, ['priority' => 200]);
|
||||
$container->register('n3')->addTag($tag);
|
||||
|
||||
$propertyInfoPass = new PropertyInfoPass();
|
||||
$propertyInfoPass->process($container);
|
||||
|
||||
$expected = new IteratorArgument([
|
||||
new Reference('n1'),
|
||||
new Reference('n2'),
|
||||
new Reference('n3'),
|
||||
]);
|
||||
$this->assertEquals($expected, $definition->getArgument($index));
|
||||
}
|
||||
|
||||
public function provideTags()
|
||||
{
|
||||
return [
|
||||
[0, 'property_info.list_extractor'],
|
||||
[1, 'property_info.type_extractor'],
|
||||
[2, 'property_info.description_extractor'],
|
||||
[3, 'property_info.access_extractor'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testReturningEmptyArrayWhenNoService()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$propertyInfoExtractorDefinition = $container->register('property_info')
|
||||
->setArguments([[], [], [], []]);
|
||||
|
||||
$propertyInfoPass = new PropertyInfoPass();
|
||||
$propertyInfoPass->process($container);
|
||||
|
||||
$this->assertEquals(new IteratorArgument([]), $propertyInfoExtractorDefinition->getArgument(0));
|
||||
$this->assertEquals(new IteratorArgument([]), $propertyInfoExtractorDefinition->getArgument(1));
|
||||
$this->assertEquals(new IteratorArgument([]), $propertyInfoExtractorDefinition->getArgument(2));
|
||||
$this->assertEquals(new IteratorArgument([]), $propertyInfoExtractorDefinition->getArgument(3));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Tests for the SerializerPass class.
|
||||
*
|
||||
* @group legacy
|
||||
*
|
||||
* @author Javier Lopez <f12loalf@gmail.com>
|
||||
*/
|
||||
class SerializerPassTest extends TestCase
|
||||
{
|
||||
public function testThrowExceptionWhenNoNormalizers()
|
||||
{
|
||||
$this->expectException('RuntimeException');
|
||||
$this->expectExceptionMessage('You must tag at least one service as "serializer.normalizer" to use the "serializer" service');
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('serializer');
|
||||
|
||||
$serializerPass = new SerializerPass();
|
||||
$serializerPass->process($container);
|
||||
}
|
||||
|
||||
public function testThrowExceptionWhenNoEncoders()
|
||||
{
|
||||
$this->expectException('RuntimeException');
|
||||
$this->expectExceptionMessage('You must tag at least one service as "serializer.encoder" to use the "serializer" service');
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('serializer')
|
||||
->addArgument([])
|
||||
->addArgument([]);
|
||||
$container->register('normalizer')->addTag('serializer.normalizer');
|
||||
|
||||
$serializerPass = new SerializerPass();
|
||||
$serializerPass->process($container);
|
||||
}
|
||||
|
||||
public function testServicesAreOrderedAccordingToPriority()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definition = $container->register('serializer')->setArguments([null, null]);
|
||||
$container->register('n2')->addTag('serializer.normalizer', ['priority' => 100])->addTag('serializer.encoder', ['priority' => 100]);
|
||||
$container->register('n1')->addTag('serializer.normalizer', ['priority' => 200])->addTag('serializer.encoder', ['priority' => 200]);
|
||||
$container->register('n3')->addTag('serializer.normalizer')->addTag('serializer.encoder');
|
||||
|
||||
$serializerPass = new SerializerPass();
|
||||
$serializerPass->process($container);
|
||||
|
||||
$expected = [
|
||||
new Reference('n1'),
|
||||
new Reference('n2'),
|
||||
new Reference('n3'),
|
||||
];
|
||||
$this->assertEquals($expected, $definition->getArgument(0));
|
||||
$this->assertEquals($expected, $definition->getArgument(1));
|
||||
}
|
||||
}
|
||||
@@ -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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class TranslatorPassTest extends TestCase
|
||||
{
|
||||
public function testValidCollector()
|
||||
{
|
||||
$loader = (new Definition())
|
||||
->addTag('translation.loader', ['alias' => 'xliff', 'legacy-alias' => 'xlf']);
|
||||
|
||||
$translator = (new Definition())
|
||||
->setArguments([null, null, null, null]);
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->setDefinition('translator.default', $translator);
|
||||
$container->setDefinition('translation.loader', $loader);
|
||||
|
||||
$pass = new TranslatorPass();
|
||||
$pass->process($container);
|
||||
|
||||
$expected = (new Definition())
|
||||
->addTag('translation.loader', ['alias' => 'xliff', 'legacy-alias' => 'xlf'])
|
||||
->addMethodCall('addLoader', ['xliff', new Reference('translation.loader')])
|
||||
->addMethodCall('addLoader', ['xlf', new Reference('translation.loader')])
|
||||
;
|
||||
$this->assertEquals($expected, $loader);
|
||||
|
||||
$this->assertSame(['translation.loader' => ['xliff', 'xlf']], $translator->getArgument(3));
|
||||
|
||||
$expected = ['translation.loader' => new ServiceClosureArgument(new Reference('translation.loader'))];
|
||||
$this->assertEquals($expected, $container->getDefinition((string) $translator->getArgument(0))->getArgument(0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
class UnusedTagsPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$pass = new UnusedTagsPass();
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('foo')
|
||||
->addTag('kenrel.event_subscriber');
|
||||
$container->register('bar')
|
||||
->addTag('kenrel.event_subscriber');
|
||||
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertSame([sprintf('%s: Tag "kenrel.event_subscriber" was defined on service(s) "foo", "bar", but was never used. Did you mean "kernel.event_subscriber"?', UnusedTagsPass::class)], $container->getCompiler()->getLog());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\WorkflowGuardListenerPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
use Symfony\Component\Security\Core\Role\RoleHierarchy;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
class WorkflowGuardListenerPassTest extends TestCase
|
||||
{
|
||||
private $container;
|
||||
private $compilerPass;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->container = new ContainerBuilder();
|
||||
$this->compilerPass = new WorkflowGuardListenerPass();
|
||||
}
|
||||
|
||||
public function testNoExeptionIfParameterIsNotSet()
|
||||
{
|
||||
$this->compilerPass->process($this->container);
|
||||
|
||||
$this->assertFalse($this->container->hasParameter('workflow.has_guard_listeners'));
|
||||
}
|
||||
|
||||
public function testNoExeptionIfAllDependenciesArePresent()
|
||||
{
|
||||
$this->container->setParameter('workflow.has_guard_listeners', true);
|
||||
$this->container->register('security.token_storage', TokenStorageInterface::class);
|
||||
$this->container->register('security.authorization_checker', AuthorizationCheckerInterface::class);
|
||||
$this->container->register('security.authentication.trust_resolver', AuthenticationTrustResolverInterface::class);
|
||||
$this->container->register('security.role_hierarchy', RoleHierarchy::class);
|
||||
$this->container->register('validator', ValidatorInterface::class);
|
||||
|
||||
$this->compilerPass->process($this->container);
|
||||
|
||||
$this->assertFalse($this->container->hasParameter('workflow.has_guard_listeners'));
|
||||
}
|
||||
|
||||
public function testExceptionIfTheTokenStorageServiceIsNotPresent()
|
||||
{
|
||||
$this->expectException('Symfony\Component\DependencyInjection\Exception\LogicException');
|
||||
$this->expectExceptionMessage('The "security.token_storage" service is needed to be able to use the workflow guard listener.');
|
||||
$this->container->setParameter('workflow.has_guard_listeners', true);
|
||||
$this->container->register('security.authorization_checker', AuthorizationCheckerInterface::class);
|
||||
$this->container->register('security.authentication.trust_resolver', AuthenticationTrustResolverInterface::class);
|
||||
$this->container->register('security.role_hierarchy', RoleHierarchy::class);
|
||||
|
||||
$this->compilerPass->process($this->container);
|
||||
}
|
||||
|
||||
public function testExceptionIfTheAuthorizationCheckerServiceIsNotPresent()
|
||||
{
|
||||
$this->expectException('Symfony\Component\DependencyInjection\Exception\LogicException');
|
||||
$this->expectExceptionMessage('The "security.authorization_checker" service is needed to be able to use the workflow guard listener.');
|
||||
$this->container->setParameter('workflow.has_guard_listeners', true);
|
||||
$this->container->register('security.token_storage', TokenStorageInterface::class);
|
||||
$this->container->register('security.authentication.trust_resolver', AuthenticationTrustResolverInterface::class);
|
||||
$this->container->register('security.role_hierarchy', RoleHierarchy::class);
|
||||
|
||||
$this->compilerPass->process($this->container);
|
||||
}
|
||||
|
||||
public function testExceptionIfTheAuthenticationTrustResolverServiceIsNotPresent()
|
||||
{
|
||||
$this->expectException('Symfony\Component\DependencyInjection\Exception\LogicException');
|
||||
$this->expectExceptionMessage('The "security.authentication.trust_resolver" service is needed to be able to use the workflow guard listener.');
|
||||
$this->container->setParameter('workflow.has_guard_listeners', true);
|
||||
$this->container->register('security.token_storage', TokenStorageInterface::class);
|
||||
$this->container->register('security.authorization_checker', AuthorizationCheckerInterface::class);
|
||||
$this->container->register('security.role_hierarchy', RoleHierarchy::class);
|
||||
|
||||
$this->compilerPass->process($this->container);
|
||||
}
|
||||
|
||||
public function testExceptionIfTheRoleHierarchyServiceIsNotPresent()
|
||||
{
|
||||
$this->expectException('Symfony\Component\DependencyInjection\Exception\LogicException');
|
||||
$this->expectExceptionMessage('The "security.role_hierarchy" service is needed to be able to use the workflow guard listener.');
|
||||
$this->container->setParameter('workflow.has_guard_listeners', true);
|
||||
$this->container->register('security.token_storage', TokenStorageInterface::class);
|
||||
$this->container->register('security.authorization_checker', AuthorizationCheckerInterface::class);
|
||||
$this->container->register('security.authentication.trust_resolver', AuthenticationTrustResolverInterface::class);
|
||||
|
||||
$this->compilerPass->process($this->container);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user