Passed
Push — master ( 0ee5ba...9ecbd5 )
by Alex
06:47
created

testGetCallbackWithUnexistingRoute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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