CacheCollectorPassTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Cache\Tests\DependencyInjection;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Cache\Adapter\FilesystemAdapter;
  13. use Symfony\Component\Cache\Adapter\TagAwareAdapter;
  14. use Symfony\Component\Cache\Adapter\TraceableAdapter;
  15. use Symfony\Component\Cache\Adapter\TraceableTagAwareAdapter;
  16. use Symfony\Component\Cache\DataCollector\CacheDataCollector;
  17. use Symfony\Component\Cache\DependencyInjection\CacheCollectorPass;
  18. use Symfony\Component\DependencyInjection\ContainerBuilder;
  19. use Symfony\Component\DependencyInjection\Reference;
  20. class CacheCollectorPassTest extends TestCase
  21. {
  22. public function testProcess()
  23. {
  24. $container = new ContainerBuilder();
  25. $container
  26. ->register('fs', FilesystemAdapter::class)
  27. ->addTag('cache.pool');
  28. $container
  29. ->register('tagged_fs', TagAwareAdapter::class)
  30. ->addArgument(new Reference('fs'))
  31. ->addTag('cache.pool');
  32. $collector = $container->register('data_collector.cache', CacheDataCollector::class);
  33. (new CacheCollectorPass())->process($container);
  34. $this->assertEquals([
  35. ['addInstance', ['fs', new Reference('fs')]],
  36. ['addInstance', ['tagged_fs', new Reference('tagged_fs')]],
  37. ], $collector->getMethodCalls());
  38. $this->assertSame(TraceableAdapter::class, $container->findDefinition('fs')->getClass());
  39. $this->assertSame(TraceableTagAwareAdapter::class, $container->getDefinition('tagged_fs')->getClass());
  40. $this->assertFalse($collector->isPublic(), 'The "data_collector.cache" should be private after processing');
  41. }
  42. }