ProfilerPassTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. class ProfilerPassTest extends TestCase
  15. {
  16. /**
  17. * Tests that collectors that specify a template but no "id" will throw
  18. * an exception (both are needed if the template is specified).
  19. *
  20. * Thus, a fully-valid tag looks something like this:
  21. *
  22. * <tag name="data_collector" template="YourBundle:Collector:templatename" id="your_collector_name" />
  23. *
  24. * @expectedException \InvalidArgumentException
  25. */
  26. public function testTemplateNoIdThrowsException()
  27. {
  28. $builder = new ContainerBuilder();
  29. $builder->register('profiler', 'ProfilerClass');
  30. $builder->register('my_collector_service')
  31. ->addTag('data_collector', array('template' => 'foo'));
  32. $profilerPass = new ProfilerPass();
  33. $profilerPass->process($builder);
  34. }
  35. public function testValidCollector()
  36. {
  37. $container = new ContainerBuilder();
  38. $profilerDefinition = $container->register('profiler', 'ProfilerClass');
  39. $container->register('my_collector_service')
  40. ->addTag('data_collector', array('template' => 'foo', 'id' => 'my_collector'));
  41. $profilerPass = new ProfilerPass();
  42. $profilerPass->process($container);
  43. $this->assertSame(array('my_collector_service' => array('my_collector', 'foo')), $container->getParameter('data_collector.templates'));
  44. // grab the method calls off of the "profiler" definition
  45. $methodCalls = $profilerDefinition->getMethodCalls();
  46. $this->assertCount(1, $methodCalls);
  47. $this->assertEquals('add', $methodCalls[0][0]); // grab the method part of the first call
  48. }
  49. }