diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f41a7cbc3..9eee7c86f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -45,11 +45,6 @@ parameters: count: 1 path: tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php - - - message: "#^Call to method generate\\(\\) on an unknown class PHPUnit_Framework_MockObject_MockObject\\.$#" - count: 2 - path: tests/Wallabag/CoreBundle/Helper/RedirectTest.php - - message: "#^Property Tests\\\\Wallabag\\\\CoreBundle\\\\Helper\\\\RedirectTest\\:\\:\\$routerMock has unknown class PHPUnit_Framework_MockObject_MockObject as its type\\.$#" count: 1 diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index d0e5a5aa6..32db1ef0f 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -104,7 +104,7 @@ class TagController extends AbstractController $this->entityManager->flush(); } - $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), '', true); + $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), true); return $this->redirect($redirectUrl); } @@ -185,7 +185,7 @@ class TagController extends AbstractController $form = $this->createForm(RenameTagType::class, new Tag()); $form->handleRequest($request); - $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), '', true); + $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), true); if ($form->isSubmitted() && $form->isValid()) { $newTag = new Tag(); @@ -257,7 +257,7 @@ class TagController extends AbstractController $this->entityManager->flush(); } - return $this->redirect($this->redirectHelper->to($request->getSession()->get('prevUrl'), '', true)); + return $this->redirect($this->redirectHelper->to($request->getSession()->get('prevUrl'), true)); } /** @@ -279,7 +279,7 @@ class TagController extends AbstractController $this->entityManager->remove($tag); $this->entityManager->flush(); } - $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), '', true); + $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), true); return $this->redirect($redirectUrl); } diff --git a/src/Wallabag/CoreBundle/Helper/Redirect.php b/src/Wallabag/CoreBundle/Helper/Redirect.php index 99bc192a6..6bcb64779 100644 --- a/src/Wallabag/CoreBundle/Helper/Redirect.php +++ b/src/Wallabag/CoreBundle/Helper/Redirect.php @@ -23,12 +23,11 @@ class Redirect /** * @param string $url URL to redirect - * @param string $fallback Fallback URL if $url is null * @param bool $ignoreActionMarkAsRead Ignore configured action when mark as read * * @return string */ - public function to($url, $fallback = '', $ignoreActionMarkAsRead = false) + public function to($url, $ignoreActionMarkAsRead = false) { $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; @@ -45,10 +44,6 @@ class Redirect return $url; } - if ('' === $fallback) { - return $this->router->generate('homepage'); - } - - return $fallback; + return $this->router->generate('homepage'); } } diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php index 780eeddac..2b56e8afb 100644 --- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php @@ -33,7 +33,7 @@ class RedirectTest extends TestCase $this->routerMock->expects($this->any()) ->method('generate') ->with('homepage') - ->willReturn('homepage'); + ->willReturn('/'); $this->user = new User(); $this->user->setName('youpi'); @@ -59,18 +59,11 @@ class RedirectTest extends TestCase $this->redirect = new Redirect($this->routerMock, $tokenStorage); } - public function testRedirectToNullWithFallback() - { - $redirectUrl = $this->redirect->to(null, 'fallback'); - - $this->assertSame('fallback', $redirectUrl); - } - - public function testRedirectToNullWithoutFallback() + public function testRedirectToNull() { $redirectUrl = $this->redirect->to(null); - $this->assertSame($this->routerMock->generate('homepage'), $redirectUrl); + $this->assertSame('/', $redirectUrl); } public function testRedirectToValidUrl() @@ -94,24 +87,24 @@ class RedirectTest extends TestCase $redirectUrl = $this->redirect->to('/unread/list'); - $this->assertSame($this->routerMock->generate('homepage'), $redirectUrl); + $this->assertSame('/', $redirectUrl); } public function testUserForRedirectWithIgnoreActionMarkAsRead() { $this->user->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); - $redirectUrl = $this->redirect->to('/unread/list', '', true); + $redirectUrl = $this->redirect->to('/unread/list', true); $this->assertSame('/unread/list', $redirectUrl); } - public function testUserForRedirectNullWithFallbackWithIgnoreActionMarkAsRead() + public function testUserForRedirectNullWithIgnoreActionMarkAsRead() { $this->user->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); - $redirectUrl = $this->redirect->to(null, 'fallback', true); + $redirectUrl = $this->redirect->to(null, true); - $this->assertSame('fallback', $redirectUrl); + $this->assertSame('/', $redirectUrl); } }