Fix tests

This commit is contained in:
Nicolas Lœuillet 2016-04-15 09:58:29 +02:00
parent af497a641c
commit 4086e0782e
No known key found for this signature in database
GPG key ID: 5656BE27E1E34D0A
2 changed files with 19 additions and 12 deletions

View file

@ -4,6 +4,9 @@ namespace Wallabag\CoreBundle\Helper;
use Symfony\Component\Routing\Router;
/**
* Manage redirections to avoid redirecting to empty routes.
*/
class Redirect
{
private $router;
@ -21,16 +24,14 @@ class Redirect
*/
public function to($url, $fallback = '')
{
$returnUrl = $url;
if (null === $url) {
if ('' !== $fallback) {
$returnUrl = $fallback;
} else {
$returnUrl = $this->router->generate('homepage');
}
if (null !== $url) {
return $url;
}
return $returnUrl;
if ('' === $fallback) {
return $this->router->generate('homepage');
}
return $fallback;
}
}

View file

@ -6,7 +6,7 @@ use Wallabag\CoreBundle\Helper\Redirect;
class RedirectTest extends \PHPUnit_Framework_TestCase
{
/** @var \Symfony\Component\Routing\Router */
/** @var \PHPUnit_Framework_MockObject_MockObject */
private $routerMock;
/** @var Redirect */
@ -41,9 +41,15 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
private function getRouterMock()
{
return $this->getMockBuilder('Symfony\Component\Routing\Router')
->setMethods(['generate'])
$mock = $this->getMockBuilder('Symfony\Component\Routing\Router')
->disableOriginalConstructor()
->getMock();
$mock->expects($this->any())
->method('generate')
->with('homepage')
->willReturn('homepage');
return $mock;
}
}