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
|
|
|
function it_converts_dashed_url_controller_param_into_controller_class_names() |
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
|
|
|
function it_converts_underscored_url_controller_param_into_controller_class_names() |
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 |
87
|
|
|
{ |
88
|
|
|
use ControllerMethods; |
89
|
|
|
|
90
|
|
|
public function index() |
91
|
|
|
{ |
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
class YellowPages extends Pages |
97
|
|
|
{ |
98
|
|
|
} |