From 6e4a9ef23ac128969c3821b6bb5079adce93131f Mon Sep 17 00:00:00 2001 From: Alexander Demidov Date: Fri, 25 May 2012 18:41:25 +0400 Subject: [PATCH] Modify RouterTest (unmocked simply methods). --- tests/app/router/RouterTest.php | 42 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/tests/app/router/RouterTest.php b/tests/app/router/RouterTest.php index 436e2fe..fa5c6e6 100644 --- a/tests/app/router/RouterTest.php +++ b/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');