DisparcherTest::testWithNamespace()   A
last analyzed

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
 * 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\Dispatcher;
11
12
use Ds\Router\Dispatcher\Dispatcher;
13
use Tests\Ds\Router\Helpers\Reflection;
14
15
/**
16
 * Class DisparcherTest
17
 * @package Tests\Ds\Router\Dispatcher
18
 */
19
class DisparcherTest extends \PHPUnit_Framework_TestCase
20
{
21
    /**
22
     * @var Dispatcher
23
     */
24
    public $dispatcher;
25
26
    public function setUp()
27
    {
28
        $options = [];
29
        $this->dispatcher = new Dispatcher($options);
30
    }
31
32
    public function testWithNamespace()
33
    {
34
        $ns = 'myNamespace';
35
        $dispatcher = $this->dispatcher->withNamespace($ns);
36
        $addedNamespaces = Reflection::getProperty(Dispatcher::class, 'namespaces', $dispatcher);
37
        $this->assertEquals([$ns => $ns], $addedNamespaces);
38
    }
39
40
    public function testWithNamespaces()
41
    {
42
        $namespaces = [
43
            '\my\namespace','another','one\more'
44
        ];
45
46
        $expected = [
47
            $namespaces[0] => $namespaces[0],
48
            $namespaces[1] => $namespaces[1],
49
            $namespaces[2] => $namespaces[2]
50
        ];
51
52
        $dispatcher = $this->dispatcher->withNamespaces($namespaces);
53
        $addedNamespaces = Reflection::getProperty(Dispatcher::class, 'namespaces', $dispatcher);
54
        $this->assertEquals($expected, $addedNamespaces);
55
    }
56
}
57