Passed
Push — master ( 61847e...dd6f34 )
by Alex
07:15
created

AmbigousRoutesTestClass   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
eloc 14
c 1
b 1
f 0
dl 0
loc 53
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testDateRoute() 0 14 1
A testAmbigousRoutes() 0 17 1
A setUp() 0 3 1
1
<?php
2
declare(strict_types = 1);
3
namespace Mezon\Router\Tests\Base;
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 *
9
 * @psalm-suppress PropertyNotSetInConstructor
10
 */
11
abstract class AmbigousRoutesTestClass extends BaseRouterUnitTestClass
12
{
13
14
    /**
15
     * Default setup
16
     *
17
     * {@inheritdoc}
18
     * @see TestCase::setUp()
19
     */
20
    public function setUp(): void
21
    {
22
        $_SERVER['REQUEST_METHOD'] = 'GET';
23
    }
24
25
    /**
26
     * Testing ambigous routes
27
     */
28
    public function testAmbigousRoutes(): void
29
    {
30
        // setup
31
        $router = $this->getRouter();
32
        $router->addRoute('/user/[s:login]', function () {
33
            return '1';
34
        });
35
        $router->addRoute('/user/[s:login]/[s:regdate]', function () {
36
            return '2';
37
        });
38
39
        // test body
40
        /** @var string $result */
41
        $result = $router->callRoute('/user/index@localhost');
42
43
        // assertions
44
        $this->assertEquals('1', $result);
45
    }
46
47
    /**
48
     * Testing route with date
49
     */
50
    public function testDateRoute(): void
51
    {
52
        // setup
53
        $router = $this->getRouter();
54
        $router->addRoute('/forum-[i:year]-[i:month]-[i:day]', function () {
55
            return '1';
56
        });
57
58
        // test body
59
        /** @var string $result */
60
        $result = $router->callRoute('/forum-2022-09-13');
61
62
        // assertions
63
        $this->assertEquals('1', $result);
64
    }
65
}
66