Test Failed
Push — master ( 3e96d2...d4b731 )
by Dan
06:30
created

RouterFactoryTest::testCreateRouter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
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