Browse Source

Modify RouterTest (unmocked simply methods).

master
Alexander Demidov 13 years ago
parent
commit
6e4a9ef23a
  1. 42
      tests/app/router/RouterTest.php

42
tests/app/router/RouterTest.php

@ -84,20 +84,16 @@ class RouterTest extends PHPUnit_Framework_TestCase
->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));
$router = new Router();
$reflection = new ReflectionProperty('Router', 'route');
$reflection->setAccessible(true);
$reflection->setValue($router, $route_mock);
$this->assertEquals($uri, $router->getUri($name));
}
public function testGetUriWithNamed()
{
$name = 'name of route';
$name = 'nameofroute';
$uri = 'uri from route.';
$route_mock = $this->getMockBuilder('Route')
->disableOriginalConstructor()
@ -107,21 +103,11 @@ class RouterTest extends PHPUnit_Framework_TestCase
->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));
$router = new Router();
$reflection = new ReflectionProperty('Router', 'routes');
$reflection->setAccessible(true);
$reflection->setValue($router, array($name => $route_mock));
$this->assertEquals($uri, $router->getUri($name));
}
public function testGetUriWithNamedWithError()
@ -129,14 +115,10 @@ class RouterTest extends PHPUnit_Framework_TestCase
$name = 'name of route';
$router_mock = $this->getMockBuilder('Router')
->disableOriginalConstructor()
->setMethods(array('getRoute', 'routeIsExists', 'getRouteByName'))
->setMethods(array('getRoute', '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');

Loading…
Cancel
Save