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

RouterTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 33
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A routeDataProvider() 0 6 1
A getCreatesCorrectRouteObject() 0 6 1
A getThrowsExceptionForInvalidIdentifier() 0 6 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\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');
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...
49
    }
50
}
51