|
19 | 19 | use Symfony\Component\Cache\Adapter\TraceableTagAwareAdapter;
|
20 | 20 | use Symfony\Component\Cache\DataCollector\CacheDataCollector;
|
21 | 21 | use Symfony\Component\Cache\DependencyInjection\CacheCollectorPass;
|
| 22 | +use Symfony\Component\Cache\Tests\Fixtures\ArrayCache; |
| 23 | +use Symfony\Component\DependencyInjection\Compiler\PassConfig; |
22 | 24 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
23 | 25 | use Symfony\Component\DependencyInjection\Reference;
|
24 | 26 |
|
@@ -48,16 +50,51 @@ public function testProcess()
|
48 | 50 | $this->assertEquals([
|
49 | 51 | ['addInstance', ['fs', new Reference('fs')]],
|
50 | 52 | ['addInstance', ['tagged_fs', new Reference('tagged_fs')]],
|
51 |
| - ['addInstance', ['.php.inner', new Reference('.php.inner')]], |
52 |
| - ['addInstance', ['php', new Reference('php')]], |
| 53 | + ['addInstance', ['php', new Reference('.php.inner')]], |
53 | 54 | ], $collector->getMethodCalls());
|
54 | 55 |
|
55 | 56 | $this->assertSame(TraceableAdapter::class, $container->findDefinition('fs')->getClass());
|
56 | 57 | $this->assertSame(TraceableTagAwareAdapter::class, $container->getDefinition('tagged_fs')->getClass());
|
57 | 58 |
|
58 | 59 | $this->assertSame(TraceableAdapter::class, $container->findDefinition('.php.inner')->getClass());
|
59 |
| - $this->assertSame(TraceableTagAwareAdapter::class, $container->getDefinition('php')->getClass()); |
| 60 | + $this->assertSame(TagAwareAdapter::class, $container->getDefinition('php')->getClass()); |
60 | 61 |
|
61 | 62 | $this->assertFalse($collector->isPublic(), 'The "data_collector.cache" should be private after processing');
|
62 | 63 | }
|
| 64 | + |
| 65 | + public function testProcessCacheObjectsAreDecorated() |
| 66 | + { |
| 67 | + $container = new ContainerBuilder(); |
| 68 | + $collector = $container->register('data_collector.cache', CacheDataCollector::class); |
| 69 | + |
| 70 | + $container |
| 71 | + ->register('cache.object', ArrayCache::class) |
| 72 | + ->addTag('cache.pool', ['name' => 'cache.object']); |
| 73 | + |
| 74 | + $container |
| 75 | + ->register('something_is_decorating_cache_object', TagAwareAdapter::class) |
| 76 | + ->setPublic(true) |
| 77 | + ->setDecoratedService('cache.object'); |
| 78 | + |
| 79 | + $container->register('some_service_using_cache_object', TraceableAdapter::class) |
| 80 | + ->setPublic(true) |
| 81 | + ->addArgument(new Reference('cache.object')); |
| 82 | + |
| 83 | + $container->addCompilerPass(new CacheCollectorPass(), PassConfig::TYPE_BEFORE_REMOVING); |
| 84 | + |
| 85 | + $container->compile(); |
| 86 | + $this->assertCount(1, $collector->getMethodCalls()); |
| 87 | + $this->assertEquals( |
| 88 | + [ |
| 89 | + [ |
| 90 | + 'addInstance', |
| 91 | + [ |
| 92 | + 'cache.object', |
| 93 | + new Reference('something_is_decorating_cache_object'), |
| 94 | + ], |
| 95 | + ], |
| 96 | + ], |
| 97 | + $collector->getMethodCalls() |
| 98 | + ); |
| 99 | + } |
63 | 100 | }
|
0 commit comments