Add tests app/router for new methods.
This commit is contained in:
@ -77,4 +77,17 @@ class RouteTest extends PHPUnit_Framework_TestCase
|
||||
$this->setExpectedException('PHPUnit_Framework_Error');
|
||||
$route->match('');
|
||||
}
|
||||
|
||||
public function testGetUri()
|
||||
{
|
||||
$route = 'myroute';
|
||||
$route_mock = $this->getMockBuilder('Route')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('__construct'))
|
||||
->getMock();
|
||||
$reflection = new ReflectionProperty('Route', 'route');
|
||||
$reflection->setAccessible(true);
|
||||
$reflection->setValue($route_mock, $route);
|
||||
$this->assertEquals('/' . $route, $route_mock->getUri());
|
||||
}
|
||||
}
|
@ -61,4 +61,85 @@ class RouterTest extends PHPUnit_Framework_TestCase
|
||||
$router->setDefaultLayout('userLayout');
|
||||
$this->assertAttributeEquals('userLayout', 'default_layout', $router);
|
||||
}
|
||||
|
||||
public function testGetRoute()
|
||||
{
|
||||
$route = 'route object.';
|
||||
$router = new Router();
|
||||
$reflection = new ReflectionProperty('Router', 'route');
|
||||
$reflection->setAccessible(true);
|
||||
$reflection->setValue($router, $route);
|
||||
$this->assertEquals($route, $router->getRoute());
|
||||
}
|
||||
|
||||
public function testGetUriWithNameIsNull()
|
||||
{
|
||||
$name = null;
|
||||
$uri = 'uri from route.';
|
||||
$route_mock = $this->getMockBuilder('Route')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('getUri'))
|
||||
->getMock();
|
||||
$route_mock->expects($this->once())
|
||||
->method('getUri')
|
||||
->with()
|
||||
->will($this->returnValue($uri));
|
||||
$router_mock = $this->getMockBuilder('Router')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('getRoute'))
|
||||
->getMock();
|
||||
$router_mock->expects($this->once())
|
||||
->method('getRoute')
|
||||
->with()
|
||||
->will($this->returnValue($route_mock));
|
||||
$this->assertEquals($uri, $router_mock->getUri($name));
|
||||
}
|
||||
|
||||
public function testGetUriWithNamed()
|
||||
{
|
||||
$name = 'name of route';
|
||||
$uri = 'uri from route.';
|
||||
$route_mock = $this->getMockBuilder('Route')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('getUri'))
|
||||
->getMock();
|
||||
$route_mock->expects($this->once())
|
||||
->method('getUri')
|
||||
->with()
|
||||
->will($this->returnValue($uri));
|
||||
$router_mock = $this->getMockBuilder('Router')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('getRoute', 'routeIsExists', 'getRouteByName'))
|
||||
->getMock();
|
||||
$router_mock->expects($this->never())
|
||||
->method('getRoute');
|
||||
$router_mock->expects($this->at(0))
|
||||
->method('routeIsExists')
|
||||
->with($this->equalTo($name))
|
||||
->will($this->returnValue(true));
|
||||
$router_mock->expects($this->at(1))
|
||||
->method('getRouteByName')
|
||||
->with($this->equalTo($name))
|
||||
->will($this->returnValue($route_mock));
|
||||
$this->assertEquals($uri, $router_mock->getUri($name));
|
||||
}
|
||||
|
||||
public function testGetUriWithNamedWithError()
|
||||
{
|
||||
$name = 'name of route';
|
||||
$router_mock = $this->getMockBuilder('Router')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('getRoute', 'routeIsExists', 'getRouteByName'))
|
||||
->getMock();
|
||||
$router_mock->expects($this->never())
|
||||
->method('getRoute');
|
||||
$router_mock->expects($this->once())
|
||||
->method('routeIsExists')
|
||||
->with($this->equalTo($name))
|
||||
->will($this->returnValue(false));
|
||||
$router_mock->expects($this->never())
|
||||
->method('getRouteByName');
|
||||
$this->setExpectedException('ErrorException');
|
||||
$router_mock->getUri($name);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user