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