mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-27 11:31:05 +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;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue