]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - tests/Wallabag/CoreBundle/Helper/RedirectTest.php
Tried to fix tests
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Helper / RedirectTest.php
index f339f75e80f07fe65f9768a6525602e467799102..3dcdf8de6cb2ab68278de5e6132a36299bc2d861 100644 (file)
@@ -12,10 +12,15 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
     /** @var Redirect */
     private $redirect;
 
+    const PASSWORD = 's3Cr3t';
+    const SALT = '^S4lt$';
+
     public function setUp()
     {
         $this->routerMock = $this->getRouterMock();
-        $this->redirect = new Redirect($this->routerMock);
+        $user = $this->createUser();
+        $tokenStorage = $this->createTokenStorage($user);
+        $this->redirect = new Redirect($this->routerMock, $tokenStorage);
     }
 
     public function testRedirectToNullWithFallback()
@@ -52,4 +57,57 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
 
         return $mock;
     }
+
+    protected function createTokenStorage($user = null)
+    {
+        $token = $this->createAuthenticationToken($user);
+
+        $mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $mock
+            ->expects($this->any())
+            ->method('getToken')
+            ->will($this->returnValue($token))
+        ;
+
+        return $mock;
+    }
+
+    protected function createUser()
+    {
+        $mock = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $mock
+            ->expects($this->any())
+            ->method('getPassword')
+            ->will($this->returnValue(static::PASSWORD))
+        ;
+
+        $mock
+            ->expects($this->any())
+            ->method('getSalt')
+            ->will($this->returnValue(static::SALT))
+        ;
+
+        return $mock;
+    }
+
+    protected function createAuthenticationToken($user = null)
+    {
+        $mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $mock
+            ->expects($this->any())
+            ->method('getUser')
+            ->will($this->returnValue($user))
+        ;
+
+        return $mock;
+    }
 }