Browse Source

Modify RouterTest (unmocked simply methods).

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

40
tests/app/router/RouterTest.php

@ -84,15 +84,11 @@ class RouterTest extends PHPUnit_Framework_TestCase
->method('getUri') ->method('getUri')
->with() ->with()
->will($this->returnValue($uri)); ->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() public function testGetUriWithNamed()
@ -107,21 +103,11 @@ class RouterTest extends PHPUnit_Framework_TestCase
->method('getUri') ->method('getUri')
->with() ->with()
->will($this->returnValue($uri)); ->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() public function testGetUriWithNamedWithError()
@ -129,14 +115,10 @@ class RouterTest extends PHPUnit_Framework_TestCase
$name = 'name of route'; $name = 'name of route';
$router_mock = $this->getMockBuilder('Router') $router_mock = $this->getMockBuilder('Router')
->disableOriginalConstructor() ->disableOriginalConstructor()
->setMethods(array('getRoute', 'routeIsExists', 'getRouteByName'))
->setMethods(array('getRoute', 'getRouteByName'))
->getMock(); ->getMock();
$router_mock->expects($this->never()) $router_mock->expects($this->never())
->method('getRoute'); ->method('getRoute');
$router_mock->expects($this->once())
->method('routeIsExists')
->with($this->equalTo($name))
->will($this->returnValue(false));
$router_mock->expects($this->never()) $router_mock->expects($this->never())
->method('getRouteByName'); ->method('getRouteByName');
$this->setExpectedException('ErrorException'); $this->setExpectedException('ErrorException');

Loading…
Cancel
Save