Completed
Push — master ( 128ddb...c5783a )
by
unknown
14s queued 10s
created

SessionCheckTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testSessionNotSet() 0 12 1
A testSessionSet() 0 17 1
A setUp() 0 4 1
1
<?php
2
3
namespace SilverStripe\EnvironmentCheck\Tests\Checks;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\HandlerStack;
7
use GuzzleHttp\Psr7\Response;
8
use SilverStripe\Dev\SapphireTest;
9
use GuzzleHttp\Handler\MockHandler;
10
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
11
use SilverStripe\EnvironmentCheck\Checks\SessionCheck;
12
13
/**
14
 * Test session checks.
15
 */
16
class SessionCheckTest extends SapphireTest
17
{
18
    /**
19
     * @var SilverStripe\EnvironmentCheck\Checks\SessionCheck
0 ignored issues
show
Bug introduced by
The type SilverStripe\Environment...eck\Checks\SessionCheck was not found. Did you mean SilverStripe\EnvironmentCheck\Checks\SessionCheck? If so, make sure to prefix the type with \.
Loading history...
20
     */
21
    public $sessionCheck = null;
22
23
    /**
24
     * Create a session check for use by tests.
25
     *
26
     * @return void
27
     */
28
    protected function setUp()
29
    {
30
        parent::setUp();
31
        $this->sessionCheck = new SessionCheck('/');
0 ignored issues
show
Documentation Bug introduced by
It seems like new SilverStripe\Environ...hecks\SessionCheck('/') of type SilverStripe\EnvironmentCheck\Checks\SessionCheck is incompatible with the declared type SilverStripe\Environment...eck\Checks\SessionCheck of property $sessionCheck.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
32
    }
33
34
    /**
35
     * Env check reports error when session cookies are being set.
36
     *
37
     * @return void
38
     */
39
    public function testSessionSet()
40
    {
41
        // Create a mock and queue two responses.
42
        $mock = new MockHandler([
43
            new Response(200, ['Set-Cookie' => 'PHPSESSID:foo']),
44
            new Response(200, ['Set-Cookie' => 'SECSESSID:bar'])
45
        ]);
46
47
        $handler = HandlerStack::create($mock);
48
        $client = new Client(['handler' => $handler]);
49
        $this->sessionCheck->client = $client;
50
51
        // Check for PHPSESSID
52
        $this->assertContains(EnvironmentCheck::ERROR, $this->sessionCheck->check());
53
54
        // Check for SECSESSID
55
        $this->assertContains(EnvironmentCheck::ERROR, $this->sessionCheck->check());
56
    }
57
58
    /**
59
     * Env check responds OK when no session cookies are set in response.
60
     *
61
     * @return void
62
     */
63
    public function testSessionNotSet()
64
    {
65
        // Create a mock and queue two responses.
66
        $mock = new MockHandler([
67
            new Response(200)
68
        ]);
69
70
        $handler = HandlerStack::create($mock);
71
        $client = new Client(['handler' => $handler]);
72
        $this->sessionCheck->client = $client;
73
74
        $this->assertContains(EnvironmentCheck::OK, $this->sessionCheck->check());
75
    }
76
}
77