1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Sunrise\Http\Router\Tests; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Import classes |
7
|
|
|
*/ |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Sunrise\Http\Router\RouteCollection; |
10
|
|
|
use Sunrise\Http\Router\RouteCollectionInterface; |
11
|
|
|
use ArrayIterator; |
12
|
|
|
use IteratorAggregate; |
13
|
|
|
use Countable; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* RouteCollectionTest |
17
|
|
|
*/ |
18
|
|
|
class RouteCollectionTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @return void |
23
|
|
|
*/ |
24
|
|
|
public function testConstructor() : void |
25
|
|
|
{ |
26
|
|
|
$collection = new RouteCollection(); |
27
|
|
|
|
28
|
|
|
$this->assertInstanceOf(RouteCollectionInterface::class, $collection); |
29
|
|
|
$this->assertInstanceOf(IteratorAggregate::class, $collection); |
30
|
|
|
$this->assertInstanceOf(Countable::class, $collection); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
|
|
public function testConstructorWithRoutes() : void |
37
|
|
|
{ |
38
|
|
|
$routes = [ |
39
|
|
|
new Fixture\TestRoute(), |
40
|
|
|
new Fixture\TestRoute(), |
41
|
|
|
new Fixture\TestRoute(), |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
$collection = new RouteCollection(...$routes); |
45
|
|
|
|
46
|
|
|
$this->assertSame($routes, $collection->all()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
public function testAdd() : void |
53
|
|
|
{ |
54
|
|
|
$routes = [ |
55
|
|
|
new Fixture\TestRoute(), |
56
|
|
|
new Fixture\TestRoute(), |
57
|
|
|
new Fixture\TestRoute(), |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
$collection = new RouteCollection(); |
61
|
|
|
|
62
|
|
|
$collection->add(...$routes); |
63
|
|
|
|
64
|
|
|
$this->assertSame($routes, $collection->all()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return void |
69
|
|
|
*/ |
70
|
|
|
public function testCount() : void |
71
|
|
|
{ |
72
|
|
|
$routes = [ |
73
|
|
|
new Fixture\TestRoute(), |
74
|
|
|
new Fixture\TestRoute(), |
75
|
|
|
new Fixture\TestRoute(), |
76
|
|
|
]; |
77
|
|
|
|
78
|
|
|
$collection = new RouteCollection(); |
79
|
|
|
|
80
|
|
|
$this->assertCount(0, $collection); |
81
|
|
|
|
82
|
|
|
$collection->add(...$routes); |
83
|
|
|
|
84
|
|
|
$this->assertCount(3, $collection); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return void |
89
|
|
|
*/ |
90
|
|
|
public function testIterator() : void |
91
|
|
|
{ |
92
|
|
|
$collection = new RouteCollection(); |
93
|
|
|
|
94
|
|
|
$this->assertInstanceOf(ArrayIterator::class, $collection->getIterator()); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|