Completed
Push — master ( 0daa93...76ae44 )
by Raffael
01:40
created

RouterTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 5
c 2
b 1
f 0
lcom 1
cbo 4
dl 0
loc 55
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testInit() 0 12 1
A testVerb() 0 5 1
A testPath() 0 5 1
A testClearRoutes() 0 5 1
A testAppendRoute() 0 6 1
1
<?php
2
namespace Micro\Testsuite\Http;
3
4
use \PHPUnit\Framework\TestCase;
5
use \Micro\Http\Router;
6
use \Micro\Http\Router\Route;
7
use \Micro\Testsuite\MockLogger;
8
9
class RouterTest extends TestCase
10
{
11
    public function testInit()
12
    {
13
        $server = [
14
            'PATH_INFO' => 'index.php/api/my/path',
15
            'REQUEST_METHOD' => 'PUT',
16
        ];
17
18
        $router = new Router($server, new MockLogger());
19
        $this->assertEquals($router->getPath(), 'index.php/api/my/path');
20
        $this->assertEquals($router->getVerb(), 'put');
21
        return $router;
22
    }
23
24
    /**
25
     * @depends testInit
26
     */
27
    public function testVerb($router)
28
    {
29
        $router->setVerb('GET');
30
        $this->assertEquals($router->getVerb(), 'get');
31
    }
32
    
33
34
    /**
35
     * @depends testInit
36
     */
37
    public function testPath($router)
38
    {
39
        $router->setPath('index.php/api');
40
        $this->assertEquals($router->getPath(), 'index.php/api');
41
    }
42
    
43
44
    /**
45
     * @depends testInit
46
     */
47
    public function testAppendRoute($router)
48
    {
49
        $this->assertCount(0, $router->getRoutes());
50
        $router->appendRoute(new Route('/', 'Controller'));
51
        $this->assertCount(1, $router->getRoutes());
52
    }
53
    
54
55
    /**
56
     * @depends testInit
57
     */
58
    public function testClearRoutes($router)
59
    {
60
        $router->clearRoutingTable();
61
        $this->assertCount(0, $router->getRoutes());
62
    }
63
}
64