Skip to content

Instantly share code, notes, and snippets.

@mustafaileri
Last active August 29, 2015 13:57
Show Gist options
  • Save mustafaileri/9659863 to your computer and use it in GitHub Desktop.
Save mustafaileri/9659863 to your computer and use it in GitHub Desktop.
Mocking methods by parameters
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