ExceptionControllerTest.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /*
  3. * This file is part of the Symfony framework.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\Bundle\WebProfilerBundle\Tests\Controller;
  11. use Symfony\Bundle\WebProfilerBundle\Tests\TestCase;
  12. use Symfony\Bundle\WebProfilerBundle\Controller\ExceptionController;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Reference;
  15. use Symfony\Component\DependencyInjection\Scope;
  16. use Symfony\Component\DependencyInjection\Definition;
  17. class ExceptionControllerTest extends TestCase
  18. {
  19. protected $controller;
  20. protected $container;
  21. protected $flatten;
  22. protected $kernel;
  23. protected function setUp()
  24. {
  25. parent::setUp();
  26. $this->flatten = $this->getMock('Symfony\Component\HttpKernel\Exception\FlattenException');
  27. $this->flatten->expects($this->once())->method('getStatusCode')->will($this->returnValue(404));
  28. $this->controller = new ExceptionController();
  29. $this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface');
  30. $this->container = $this->getContainer();
  31. }
  32. /**
  33. * @dataProvider getDebugModes
  34. */
  35. public function testShowActionDependingOnDebug($debug)
  36. {
  37. $this->container->setParameter('kernel.debug', $debug);
  38. $this->controller->setContainer($this->container);
  39. $this->controller->showAction($this->flatten);
  40. }
  41. public function getDebugModes()
  42. {
  43. return array(
  44. array(true),
  45. array(false),
  46. );
  47. }
  48. private function getContainer()
  49. {
  50. $container = new ContainerBuilder();
  51. $container->addScope(new Scope('request'));
  52. $container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request');
  53. $container->register('templating.helper.assets', $this->getMockClass('Symfony\\Component\\Templating\\Helper\\AssetsHelper'));
  54. $container->register('templating.helper.router', $this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\RouterHelper'))
  55. ->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Routing\\RouterInterface')));
  56. $container->register('twig', 'Twig_Environment');
  57. $container->register('templating.engine.twig',$this->getMockClass('Symfony\\Bundle\\TwigBundle\\TwigEngine'))
  58. ->addArgument($this->getMock('Twig_Environment'))
  59. ->addArgument($this->getMock('Symfony\\Component\\Templating\\TemplateNameParserInterface'))
  60. ->addArgument($this->getMock('Symfony\\Bundle\\FrameworkBundle\\Templating\\GlobalVariables', array(), array($this->getMock('Symfony\\Component\\DependencyInjection\\Container'))));
  61. $container->setAlias('templating', 'templating.engine.twig');
  62. $container->setParameter('kernel.bundles', array());
  63. $container->setParameter('kernel.cache_dir', __DIR__);
  64. $container->setParameter('kernel.root_dir', __DIR__);
  65. $container->set('kernel', $this->kernel);
  66. return $container;
  67. }
  68. }