Completed
Push — master ( 73634f...8a94ba )
by Philip
02:09
created

BaseAcceptanceTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 7
dl 0
loc 42
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 Dontdrinkandroot\Gitki\WebBundle\Tests\Acceptance;
4
5
use Dontdrinkandroot\Gitki\WebBundle\Entity\User;
6
use Dontdrinkandroot\Gitki\WebBundle\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
#
12
13
abstract class BaseAcceptanceTest extends BaseIntegrationTest
14
{
15
16
    /**
17
     * @var Client
18
     */
19
    protected $client = null;
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    protected function setUp()
25
    {
26
        parent::setUp();
27
        $this->client = static::createClient();
28
    }
29
30
    /**
31
     * @param User $user
32
     */
33
    protected function logIn(User $user)
34
    {
35
        $session = $this->client->getContainer()->get('session');
36
37
        $firewall = 'main';
38
        $token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles());
39
        $session->set('_security_' . $firewall, serialize($token));
40
        $session->save();
41
42
        $cookie = new Cookie($session->getName(), $session->getId());
43
        $this->client->getCookieJar()->set($cookie);
44
    }
45
46
    protected function logOut()
47
    {
48
        $session = $this->client->getContainer()->get('session');
49
        $session->clear();
50
        $session->save();
51
52
        $this->client->getCookieJar()->clear();
53
    }
54
}
55