ViewListenerSpec::let()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 6
1
<?php
2
3
namespace spec\Knp\RadBundle\EventListener;
4
5
use PhpSpec\ObjectBehavior;
6
7
class ViewListenerSpec extends ObjectBehavior
8
{
9
    /**
10
     * @param Symfony\Component\HttpFoundation\Request                               $request
11
     * @param Symfony\Component\HttpFoundation\ParameterBag                          $params
12
     * @param Symfony\Component\HttpFoundation\Response                              $response
0 ignored issues
show
Bug introduced by
There is no parameter named $response. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
13
     * @param Symfony\Bundle\FrameworkBundle\Templating\EngineInterface              $engine
14
     * @param Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
15
     * @param Knp\RadBundle\EventListener\MissingViewHandler                         $mvh
16
     * @param Knp\RadBundle\View\NameDeducer                                         $deducer
17
     */
18
    function let($request, $params, $engine, $event, $mvh, $deducer)
19
    {
20
        $event->getRequest()->willReturn($request);
21
        $request->attributes = $params;
22
        $this->beConstructedWith($engine, $deducer, $mvh);
23
    }
24
25
    function it_should_create_a_view_response_when_controller_did_not_return_any($deducer, $request, $params, $response, $engine, $event, $mvh)
0 ignored issues
show
Coding Style introduced by
Method name "ViewListenerSpec::it_should_create_a_view_response_when_controller_did_not_return_any" is not in camel caps format
Loading history...
26
    {
27
        $params->get('_controller')->willReturn('App\Controller\CheeseController::eatAction');
28
        $deducer->deduce($request)->willReturn('App:Cheese:eat.html.twig');
29
        $engine->exists('App:Cheese:eat.html.twig')->willReturn(true);
30
        $engine->renderResponse('App:Cheese:eat.html.twig', array('foo' => 'bar'))->willReturn($response);
31
32
        $event->setResponse($response)->shouldBeCalled();
33
        $event->getRequest()->willReturn($request);
34
        $event->getControllerResult()->willReturn(array('foo' => 'bar'));
35
36
        $mvh->handleMissingView(\Prophecy\Argument::cetera())->shouldNotBeCalled();
37
38
        $this->onKernelView($event);
39
    }
40
41
    function it_should_create_a_view_response_when_controller_return_null($deducer, $request, $params, $response, $engine, $event, $mvh)
0 ignored issues
show
Coding Style introduced by
Method name "ViewListenerSpec::it_should_create_a_view_response_when_controller_return_null" is not in camel caps format
Loading history...
42
    {
43
        $params->get('_controller')->willReturn('App\Controller\CheeseController::eatAction');
44
        $deducer->deduce($request)->willReturn('App:Cheese:eat.html.twig');
45
        $engine->exists('App:Cheese:eat.html.twig')->willReturn(true);
46
        $engine->renderResponse('App:Cheese:eat.html.twig', array())->willReturn($response);
47
48
        $event->setResponse($response)->shouldBeCalled();
49
        $event->getRequest()->willReturn($request);
50
        $event->getControllerResult()->willReturn(null);
51
52
        $mvh->handleMissingView(\Prophecy\Argument::cetera())->shouldNotBeCalled();
53
54
        $this->onKernelView($event);
55
    }
56
57
    function it_should_resolve_controller_when_not_yet_resolved($deducer, $request, $params, $response, $engine, $event, $mvh)
0 ignored issues
show
Coding Style introduced by
Method name "ViewListenerSpec::it_should_resolve_controller_when_not_yet_resolved" is not in camel caps format
Loading history...
58
    {
59
        $params->get('_controller')->willReturn('App\Controller\CheeseController::eatAction');
60
        $deducer->deduce($request)->willReturn('App:Cheese:eat.html.twig');
61
        $engine->exists('App:Cheese:eat.html.twig')->willReturn(true);
62
        $engine->renderResponse('App:Cheese:eat.html.twig', array('foo' => 'bar'))->willReturn($response);
63
64
        $event->setResponse($response)->shouldBeCalled();
65
        $event->getRequest()->willReturn($request);
66
        $event->getControllerResult()->willReturn(array('foo' => 'bar'));
67
68
        $mvh->handleMissingView(\Prophecy\Argument::cetera())->shouldNotBeCalled();
69
70
        $this->onKernelView($event);
71
    }
72
73
    function it_should_use_the_right_template_depending_on_request_format($deducer, $request, $params, $response, $engine, $event, $mvh)
0 ignored issues
show
Coding Style introduced by
Method name "ViewListenerSpec::it_should_use_the_right_template_depending_on_request_format" is not in camel caps format
Loading history...
74
    {
75
        $params->get('_controller')->willReturn('App\Controller\CheeseController::eatAction');
76
        $deducer->deduce($request)->willReturn('App:Cheese:eat.xml.twig');
77
        $engine->exists('App:Cheese:eat.xml.twig')->willReturn(true);
78
        $engine->renderResponse('App:Cheese:eat.xml.twig', array('foo' => 'bar'))->willReturn($response);
79
80
        $event->setResponse($response)->shouldBeCalled();
81
        $event->getRequest()->willReturn($request);
82
        $event->getControllerResult()->willReturn(array('foo' => 'bar'));
83
84
        $mvh->handleMissingView(\Prophecy\Argument::cetera())->shouldNotBeCalled();
85
86
        $this->onKernelView($event);
87
    }
88
89
    function it_should_abort_when_controller_is_not_in_request_attributes($deducer, $request, $params, $event)
0 ignored issues
show
Unused Code introduced by
The parameter $deducer is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Method name "ViewListenerSpec::it_should_abort_when_controller_is_not_in_request_attributes" is not in camel caps format
Loading history...
90
    {
91
        $event->getControllerResult()->willReturn(array('foo' => 'bar'));
92
        $event->setResponse(\Prophecy\Argument::cetera())->shouldNotBeCalled();
93
94
        $this->onKernelView($event);
95
    }
96
97
    function it_should_forward_event_to_missing_view_handler_when_view_does_not_exist($deducer, $request, $params, $response, $engine, $event, $mvh)
0 ignored issues
show
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Method name "ViewListenerSpec::it_should_forward_event_to_missing_view_handler_when_view_does_not_exist" is not in camel caps format
Loading history...
98
    {
99
        $params->get('_controller')->willReturn('App\Controller\CheeseController::eatAction');
100
        $deducer->deduce($request)->willReturn('App:Cheese:eat.html.twig');
101
        $engine->exists('App:Cheese:eat.html.twig')->willReturn(false);
102
        $event->getControllerResult()->willReturn(array('foo' => 'bar'));
103
        $mvh->handleMissingView($event, 'App:Cheese:eat.html.twig', array('foo' => 'bar'))->shouldBeCalled();
104
105
        $this->onKernelView($event);
106
    }
107
108
    function it_should_deduce_view_with_correct_bundle_name($deducer, $request, $params, $response, $engine, $event, $mvh)
0 ignored issues
show
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Method name "ViewListenerSpec::it_should_deduce_view_with_correct_bundle_name" is not in camel caps format
Loading history...
109
    {
110
        $params->get('_controller')->willReturn('TestBundle\Controller\CheeseController::eatAction');
111
        $deducer->deduce($request)->willReturn('TestBundle:Cheese:eat.html.twig');
112
        $engine->exists('TestBundle:Cheese:eat.html.twig')->willReturn(false);
113
        $event->getControllerResult()->willReturn(array('foo' => 'bar'));
114
        $mvh->handleMissingView($event, 'TestBundle:Cheese:eat.html.twig', array('foo' => 'bar'))->shouldBeCalled();
115
116
        $this->onKernelView($event);
117
    }
118
119
    function it_should_abort_when_controller_is_not_within_the_App_bundle($deducer, $request, $params, $event)
0 ignored issues
show
Unused Code introduced by
The parameter $deducer is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Method name "ViewListenerSpec::it_should_abort_when_controller_is_not_within_the_App_bundle" is not in camel caps format
Loading history...
120
    {
121
        $event->getControllerResult()->willReturn(array('foo' => 'bar'));
122
        $event->setResponse(\Prophecy\Argument::cetera())->shouldNotBeCalled();
123
124
        $this->onKernelView($event);
125
    }
126
127
    /**
128
     * @param Twig_LoaderInterface $tli
0 ignored issues
show
Bug introduced by
There is no parameter named $tli. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
129
     */
130
    function it_should_not_handle_missing_view_if_template_exists_but_fails_to_load($deducer, $request, $params, $response, $engine, $event, $mvh)
0 ignored issues
show
Unused Code introduced by
The parameter $deducer is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Method name "ViewListenerSpec::it_should_not_handle_missing_view_if_template_exists_but_fails_to_load" is not in camel caps format
Loading history...
131
    {
132
        $request->getRequestFormat()->willReturn('html');
133
        $event->getControllerResult()->willReturn(array('foo' => 'bar'));
134
        $engine->renderResponse(\Prophecy\Argument::any())->willReturn(new \Twig_Error_Loader('fail!'));
135
136
        $mvh->handleMissingView(\Prophecy\Argument::cetera())->shouldNotBeCalled();
137
138
        $this->shouldThrow()->duringOnKernelView($event);
139
    }
140
}
141