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

it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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 Aura\Router\Route;
13
use PhpSpec\Exception\Example\FailureException;
14
use Slick\WebStack\Controller\ControllerMethods;
15
use Slick\WebStack\ControllerInterface;
16
use Slick\WebStack\Dispatcher\ControllerDispatch;
17
use Slick\WebStack\Dispatcher\ControllerDispatchInflector;
18
use PhpSpec\ObjectBehavior;
19
use Slick\WebStack\Dispatcher\ControllerDispatchInflectorInterface;
20
21
/**
22
 * ControllerDispatchInflectorSpec specs
23
 *
24
 * @package spec\Slick\WebStack\Dispatcher
25
 */
26
class ControllerDispatchInflectorSpec extends ObjectBehavior
27
{
28
29
    function its_a_controller_inflector()
30
    {
31
        $this->shouldBeAnInstanceOf(ControllerDispatchInflectorInterface::class);
32
    }
33
34
    function it_is_initializable()
35
    {
36
        $this->shouldHaveType(ControllerDispatchInflector::class);
37
    }
38
39
    function it_inflects_controller_dispatch_from_route_attributes()
40
    {
41
        $route = new Route();
42
        $route->attributes([
43
            'namespace' => 'spec\Slick\WebStack\Dispatcher',
44
            'controller' => 'pages',
45
            'action' => 'index',
46
            'args' => [123, 'test']
47
        ]);
48
        $this->inflect($route)->shouldBeAnInstanceOf(ControllerDispatch::class);
49
    }
50 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...
51
    {
52
        $route = new Route();
53
        $route->attributes([
54
            'namespace' => 'spec\Slick\WebStack\Dispatcher',
55
            'controller' => 'yellow-pages',
56
            'action' => 'index'
57
        ]);
58
        $this->inflect($route)->shouldHaveControllerNamed('spec\Slick\WebStack\Dispatcher\YellowPages');
59
    }
60 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...
61
    {
62
        $route = new Route();
63
        $route->attributes([
64
            'namespace' => 'spec\Slick\WebStack\Dispatcher',
65
            'controller' => 'yellow_pages',
66
            'action' => 'index'
67
        ]);
68
        $this->inflect($route)->shouldHaveControllerNamed('spec\Slick\WebStack\Dispatcher\YellowPages');
69
    }
70
    public function getMatchers()
71
    {
72
        return [
73
            'haveControllerNamed' => function (ControllerDispatch $subject, $name) {
74
                if ($subject->controllerClass()->getName() !== $name) {
75
                    throw new FailureException(
76
                        "Expected controller name to be '{$name}', ".
77
                        "but got {$subject->controllerClass()->getName()}"
78
                    );
79
                }
80
                return true;
81
            }
82
        ];
83
    }
84
}
85
86
class Pages 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...
87
{
88
    use ControllerMethods;
89
90
    public function index()
91
    {
92
93
    }
94
}
95
96
class YellowPages extends Pages
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...
97
{
98
}