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

RealLifeExampleTestClass::testRealLifeExample()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 15
c 1
b 1
f 0
dl 0
loc 29
rs 9.7666
cc 1
nc 1
nop 0
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 RealLifeExampleTestClass 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 real life example
27
     */
28
    public function testRealLifeExample(): void
29
    {
30
        // setup
31
        $router = $this->getRouter();
32
        $router->addRoute('/user/[s:login]/custom-field/[s:name]', function () {
33
            return 'get-custom-field';
34
        });
35
        $router->addRoute('/user/[s:login]/custom-field/[s:name]/add', function () {
36
            return 'add-custom-field';
37
        });
38
        $router->addRoute('/user/[s:login]/custom-field/[s:name]/delete', function () {
39
            return 'delete-custom-field';
40
        });
41
        $router->addRoute('/restore-password/[s:token]', function () {
42
            return 'restore-password';
43
        });
44
        $router->addRoute('/reset-password/[s:token]', function () {
45
            return 'reset-password';
46
        });
47
        $router->addRoute('/user/[s:login]/delete', function () {
48
            return 'user-delete';
49
        });
50
51
        // test body
52
        /** @var string $result */
53
        $result = $router->callRoute('/user/index@localhost/custom-field/name/add');
54
55
        // assertions
56
        $this->assertEquals('add-custom-field', $result);
57
    }
58
}
59