-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiRouterTest.php
78 lines (58 loc) · 2.33 KB
/
MultiRouterTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace Corpus\Test\Router;
use Corpus\Router\Interfaces\RouterInterface;
use Corpus\Router\MultiRouter;
class MultiRouterTest extends \PHPUnit\Framework\TestCase {
public function testEmpty() : void {
$router = new MultiRouter;
$this->assertNull($router->match('index.html'));
}
public function testMatch_None() : void {
$router = new MultiRouter;
/**
* @var \Corpus\Router\Interfaces\RouterInterface|\PHPUnit\Framework\MockObject\MockObject $ri1
*/
$ri1 = $this->createMock(RouterInterface::class);
$ri1->expects($this->exactly(3))->method('match')->with(
$this->equalTo('index.html')
)->willReturn(null);
$router->addRouter($ri1);
$router->addRouter($ri1);
$router->addRouter($ri1);
$this->assertNull($router->match('index.html'));
}
public function testMatch_MidStream() : void {
$router = new MultiRouter;
/**
* @var \Corpus\Router\Interfaces\RouterInterface|\PHPUnit\Framework\MockObject\MockObject $ri1
* @var \Corpus\Router\Interfaces\RouterInterface|\PHPUnit\Framework\MockObject\MockObject $ri2
* @var \Corpus\Router\Interfaces\RouterInterface|\PHPUnit\Framework\MockObject\MockObject $ri3
*/
$ri1 = $this->createMock(RouterInterface::class);
$ri2 = $this->createMock(RouterInterface::class);
$ri3 = $this->createMock(RouterInterface::class);
$ri1->expects($this->once())->method('match')->with(
$this->equalTo('index.html')
)->willReturn(null);
$ri2->expects($this->once())->method('match')->with(
$this->equalTo('index.html')
)->willReturn([ true ]);
$ri3->expects($this->never())->method('match');
$router->addRouter($ri1);
$router->addRouter($ri2);
$router->addRouter($ri3);
$this->assertSame([ true ], $router->match('index.html'));
}
public function testConstruct() : void {
/**
* @var \Corpus\Router\Interfaces\RouterInterface|\PHPUnit\Framework\MockObject\MockObject $ri1
* @var \Corpus\Router\Interfaces\RouterInterface|\PHPUnit\Framework\MockObject\MockObject $ri2
* @var \Corpus\Router\Interfaces\RouterInterface|\PHPUnit\Framework\MockObject\MockObject $ri3
*/
$ri1 = $this->createMock(RouterInterface::class);
$ri2 = $this->createMock(RouterInterface::class);
$ri3 = $this->createMock(RouterInterface::class);
$router = new MultiRouter($ri1, $ri2, $ri3);
$this->assertSame([ $ri1, $ri2, $ri3 ], $router->getRouters());
}
}