Passed
Push — master ( 99f62c...22c5d8 )
by Alex
07:13
created

BoolResultTestClass::testBoolResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 12
rs 10
cc 1
nc 1
nop 2
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 BoolResultTestClass 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
     * Data provider for the test testBoolResult
27
     *
28
     * @return array testing data
29
     */
30
    public function boolResultDataProvider(): array
31
    {
32
        return [
33
            [
34
                function (): bool {
35
                    return true;
36
                },
37
                true
38
            ],
39
            [
40
                function (): bool {
41
                    return false;
42
                },
43
                false
44
            ]
45
        ];
46
    }
47
48
    /**
49
     * Testing bool return values for route handlers, checking that false return value works correctly
50
     *
51
     * @param callable $handler
52
     *            route handler
53
     * @param bool $expected
54
     *            expected result
55
     * @dataProvider boolResultDataProvider
56
     */
57
    public function testBoolResult(callable $handler, bool $expected): void
58
    {
59
        // setup
60
        $router = $this->getRouter();
61
        $router->addRoute('/catalog/[a:cat_id]/', $handler);
62
63
        // test body
64
        /** @var bool $result */
65
        $result = $router->callRoute('/catalog/foo/');
66
67
        // assertions
68
        $this->assertEquals($expected, $result);
69
    }
70
}
71