|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Chris\Bundle\FrontRenderBundle\Tests\Listener; |
|
4
|
|
|
|
|
5
|
|
|
use Chris\Bundle\FrontRenderBundle\Subscriber\RenderSubscriber; |
|
6
|
|
|
use Phake; |
|
7
|
|
|
use Phake_IMock; |
|
8
|
|
|
use PHPUnit_Framework_TestCase; |
|
9
|
|
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent; |
|
10
|
|
|
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; |
|
11
|
|
|
use Twig_Environment; |
|
12
|
|
|
use Twig_Loader_Filesystem; |
|
13
|
|
|
|
|
14
|
|
|
class ExceptionListenerTest extends PHPUnit_Framework_TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var string TEMPLATE_PATH |
|
18
|
|
|
*/ |
|
19
|
|
|
const TEMPLATE_PATH = 'Template'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var Twig_Loader_Filesystem |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $twigLoader; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var Twig_Environment|Phake_IMock |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $twigEnvironment; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var GetResponseEvent |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $responseEvent; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var GetResponseForExceptionEvent |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $exceptionEvent; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var RenderSubscriber |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $renderSubscriber; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritdoc} |
|
48
|
|
|
*/ |
|
49
|
|
|
public function setUp() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->twigLoader = Phake::partialMock(Twig_Loader_Filesystem::class, [__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . self::TEMPLATE_PATH]); |
|
|
|
|
|
|
52
|
|
|
$this->twigEnvironment = Phake::partialMock(Twig_Environment::class, $this->twigLoader); |
|
53
|
|
|
$this->responseEvent = Phake::mock(GetResponseEvent::class); |
|
|
|
|
|
|
54
|
|
|
$this->exceptionEvent = Phake::mock(GetResponseForExceptionEvent::class); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
$this->renderSubscriber = new RenderSubscriber($this->twigEnvironment); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Test we have register events subscribed |
|
61
|
|
|
*/ |
|
62
|
|
|
public function testGetSubscriberEvent() |
|
63
|
|
|
{ |
|
64
|
|
|
$eventsSubscribed = RenderSubscriber::getSubscribedEvents(); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertInternalType('array', $eventsSubscribed); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Test the lexer update to have a custom lexer for the front |
|
71
|
|
|
*/ |
|
72
|
|
|
public function testSetLexerForTheFront() |
|
73
|
|
|
{ |
|
74
|
|
|
$this->renderSubscriber->updateTagTwig($this->responseEvent); |
|
75
|
|
|
|
|
76
|
|
|
Phake::verify($this->twigEnvironment)->setLexer(Phake::anyParameters()); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Test the lexer update to have the default lexer for exception |
|
81
|
|
|
*/ |
|
82
|
|
|
public function testSetLexerForException() |
|
83
|
|
|
{ |
|
84
|
|
|
$this->renderSubscriber->updateTagTwig($this->responseEvent); |
|
85
|
|
|
$this->renderSubscriber->onKernelException($this->exceptionEvent); |
|
86
|
|
|
|
|
87
|
|
|
Phake::verify($this->twigEnvironment, Phake::times(2))->setLexer(Phake::anyParameters()); |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..