Completed
Push — master ( bd4c23...b341c0 )
by Filipe
10:29
created

InvokedController::setContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace spec\Slick\Mvc\Http\Dispatcher;
4
5
use PhpSpec\ObjectBehavior;
6
use Slick\Mvc\Controller\ControllerContextInterface;
7
use Slick\Mvc\ControllerInterface;
8
use Slick\Mvc\Exception\UndefinedControllerMethodException;
9
use Slick\Mvc\Http\Dispatcher\ControllerDispatch;
10
use Slick\Mvc\Http\Dispatcher\ControllerInvoker;
11
use Slick\Mvc\Http\Dispatcher\ControllerInvokerInterface;
12
13
/**
14
 * ControllerInvoker Spec
15
 *
16
 * @package spec\Slick\Mvc\Http\Dispatcher
17
 * @author  Filipe Silva <[email protected]>
18
 */
19
class ControllerInvokerSpec extends ObjectBehavior
20
{
21
    function it_is_initializable()
22
    {
23
        $this->shouldHaveType(ControllerInvoker::class);
24
    }
25
26
    function its_a_controller_invoker_implementation()
27
    {
28
        $this->shouldBeAnInstanceOf(ControllerInvokerInterface::class);
29
    }
30
31
    function it_uses_the_controller_dispatch_to_invoke_the_controller_handler(
32
        InvokedController $controller
33
    )
34
    {
35
        $data = ['foo' => 'bar'];
36
        $controllerDispatch = new ControllerDispatch(
37
            InvokedController::class,
38
            'index',
39
            [123]
40
        );
41
        $controller->getViewData()
42
            ->shouldBeCalled()
43
            ->willReturn($data);
44
        $controller->index(123)->shouldBeCalled();
45
        $this->invoke($controller, $controllerDispatch)->shouldReturn($data);
46
    }
47
48
    function it_throws_undefined_controller_method_exception_if_method_is_not_defined_in_controller()
49
    {
50
        $controller = new InvokedController();
51
        $controllerDispatch = new ControllerDispatch(
52
            InvokedController::class,
53
            'unknown',
54
            [123]
55
        );
56
        $this->shouldThrow(UndefinedControllerMethodException::class)
57
            ->during('invoke', [$controller, $controllerDispatch]);
58
59
    }
60
}
61
62
class InvokedController implements ControllerInterface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
63
{
64
65
    public function setContext(ControllerContextInterface $context)
66
    {
67
        // do nothing
68
        return $this;
69
    }
70
71
    public function set($name, $value = null)
72
    {
73
        // do nothing
74
        return $this;
75
    }
76
77
    public function index($test)
0 ignored issues
show
Unused Code introduced by
The parameter $test 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...
78
    {
79
        // Do controller stuff
80
    }
81
82
    /**
83
     * A view data model used by renderer
84
     *
85
     * @return array
86
     */
87
    public function getViewData()
88
    {
89
        // do nothing
90
        return [];
91
    }
92
}
93