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; use Symfony\Component\Routing\Router;
/**
* Manage redirections to avoid redirecting to empty routes.
*/
class Redirect class Redirect
{ {
private $router; private $router;
@ -21,16 +24,14 @@ class Redirect
*/ */
public function to($url, $fallback = '') public function to($url, $fallback = '')
{ {
$returnUrl = $url; if (null !== $url) {
return $url;
if (null === $url) {
if ('' !== $fallback) {
$returnUrl = $fallback;
} else {
$returnUrl = $this->router->generate('homepage');
}
} }
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 class RedirectTest extends \PHPUnit_Framework_TestCase
{ {
/** @var \Symfony\Component\Routing\Router */ /** @var \PHPUnit_Framework_MockObject_MockObject */
private $routerMock; private $routerMock;
/** @var Redirect */ /** @var Redirect */
@ -41,9 +41,15 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
private function getRouterMock() private function getRouterMock()
{ {
return $this->getMockBuilder('Symfony\Component\Routing\Router') $mock = $this->getMockBuilder('Symfony\Component\Routing\Router')
->setMethods(['generate'])
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$mock->expects($this->any())
->method('generate')
->with('homepage')
->willReturn('homepage');
return $mock;
} }
} }