Passed
Push — master ( f3dde3...f14a68 )
by Alex
01:32
created

testGetCallbackWithUnexistingRoute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 13
rs 10
c 1
b 0
f 0
1
<?php
2
use PHPUnit\Framework\TestCase;
3
use Mezon\Router\Router;
4
5
class GetCallbackUnitTest extends TestCase
6
{
7
8
    /**
9
     * Data provider for the
10
     *
11
     * @return array testing dataset
12
     */
13
    public function getCallbackDataProvider(): array
14
    {
15
        return [
16
            [
17
                'some-static-route',
18
                'some-static-route'
19
            ],
20
            [
21
                'some/non-static/route/[i:id]',
22
                'some/non-static/route/1'
23
            ]
24
        ];
25
    }
26
27
    /**
28
     * Testing getting callback
29
     *
30
     * @param string $route
31
     *            route
32
     * @param string $url
33
     *            concrete URL
34
     * @dataProvider getCallbackDataProvider
35
     */
36
    public function testGetCallback(string $route, string $url): void
37
    {
38
        // setup
39
        $router = new Router();
40
        $router->addRoute($route, function () {
41
            return 'route result';
42
        });
43
44
        // test body
45
        $callback = $router->getCallback($url);
46
47
        // assertions
48
        $this->assertEquals('route result', $callback());
49
    }
50
51
    /**
52
     * Testing case with unexisting callback
53
     */
54
    public function testGetCallbackWithUnexistingRoute(): void
55
    {
56
        // setup
57
        $router = new Router();
58
        $router->addRoute('existing-route', function () {
59
            return 'existing route result';
60
        });
61
62
        // assertions
63
        $this->expectException(\Exception::class);
64
65
        // test body
66
        $router->getCallback('unexisting-route');
67
    }
68
}
69