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