ExtractParametersUnitTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 14
c 0
b 0
f 0
dl 0
loc 41
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRouter() 0 3 1
A testValidRouteParameter() 0 25 1
1
<?php
2
declare(strict_types = 1);
3
namespace Mezon\Router\Tests\Standart;
4
5
use Mezon\Router\Router;
6
use Mezon\Router\RouterInterface;
7
use Mezon\Router\Tests\Base\ExtractParametersTestClass;
8
use Mezon\Router\Tests\Base\BaseRouterUnitTestClass;
9
10
/**
11
 *
12
 * @psalm-suppress PropertyNotSetInConstructor
13
 */
14
class ExtractParametersUnitTest extends ExtractParametersTestClass
15
{
16
17
    /**
18
     *
19
     * {@inheritdoc}
20
     * @see BaseRouterUnitTestClass::getRouter()
21
     */
22
    protected function getRouter(): RouterInterface
23
    {
24
        return new Router();
25
    }
26
27
    /**
28
     * Testing parameter extractor.
29
     */
30
    public function testValidRouteParameter(): void
31
    {
32
        $router = new Router();
33
        $router->addRoute('/catalog/all/', function (string $route): string {
34
            return $route;
35
        });
36
        $router->addRoute('/catalog/[i:cat_id]', function (string $route): string {
37
            return $route;
38
        });
39
40
        // first reading
41
        /** @var string $result */
42
        $result = $router->callRoute('/catalog/all/');
43
        $this->assertEquals($result, 'catalog/all');
44
45
        // second route
46
        /** @var string $result */
47
        $result = $router->callRoute('/catalog/1024/');
48
        $this->assertEquals($result, 'catalog/1024');
49
50
        // reading regexp from cache in the _getRouteMatcherRegExPattern method
51
        $router->warmCache();
52
        /** @var string $result */
53
        $result = $router->callRoute('/catalog/1024/');
54
        $this->assertEquals($result, 'catalog/1024');
55
    }
56
}
57