Completed
Push — master ( e74872...1684aa )
by Maurício
01:57 queued 25s
created

ServerRequestTest::testGetRoute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 3
dl 0
loc 7
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\Tests\Http;
6
7
use PhpMyAdmin\Http\ServerRequest;
8
use PHPUnit\Framework\TestCase;
9
use Psr\Http\Message\ServerRequestInterface;
10
11
/**
12
 * @covers \PhpMyAdmin\Http\ServerRequest
13
 */
14
class ServerRequestTest extends TestCase
15
{
16
    /**
17
     * @param array<string, string> $get
18
     * @param array<string, string> $post
19
     *
20
     * @dataProvider providerForTestGetRoute
21
     */
22
    public function testGetRoute(string $expected, array $get, array $post): void
23
    {
24
        $requestStub = $this->createStub(ServerRequestInterface::class);
25
        $requestStub->method('getQueryParams')->willReturn($get);
26
        $requestStub->method('getParsedBody')->willReturn($post);
27
        $request = new ServerRequest($requestStub);
28
        $this->assertSame($expected, $request->getRoute());
29
    }
30
31
    /**
32
     * @return array<int, array<int, array<string, string>|string>>
33
     * @psalm-return array<int, array{string, array<string, string>, array<string, string>}>
34
     */
35
    public function providerForTestGetRoute(): iterable
36
    {
37
        return [
38
            ['/', [], []],
39
            ['/test', ['route' => '/test'], []],
40
            ['/test', [], ['route' => '/test']],
41
            ['/test-get', ['route' => '/test-get'], ['route' => '/test-post']],
42
            ['/database/structure', ['db' => 'db'], []],
43
            ['/sql', ['db' => 'db', 'table' => 'table'], []],
44
            ['/test', ['route' => '/test', 'db' => 'db'], []],
45
            ['/test', ['route' => '/test', 'db' => 'db', 'table' => 'table'], []],
46
            ['/', [], ['db' => 'db']],
47
            ['/', [], ['db' => 'db', 'table' => 'table']],
48
        ];
49
    }
50
}
51