|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace spec\Venta\Routing; |
|
4
|
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
|
6
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
7
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
8
|
|
|
use Venta\Contracts\Routing\Delegate; |
|
9
|
|
|
use Venta\Contracts\Routing\MiddlewarePipeline; |
|
10
|
|
|
use Venta\Contracts\Routing\MiddlewarePipelineFactory; |
|
11
|
|
|
use Venta\Contracts\Routing\RequestRouteCollectionFactory; |
|
12
|
|
|
use Venta\Contracts\Routing\Route; |
|
13
|
|
|
use Venta\Contracts\Routing\RouteCollection; |
|
14
|
|
|
use Venta\Contracts\Routing\RouteDispatcher; |
|
15
|
|
|
use Venta\Contracts\Routing\RouteDispatcherFactory; |
|
16
|
|
|
use Venta\Contracts\Routing\RouteMatcher; |
|
17
|
|
|
|
|
18
|
|
|
class RouterSpec extends ObjectBehavior |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
function let( |
|
22
|
|
|
RouteMatcher $matcher, |
|
23
|
|
|
MiddlewarePipelineFactory $pipelineFactory, |
|
24
|
|
|
RouteCollection $routes, |
|
25
|
|
|
RouteDispatcherFactory $dispatcherFactory, |
|
26
|
|
|
RequestRouteCollectionFactory $requestRouteCollectionFactory |
|
27
|
|
|
) { |
|
28
|
|
|
$this->beConstructedWith($dispatcherFactory, $matcher, $pipelineFactory, $routes, |
|
29
|
|
|
$requestRouteCollectionFactory); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
function it_is_initializable() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->shouldImplement(Delegate::class); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
function it_matches_and_dispatches_route( |
|
38
|
|
|
RouteMatcher $matcher, |
|
39
|
|
|
MiddlewarePipelineFactory $pipelineFactory, |
|
40
|
|
|
RouteCollection $routes, |
|
41
|
|
|
RouteDispatcherFactory $dispatcherFactory, |
|
42
|
|
|
RequestRouteCollectionFactory $requestRouteCollectionFactory, |
|
43
|
|
|
Route $route, |
|
44
|
|
|
MiddlewarePipeline $pipeline, |
|
45
|
|
|
RouteDispatcher $routeDispatcher, |
|
46
|
|
|
ServerRequestInterface $request, |
|
47
|
|
|
ResponseInterface $response |
|
48
|
|
|
) { |
|
49
|
|
|
$matcher->match($request, $routes)->willReturn($route); |
|
50
|
|
|
$route->getMiddlewares()->willReturn(['middleware']); |
|
51
|
|
|
$pipelineFactory->create(['middleware'])->willReturn($pipeline->getWrappedObject()); |
|
52
|
|
|
$dispatcherFactory->create($route)->willReturn($routeDispatcher); |
|
53
|
|
|
$pipeline->process($request, $routeDispatcher)->willReturn($response); |
|
54
|
|
|
$requestRouteCollectionFactory->create($routes, $request)->willReturn($routes); |
|
55
|
|
|
$this->next($request)->shouldBe($response); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|