forked from beberlei/bankaccount
/
RouterTest.php
64 lines (55 loc) · 1.76 KB
/
RouterTest.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
<?php
/**
* @medium
*/
class RouterTest extends PHPUnit_Framework_TestCase
{
protected $router;
protected function setUp()
{
$mapper = $this->getMockBuilder('BankAccountMapper')
->disableOriginalConstructor()
->getMock();
$mapperFactory = $this->getMockBuilder('MapperFactory')
->disableOriginalConstructor()
->getMock();
$mapperFactory->expects($this->any())
->method('getMapper')
->will($this->returnValue($mapper));
$this->router = new Router(new ControllerFactory($mapperFactory));
$this->router->set('bankaccount', 'BankAccountController');
}
/**
* @covers Router::route
*/
public function testCorrectControllerIsSelected()
{
$request = new Request(
array('REQUEST_URI' => '/bankaccount/id/1')
);
$this->assertEquals(
'BankAccountController', $this->router->route($request)
);
$this->assertEquals(1, $request->get('id'));
}
/**
* @covers Router::route
* @covers RouterException
* @expectedException RouterException
*/
public function testExceptionWhenNoControllerCanBeSelected()
{
$request = new Request(array('REQUEST_URI' => '/is/not/configured'));
$this->router->route($request);
}
/**
* @covers Router::route
* @covers RouterException
* @expectedException RouterException
*/
public function testExceptionWhenSomethingIsWrongWithTheValues()
{
$request = new Request(array('REQUEST_URI' => '/bankaccount/id'));
$this->router->route($request);
}
}