3 namespace Wallabag\ApiBundle\Tests
;
5 use Symfony\Bundle\FrameworkBundle\Test\WebTestCase
;
6 use Symfony\Component\BrowserKit\Cookie
;
8 abstract class WallabagApiTestCase
extends WebTestCase
13 protected $client = null;
16 * @var \FOS\UserBundle\Model\UserInterface
20 public function setUp()
22 $this->client
= $this->createAuthorizedClient();
28 protected function createAuthorizedClient()
30 $client = static::createClient();
31 $container = $client->getContainer();
33 /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */
34 $userManager = $container->get('fos_user.user_manager');
35 /** @var $loginManager \FOS\UserBundle\Security\LoginManager */
36 $loginManager = $container->get('fos_user.security.login_manager');
37 $firewallName = $container->getParameter('fos_user.firewall_name');
39 $this->user
= $userManager->findUserBy(['username' => 'admin']);
40 $loginManager->loginUser($firewallName, $this->user
);
42 // save the login token into the session and put it in a cookie
43 $container->get('session')->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken()));
44 $container->get('session')->save();
46 $session = $container->get('session');
47 $client->getCookieJar()->set(new Cookie($session->getName(), $session->getId()));