mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-23 17:41:01 +00:00
Fix tests
This commit is contained in:
parent
af497a641c
commit
4086e0782e
2 changed files with 19 additions and 12 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue