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

ControllerDispatchInflectorSpec::getMatchers()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace spec\Slick\Mvc\Http\Dispatcher;
4
5
use Aura\Router\Route;
6
use PhpSpec\Exception\Example\FailureException;
7
use PhpSpec\Wrapper\Subject;
8
use Slick\Mvc\Http\Dispatcher\ControllerDispatch;
9
use Slick\Mvc\Http\Dispatcher\ControllerDispatchInflector;
10
use PhpSpec\ObjectBehavior;
11
use Prophecy\Argument;
12
use Slick\Mvc\Http\Dispatcher\ControllerDispatchInflectorInterface;
13
14
class ControllerDispatchInflectorSpec extends ObjectBehavior
15
{
16
    function it_is_initializable()
17
    {
18
        $this->shouldHaveType(ControllerDispatchInflector::class);
19
    }
20
21
    function its_a_controller_class_inflector()
22
    {
23
        $this->shouldBeAnInstanceOf(ControllerDispatchInflectorInterface::class);
24
    }
25
26
    function it_inflects_controller_dispatch_form_route_attributes()
27
    {
28
        $route = new Route();
29
        $route->attributes([
30
            'namespace' => 'Controller',
31
            'controller' => 'pages',
32
            'action' => 'index',
33
            'args' => [123, 'test']
34
        ]);
35
        $this->inflect($route)->shouldBeAnInstanceOf(ControllerDispatch::class);
36
    }
37
38 View Code Duplication
    function it_converts_dashed_url_controller_param_into_controller_class_names()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        $route = new Route();
41
        $route->attributes([
42
            'namespace' => 'Controller',
43
            'controller' => 'yellow-pages',
44
            'action' => 'index'
45
        ]);
46
        $this->inflect($route)->shouldHaveControllerNamed('Controller\YellowPages');
47
    }
48
49 View Code Duplication
    function it_converts_underscored_url_controller_param_into_controller_class_names()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
    {
51
        $route = new Route();
52
        $route->attributes([
53
            'namespace' => 'Controller',
54
            'controller' => 'yellow_pages',
55
            'action' => 'index'
56
        ]);
57
        $this->inflect($route)->shouldHaveControllerNamed('Controller\YellowPages');
58
    }
59
60
61
    public function getMatchers()
62
    {
63
        return [
64
            'haveControllerNamed' => function (ControllerDispatch $subject, $name) {
65
66
                if ($subject->getControllerClassName() !== $name) {
67
                    throw new FailureException(
68
                        "Expected controller name to be '{$name}', ".
69
                        "but got {$subject->getControllerClassName()}"
70
                    );
71
                }
72
                return true;
73
            }
74
        ];
75
    }
76
}
77