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\Entity; |
12
|
|
|
|
13
|
|
|
use NeoBlack\FreeAtHomeApi\Entity\Route; |
14
|
|
|
use NeoBlack\FreeAtHomeApi\Exception\MethodNotAllowedException; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
|
17
|
|
|
class RouteTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
public function routeMethodDataProvider(): array |
20
|
|
|
{ |
21
|
|
|
return [ |
22
|
|
|
'method GET' => [Route::METHOD_GET], |
23
|
|
|
'method POST' => [Route::METHOD_POST], |
24
|
|
|
'method PUT' => [Route::METHOD_PUT], |
25
|
|
|
'method DELETE' => [Route::METHOD_DELETE], |
26
|
|
|
]; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @test |
31
|
|
|
* @dataProvider routeMethodDataProvider |
32
|
|
|
*/ |
33
|
|
|
public function objectCanBeCreated($method): void |
34
|
|
|
{ |
35
|
|
|
$route = new Route('/api/foo', $method); |
36
|
|
|
$this->assertSame('/api/foo', $route->getPath()); |
37
|
|
|
$this->assertSame($method, $route->getMethod()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @test |
42
|
|
|
*/ |
43
|
|
|
public function objectCanNotBeCreatedWithWrongMethod(): void |
44
|
|
|
{ |
45
|
|
|
$this->expectException(MethodNotAllowedException::class); |
46
|
|
|
$route = new Route('/api/foo', 'FOO'); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @test |
51
|
|
|
* @dataProvider routeMethodDataProvider |
52
|
|
|
*/ |
53
|
|
|
public function objectCanNotBeCreatedWithLowerCaseMethods($method): void |
54
|
|
|
{ |
55
|
|
|
$this->expectException(MethodNotAllowedException::class); |
56
|
|
|
$route = new Route('/api/foo', strtolower($method)); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.