Completed
Push — master ( 402c8e...a49823 )
by Philip
22:11
created

BaseAcceptanceTest::logOut()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace App\Tests\Acceptance;
4
5
use App\Entity\User;
6
use App\Tests\Integration\BaseIntegrationTest;
7
use Symfony\Bundle\FrameworkBundle\Client;
8
use Symfony\Component\BrowserKit\Cookie;
9
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
10
11
abstract class BaseAcceptanceTest extends BaseIntegrationTest
12
{
13
    /**
14
     * @var Client
15
     */
16
    protected $client = null;
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    protected function setUp()
22
    {
23
        parent::setUp();
24
        $this->client = static::createClient();
25
    }
26
27
    /**
28
     * @param User $user
29
     */
30
    protected function logIn(User $user)
31
    {
32
        $session = $this->client->getContainer()->get('session');
33
34
        $firewall = 'secured_area';
35
        $token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles());
36
        $session->set('_security_' . $firewall, serialize($token));
37
        $session->save();
38
39
        $cookie = new Cookie($session->getName(), $session->getId());
40
        $this->client->getCookieJar()->set($cookie);
41
    }
42
43
    protected function logOut()
44
    {
45
        $session = $this->client->getContainer()->get('session');
46
        $session->clear();
47
        $session->save();
48
49
        $this->client->getCookieJar()->clear();
50
    }
51
}
52