UriMatcherTest::provideCases()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
nc 1
nop 0
dl 0
loc 24
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gorynych\Tests\Http\Routing;
6
7
use Gorynych\Http\Routing\UriMatcher;
8
use Gorynych\Resource\AbstractResource;
9
use PHPUnit\Framework\TestCase;
10
11
class UriMatcherTest extends TestCase
12
{
13
    /**
14
     * @dataProvider provideCases
15
     */
16
    public function testMatchesUri(
17
        string $uri,
18
        string $resourcePath,
19
        string $operationPath,
20
        bool $isMatch,
21
        ?string $id
22
    ): void {
23
        $result = UriMatcher::matchUri($uri, $resourcePath, $operationPath, $matches);
24
25
        $this->assertSame($isMatch, $result);
26
        $this->assertSame($id, $matches['id'] ?? null);
27
    }
28
29
    /**
30
     * @return \Generator<array>
31
     */
32
    public function provideCases(): \Generator
33
    {
34
        yield 'uri with id' => [
35
            '/resources/1/foo',
36
            '/resources/' . AbstractResource::NUMERIC_ID,
37
            '/foo',
38
            true,
39
            '1',
40
        ];
41
42
        yield 'uri without id' => [
43
            '/resources/foo',
44
            '/resources',
45
            '/foo',
46
            true,
47
            null,
48
        ];
49
50
        yield 'different uri' => [
51
            '/resources/foo',
52
            '/resources',
53
            '/bar',
54
            false,
55
            null,
56
        ];
57
    }
58
}
59