Completed
Push — master ( c0f250...321e24 )
by Filipe
15:10
created

ControllerInvokerSpec::let()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
/**
4
 * This file is part of slick/web_stack package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace spec\Slick\WebStack\Dispatcher;
11
12
use Slick\Di\ContainerInterface;
13
use Slick\WebStack\Controller\ControllerContextInterface;
14
use Slick\WebStack\Controller\ControllerMethods;
15
use Slick\WebStack\ControllerInterface;
16
use Slick\WebStack\Dispatcher\ControllerDispatch;
17
use Slick\WebStack\Dispatcher\ControllerInvoker;
18
use PhpSpec\ObjectBehavior;
19
use Slick\WebStack\Dispatcher\ControllerInvokerInterface;
20
21
/**
22
 * ControllerInvokerSpec specs
23
 *
24
 * @package spec\Slick\WebStack\Dispatcher
25
 */
26
class ControllerInvokerSpec extends ObjectBehavior
27
{
28
    function let(ContainerInterface $container, InvokedController $controller)
29
    {
30
        $container->make(InvokedController::class)
31
            ->willReturn($controller);
32
        $this->beConstructedWith($container);
33
    }
34
35
    function it_is_initializable_with_a_dependency_container()
36
    {
37
        $this->shouldHaveType(ControllerInvoker::class);
38
    }
39
40
    function its_a_controller_invoker_implementation()
41
    {
42
        $this->shouldBeAnInstanceOf(ControllerInvokerInterface::class);
43
    }
44
45
    function it_uses_the_controller_dispatch_to_invoke_the_controller_handler(
46
        ContainerInterface $container,
47
        ControllerContextInterface $context
48
    )
49
    {
50
        $controller = new InvokedController();
51
        $container->make(InvokedController::class)->willReturn($controller);
52
        $data = ['foo' => 'bar'];
53
        $controllerDispatch = new ControllerDispatch(
54
            InvokedController::class,
55
            'index',
56
            ['bar']
57
        );
58
59
        $this->invoke($context, $controllerDispatch)->shouldReturn($data);
60
    }
61
}
62
63
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...
64
{
65
    use ControllerMethods;
66
67
    public function index($test)
68
    {
69
        $this->set('foo', $test);
70
    }
71
}