|
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
|
|
|
]; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @test |
|
29
|
|
|
* @dataProvider routeDataProvider |
|
30
|
|
|
* @param string $identifier |
|
31
|
|
|
* @param string $expectedPath |
|
32
|
|
|
* @param string $expectedMethod |
|
33
|
|
|
*/ |
|
34
|
|
|
public function getCreatesCorrectRouteObject(string $identifier, string $expectedPath, string $expectedMethod): void |
|
35
|
|
|
{ |
|
36
|
|
|
$route = (new Router())->get($identifier); |
|
37
|
|
|
$this->assertSame($expectedPath, $route->getPath()); |
|
38
|
|
|
$this->assertSame($expectedMethod, $route->getMethod()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @test |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getThrowsExceptionForInvalidIdentifier(): void |
|
45
|
|
|
{ |
|
46
|
|
|
$this->expectException(UnknownRouteException::class); |
|
47
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */ |
|
48
|
|
|
$route = (new Router())->get('foo'); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.