]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php
Convert array + phpDoc
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Tests / WallabagCoreTestCase.php
index e5096528cefe39d683a07a6fb67286913dc20a97..05450c0b987ac7d86a0799213bfa555cb824e282 100644 (file)
@@ -15,6 +15,8 @@ abstract class WallabagCoreTestCase extends WebTestCase
 
     public function setUp()
     {
+        parent::setUp();
+
         $this->client = static::createClient();
     }
 
@@ -22,11 +24,28 @@ abstract class WallabagCoreTestCase extends WebTestCase
     {
         $crawler = $this->client->request('GET', '/login');
         $form = $crawler->filter('button[type=submit]')->form();
-        $data = array(
+        $data = [
             '_username' => $username,
             '_password' => 'mypassword',
-        );
+        ];
 
         $this->client->submit($form, $data);
     }
+
+    /**
+     * Return the user id of the logged in user.
+     * You should be sure that you called `logInAs` before.
+     *
+     * @return int
+     */
+    public function getLoggedInUserId()
+    {
+        $token = static::$kernel->getContainer()->get('security.token_storage')->getToken();
+
+        if (null !== $token) {
+            return $token->getUser()->getId();
+        }
+
+        throw new \RuntimeException('No logged in User.');
+    }
 }