|
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 |
|
64
|
|
|
{ |
|
65
|
|
|
use ControllerMethods; |
|
66
|
|
|
|
|
67
|
|
|
public function index($test) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->set('foo', $test); |
|
70
|
|
|
} |
|
71
|
|
|
} |