1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Ds\Router; |
4
|
|
|
|
5
|
|
|
use Ds\Router\Adaptor\FastRouteAdaptor; |
6
|
|
|
use Ds\Router\Interfaces\AdaptorInterface; |
7
|
|
|
use Ds\Router\Interfaces\RouteCollectionInterface; |
8
|
|
|
use Ds\Router\Interfaces\RouterInterface; |
9
|
|
|
use Ds\Router\RouterFactory; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class RouterFactoryTest |
13
|
|
|
* @package Tests\Rs\Router |
14
|
|
|
*/ |
15
|
|
|
class RouterFactoryTest extends \PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var AdaptorInterface |
19
|
|
|
*/ |
20
|
|
|
public $adaptor; |
21
|
|
|
/** |
22
|
|
|
* @var RouteCollectionInterface |
23
|
|
|
*/ |
24
|
|
|
public $collection; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* |
28
|
|
|
*/ |
29
|
|
|
public function setUp() |
30
|
|
|
{ |
31
|
|
|
$this->adaptor = $this->getMockBuilder(AdaptorInterface::class)->getMock(); |
32
|
|
|
$this->collection = $this->getMockBuilder(RouteCollectionInterface::class)->getMock(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Test that create factory method is returning correct Router. |
37
|
|
|
*/ |
38
|
|
|
public function testCreateRouter() |
39
|
|
|
{ |
40
|
|
|
$router = RouterFactory::createRouter($this->adaptor, $this->collection); |
41
|
|
|
$this->assertSame($this->adaptor, $router->getAdaptor()); |
42
|
|
|
$this->assertSame($this->collection, $router->getCollection()); |
43
|
|
|
$this->assertInstanceOf(RouterInterface::class, $router); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Test that createFastRouter factory returns a correct instance of Router. |
48
|
|
|
*/ |
49
|
|
|
public function testCreateFastRouter() |
50
|
|
|
{ |
51
|
|
|
$options = ['errorHandlers' => [ |
52
|
|
|
'default' => [ |
53
|
|
|
'handler' => '\Site\Controllers\Error\ErrorController::error404', |
54
|
|
|
'name' => ['error'] |
55
|
|
|
] |
56
|
|
|
]]; |
57
|
|
|
|
58
|
|
|
$router = RouterFactory::createFastRouter($options); |
59
|
|
|
$adaptor = $router->getAdaptor(); |
60
|
|
|
$expectedOptions = $adaptor->getOptions(); |
61
|
|
|
|
62
|
|
|
$this->assertInstanceOf(FastRouteAdaptor::class, $router->getAdaptor()); |
63
|
|
|
$this->assertInstanceOf(RouteCollectionInterface::class, $router->getCollection()); |
64
|
|
|
$this->assertEquals($expectedOptions, $options); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|