Completed
Push — master ( 386146...a2d301 )
by John
07:40
created

ViewListenerTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 0
cbo 5
dl 0
loc 42
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B willSetResponseFromFactoryOnEvent() 0 36 1
1
<?php
2
/*
3
 * This file is part of the KleijnWeb\SwaggerBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\SwaggerBundle\Tests\EventListener;
10
11
use KleijnWeb\SwaggerBundle\EventListener\ViewListener;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Response;
14
15
/**
16
 * @author John Kleijn <[email protected]>
17
 */
18
class ViewListenerTest extends \PHPUnit_Framework_TestCase
19
{
20
    /**
21
     * @test
22
     */
23
    public function willSetResponseFromFactoryOnEvent()
24
    {
25
        $request = new Request();
26
        $response = new Response();
27
        $result = [uniqid()];
28
29
        $eventMock = $this
30
            ->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent')
31
            ->disableOriginalConstructor()
32
            ->getMock();
33
        $eventMock
34
            ->expects($this->once())
35
            ->method('getRequest')
36
            ->willReturn($request);
37
        $eventMock
38
            ->expects($this->once())
39
            ->method('getControllerResult')
40
            ->willReturn($result);
41
        $eventMock
42
            ->expects($this->once())
43
            ->method('setResponse')
44
            ->willReturn($response);
45
46
        $factoryMock = $this
47
            ->getMockBuilder('KleijnWeb\SwaggerBundle\Response\ResponseFactory')
48
            ->disableOriginalConstructor()
49
            ->getMock();
50
        $factoryMock
51
            ->expects($this->once())
52
            ->method('createResponse')
53
            ->with($request, $result)
54
            ->willReturn($response);
55
56
        $listener = new ViewListener($factoryMock);
57
        $listener->onKernelView($eventMock);
58
    }
59
}
60