RouteCollectionTest::testCanBeCounted()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Northwoods\Router;
5
6
use PHPUnit\Framework\TestCase;
7
8
class RouteCollectionTest extends TestCase
9
{
10
    use CanMockHandler;
11
12
    /** @var RouteCollection */
13
    private $collection;
14
15
    public function setUp()
16
    {
17
        $this->collection = new RouteCollection();
18
    }
19
20
    public function testCanSetAndGetRoutes(): void
21
    {
22
        $route = new Route('GET', '/test', $this->mockHandler());
23
24
        $this->collection->set('test', $route);
25
26
        $this->assertEquals($route, $this->collection->get('test'));
27
    }
28
29
    public function testCanBeCounted(): void
30
    {
31
        $route = new Route('GET', '/test', $this->mockHandler());
32
33
        $this->collection->set('test', $route);
34
35
        $this->assertCount(1, $this->collection);
36
    }
37
38
    public function testCanBeIterated(): void
39
    {
40
        $route = new Route('GET', '/test', $this->mockHandler());
41
42
        $this->collection->set('test', $route);
43
44
        foreach ($this->collection as $r) {
45
            $this->assertEquals($route, $r);
46
        }
47
    }
48
49
    public function testCanDetectNotSetRoute(): void
50
    {
51
        $this->expectException(Error\RouteNotSetException::class);
52
53
        $this->collection->get('test');
54
    }
55
}
56