1
|
|
|
<?php |
2
|
|
|
namespace SandboxBundle\Tests\EventListener; |
3
|
|
|
|
4
|
|
|
use danrevah\SandboxBundle\EventListener\SandboxListener; |
5
|
|
|
use ShortifyPunit\ShortifyPunit; |
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
7
|
|
|
|
8
|
|
|
class SandboxListenerTest extends WebTestCase |
9
|
|
|
{ |
10
|
|
|
public function testOnKernelController() |
11
|
|
|
{ |
12
|
|
|
$request = ShortifyPunit::mock('Symfony\Component\HttpFoundation\Request'); |
13
|
|
|
$requestStack = ShortifyPunit::mock('Symfony\Component\HttpFoundation\RequestStack'); |
14
|
|
|
$sandboxResponseManager = ShortifyPunit::mock('danrevah\SandboxBundle\Managers\SandboxResponseManager'); |
15
|
|
|
$event = ShortifyPunit::mock('Symfony\Component\HttpKernel\Event\FilterControllerEvent'); |
16
|
|
|
$parameterBag = ShortifyPunit::mock('Symfony\Component\HttpFoundation\ParameterBag'); |
17
|
|
|
|
18
|
|
|
ShortifyPunit::when($request)->getContent()->returns(''); |
19
|
|
|
$request->query = $parameterBag; |
20
|
|
|
$request->request = $parameterBag; |
21
|
|
|
ShortifyPunit::when($requestStack)->getCurrentRequest()->returns($request); |
22
|
|
|
ShortifyPunit::when($event)->getController()->returns([0, 1]); |
23
|
|
|
ShortifyPunit::when($event)->setController(anything())->returns(1); |
24
|
|
|
|
25
|
|
|
$sandboxListener = new SandboxListener($requestStack, $sandboxResponseManager); |
26
|
|
|
$sandboxListener->onKernelController($event); |
27
|
|
|
|
28
|
|
|
$this->assertTrue(ShortifyPunit::verify($event)->setController(anything())->atLeastOnce()); |
29
|
|
|
|
30
|
|
|
$response = [false, 0, 0, 0]; |
31
|
|
|
ShortifyPunit::when($sandboxResponseManager)->getResponseController(anything(), anything(), anything(), anything(), anything())->returns($response); |
32
|
|
|
|
33
|
|
|
$event2 = ShortifyPunit::mock('Symfony\Component\HttpKernel\Event\FilterControllerEvent'); |
34
|
|
|
ShortifyPunit::when($event2)->setController(anything())->returns(''); |
35
|
|
|
ShortifyPunit::when($event2)->getController(anything())->returns([0, 1]); |
36
|
|
|
$sandboxListener = new SandboxListener($requestStack, $sandboxResponseManager); |
37
|
|
|
$sandboxListener->onKernelController($event2); |
38
|
|
|
|
39
|
|
|
$this->assertTrue(ShortifyPunit::verify($event2)->setController(anything())->neverCalled()); |
40
|
|
|
} |
41
|
|
|
} |