RouterTest::getCreatesCorrectRouteObject()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 * This file is part of the package neoblack/free-at-home-api.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE file that was distributed with this source code.
9
 */
10
11
namespace NeoBlack\FreeAtHomeApi\Test\Unit\Service;
12
13
use NeoBlack\FreeAtHomeApi\Entity\Route;
14
use NeoBlack\FreeAtHomeApi\Exception\UnknownRouteException;
15
use NeoBlack\FreeAtHomeApi\Service\Router;
16
use PHPUnit\Framework\TestCase;
17
18
class RouterTest extends TestCase
19
{
20
    public function routeDataProvider(): array
21
    {
22
        return [
23
            'identifier: ' . Router::DEVICES_GET  => [Router::DEVICES_GET, '/devices', Route::METHOD_GET],
24
            'identifier: ' . Router::DEVICE_GET  => [Router::DEVICE_GET, '/device/{id}', Route::METHOD_GET],
25
            'identifier: ' . Router::DEVICE_UPDATE  => [Router::DEVICE_UPDATE, '/device/{id}', Route::METHOD_PUT],
26
            'identifier: ' . Router::DEVICE_DELETE  => [Router::DEVICE_DELETE, '/device/{id}', Route::METHOD_DELETE],
27
        ];
28
    }
29
30
    /**
31
     * @test
32
     * @dataProvider routeDataProvider
33
     * @param string $identifier
34
     * @param string $expectedPath
35
     * @param string $expectedMethod
36
     */
37
    public function getCreatesCorrectRouteObject(string $identifier, string $expectedPath, string $expectedMethod): void
38
    {
39
        $route = (new Router())->get($identifier);
40
        $this->assertSame($expectedPath, $route->getPath());
41
        $this->assertSame($expectedMethod, $route->getMethod());
42
    }
43
44
    /**
45
     * @test
46
     */
47
    public function getThrowsExceptionForInvalidIdentifier(): void
48
    {
49
        $this->expectException(UnknownRouteException::class);
50
        (new Router())->get('foo');
51
    }
52
}
53