Passed
Push — main ( e730b7...fedd50 )
by Alex
04:56
created

SessionHelperTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A createSession() 0 24 2
1
<?php
2
3
namespace App\Tests;
4
5
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
6
use Symfony\Component\BrowserKit\Cookie;
7
use Symfony\Component\HttpFoundation\Session\Session;
8
9
trait SessionHelperTrait
10
{
11
    /**
12
     * @param KernelBrowser $clien Current client.
13
     * @param mixed[]       $data  Session data.
14
     * @return Session
15
     */
16
    public function createSession(KernelBrowser $client, array $data): Session
17
    {
18
        $session = $client->getContainer()->get('session.factory')->createSession(null);
19
20
        $session->setId('session-mock-id');
21
        $session->start();
22
23
        foreach ($data as $key => $value) {
24
            $session->set($key, $value);
25
        }
26
27
        $session->save();
28
29
        $sessionCookie = new Cookie(
30
            'MOCKSESSID',
31
            'session-mock-id',
32
            null,
33
            null,
34
            'localhost',
35
        );
36
37
        $client->getCookieJar()->set($sessionCookie);
38
39
        return $session;
40
    }
41
}