LegacyFragmentRendererPassTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\FragmentRendererPass;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Reference;
  15. use Symfony\Component\HttpFoundation\Request;
  16. /**
  17. * @group legacy
  18. */
  19. class LegacyFragmentRendererPassTest extends TestCase
  20. {
  21. /**
  22. * Tests that content rendering not implementing FragmentRendererInterface
  23. * trigger an exception.
  24. *
  25. * @expectedException \InvalidArgumentException
  26. */
  27. public function testContentRendererWithoutInterface()
  28. {
  29. $builder = new ContainerBuilder();
  30. $builder->register('fragment.handler');
  31. $builder->register('my_content_renderer', 'stdClass')
  32. ->addTag('kernel.fragment_renderer');
  33. $pass = new FragmentRendererPass();
  34. $pass->process($builder);
  35. }
  36. public function testValidContentRenderer()
  37. {
  38. $builder = new ContainerBuilder();
  39. $fragmentHandlerDefinition = $builder->register('fragment.handler');
  40. $builder->register('my_content_renderer', 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\RendererService')
  41. ->addTag('kernel.fragment_renderer');
  42. $pass = new FragmentRendererPass();
  43. $pass->process($builder);
  44. $this->assertEquals(array(array('addRenderer', array(new Reference('my_content_renderer')))), $fragmentHandlerDefinition->getMethodCalls());
  45. }
  46. }
  47. class RendererService implements \Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface
  48. {
  49. public function render($uri, Request $request = null, array $options = array())
  50. {
  51. }
  52. public function getName()
  53. {
  54. return 'test';
  55. }
  56. }