Last active
August 29, 2015 13:57
-
-
Save mustafaileri/9659863 to your computer and use it in GitHub Desktop.
Mocking methods by parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function setRouterMock() | |
{ | |
$routerMock = $this->getMockBuilder("Symfony\Bundle\FrameworkBundle\Routing\Router")->disableOriginalConstructor() | |
->disableOriginalConstructor()->setMethods(array("all", "getRouteCollection", "generate"))->getMock(); | |
$routerMock->expects($this->any())->method("all")->will($this->returnValue(array())); | |
$routerMock->expects($this->any())->method("getRouteCollection")->will($this->returnValue($this->routeCollection)); | |
$routerMock->expects($this->any())->method("generate")->withAnyParameters()->will($this->returnCallback(array($this, "generateUrlCallback"))); | |
$this->routerMock = $routerMock; | |
} | |
public function generateUrlCallback($routeName) | |
{ | |
return $this->routeCollection->get($routeName)->getPath(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment