bug #23469 [FrameworkBundle] do not wire namespaces for the ArrayAdapter (xabbuh)

This PR was merged into the 3.2 branch.

Discussion
----------

[FrameworkBundle] do not wire namespaces for the ArrayAdapter

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23214
| License       | MIT
| Doc PR        |

Commits
-------

9380614 do not wire namespaces for the ArrayAdapter
This commit is contained in:
Nicolas Grekas 2017-07-11 08:48:27 +02:00
commit 7fd523678a
2 changed files with 21 additions and 1 deletions

View File

@ -11,6 +11,7 @@
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\RedisAdapter;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@ -70,7 +71,7 @@ class CachePoolPass implements CompilerPassInterface
}
$i = 0;
foreach ($attributes as $attr) {
if (isset($tags[0][$attr])) {
if (isset($tags[0][$attr]) && ('namespace' !== $attr || ArrayAdapter::class !== $adapter->getClass())) {
$pool->replaceArgument($i++, $tags[0][$attr]);
}
unset($tags[0][$attr]);

View File

@ -13,6 +13,7 @@ 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\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
@ -49,6 +50,24 @@ class CachePoolPassTest extends TestCase
$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 DefinitionDecorator('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();