RouteTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A objectCanNotBeCreatedWithWrongMethod() 0 4 1
A objectCanNotBeCreatedWithLowerCaseMethods() 0 4 1
A routeMethodDataProvider() 0 7 1
A objectCanBeCreated() 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
        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
        new Route('/api/foo', strtolower($method));
57
    }
58
}
59