Completed
Push — master ( 49f631...00219d )
by Frank
03:48
created

RouteTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 42
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A routeMethodDataProvider() 0 9 1
A objectCanBeCreated() 0 6 1
A objectCanNotBeCreatedWithWrongMethod() 0 5 1
A objectCanNotBeCreatedWithLowerCaseMethods() 0 5 1
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');
0 ignored issues
show
Unused Code introduced by
$route is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
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));
0 ignored issues
show
Unused Code introduced by
$route is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
57
    }
58
}
59