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

BaseAcceptanceTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 6
dl 0
loc 41
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A logIn() 0 12 1
A logOut() 0 8 1
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