|
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\WebStack\Controller\ControllerMethods; |
|
13
|
|
|
use Slick\WebStack\ControllerInterface; |
|
14
|
|
|
use Slick\WebStack\Dispatcher\ControllerDispatch; |
|
15
|
|
|
use PhpSpec\ObjectBehavior; |
|
16
|
|
|
use Slick\WebStack\Exception\BadControllerClassException; |
|
17
|
|
|
use Slick\WebStack\Exception\ControllerNotFoundException; |
|
18
|
|
|
use Slick\WebStack\Exception\MissingControllerMethodException; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* ControllerDispatchSpec specs |
|
22
|
|
|
* |
|
23
|
|
|
* @package spec\Slick\WebStack\Dispatcher |
|
24
|
|
|
*/ |
|
25
|
|
|
class ControllerDispatchSpec extends ObjectBehavior |
|
26
|
|
|
{ |
|
27
|
|
|
function let() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->beConstructedWith(DummyController::class, 'handle', ['1', '2']); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
function it_is_initializable_with_a_controller_class_name_method_and_optional_arguments() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->shouldHaveType(ControllerDispatch::class); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
function it_has_a_controller_class_reflection() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->controllerClass()->shouldBeAnInstanceOf(\ReflectionClass::class); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
function it_throws_an_exception_when_provided_controller_class_does_not_exists() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->beConstructedWith('testClass', 'someMethod'); |
|
45
|
|
|
$this->shouldThrow(ControllerNotFoundException::class)->duringInstantiation(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
function it_throws_an_exception_when_controller_class_is_not_a_controller() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->beConstructedWith(\stdClass::class, 'someMethod'); |
|
51
|
|
|
$this->shouldThrow(BadControllerClassException::class)->duringInstantiation(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
function it_has_a_request_handler_method_reflection_() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->handlerMethod()->shouldBeAnInstanceOf(\ReflectionMethod::class); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
function it_throws_an_exception_for_missing_methods() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->beConstructedWith(DummyController::class, 'someMethod'); |
|
62
|
|
|
$this->shouldThrow(MissingControllerMethodException::class)->duringInstantiation(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
function it_has_a_list_of_optional_arguments() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->arguments()->shouldBe(['1', '2']); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
class DummyController implements ControllerInterface |
|
72
|
|
|
{ |
|
73
|
|
|
use ControllerMethods; |
|
74
|
|
|
|
|
75
|
|
|
public function handle() |
|
76
|
|
|
{ |
|
77
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
} |