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

CacheHeadersCheckTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 40
dl 0
loc 84
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testMustExclude() 0 21 1
A testEtag() 0 21 1
A testMustInclude() 0 21 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\CacheHeadersCheck;
12
13
/**
14
 * Test session checks.
15
 */
16
class CacheHeadersCheckTest extends SapphireTest
17
{
18
    /**
19
     * Test that directives that must be included, are.
20
     *
21
     * @return void
22
     */
23
    public function testMustInclude()
24
    {
25
        // Create a mock and queue responses
26
        $mock = new MockHandler([
27
            new Response(200, ['Cache-Control' => 'must-revalidate', 'ETag' => '123']),
28
            new Response(200, ['Cache-Control' =>'no-cache', 'ETag' => '123']),
29
            new Response(200, ['ETag' => '123']),
30
            new Response(200, ['Cache-Control' => 'must-revalidate, private', 'ETag' => '123']),
31
        ]);
32
33
        $handler = HandlerStack::create($mock);
34
        $client = new Client(['handler' => $handler]);
35
36
        $cacheHeadersCheck = new CacheHeadersCheck('/', ['must-revalidate']);
37
        $cacheHeadersCheck->client = $client;
0 ignored issues
show
Documentation Bug introduced by
It seems like $client of type GuzzleHttp\Client is incompatible with the declared type SilverStripe\Environment...raits\GuzzleHttp\Client of property $client.

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...
38
39
        // Run checks for each response above
40
        $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cacheHeadersCheck->check() targeting SilverStripe\Environment...heHeadersCheck::check() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
41
        $this->assertContains(EnvironmentCheck::ERROR, $cacheHeadersCheck->check());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cacheHeadersCheck->check() targeting SilverStripe\Environment...heHeadersCheck::check() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
42
        $this->assertContains(EnvironmentCheck::ERROR, $cacheHeadersCheck->check());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cacheHeadersCheck->check() targeting SilverStripe\Environment...heHeadersCheck::check() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
43
        $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cacheHeadersCheck->check() targeting SilverStripe\Environment...heHeadersCheck::check() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
44
    }
45
46
    /**
47
     * Test that directives that must be excluded, are.
48
     *
49
     * @return void
50
     */
51
    public function testMustExclude()
52
    {
53
        // Create a mock and queue responses
54
        $mock = new MockHandler([
55
            new Response(200, ['Cache-Control' => 'must-revalidate', 'ETag' => '123']),
56
            new Response(200, ['Cache-Control' =>'no-cache', 'ETag' => '123']),
57
            new Response(200, ['ETag' => '123']),
58
            new Response(200, ['Cache-Control' =>'private, no-store', ' ETag' => '123']),
59
        ]);
60
61
        $handler = HandlerStack::create($mock);
62
        $client = new Client(['handler' => $handler]);
63
64
        $cacheHeadersCheck = new CacheHeadersCheck('/', [], ["no-store", "no-cache", "private"]);
65
        $cacheHeadersCheck->client = $client;
0 ignored issues
show
Documentation Bug introduced by
It seems like $client of type GuzzleHttp\Client is incompatible with the declared type SilverStripe\Environment...raits\GuzzleHttp\Client of property $client.

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...
66
67
        // Run checks for each response above
68
        $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cacheHeadersCheck->check() targeting SilverStripe\Environment...heHeadersCheck::check() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
69
        $this->assertContains(EnvironmentCheck::ERROR, $cacheHeadersCheck->check());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cacheHeadersCheck->check() targeting SilverStripe\Environment...heHeadersCheck::check() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
70
        $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cacheHeadersCheck->check() targeting SilverStripe\Environment...heHeadersCheck::check() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
71
        $this->assertContains(EnvironmentCheck::ERROR, $cacheHeadersCheck->check());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cacheHeadersCheck->check() targeting SilverStripe\Environment...heHeadersCheck::check() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
72
    }
73
74
    /**
75
     * Test that Etag header must exist in response.
76
     *
77
     * @return void
78
     */
79
    public function testEtag()
80
    {
81
        // Create a mock and queue responses
82
        $mock = new MockHandler([
83
            new Response(200, ['Cache-Control' => 'must-revalidate', 'ETag' => '123']),
84
            new Response(200, ['Cache-Control' =>'no-cache']),
85
            new Response(200, ['ETag' => '123']),
86
            new Response(200, []),
87
        ]);
88
89
        $handler = HandlerStack::create($mock);
90
        $client = new Client(['handler' => $handler]);
91
92
        $cacheHeadersCheck = new CacheHeadersCheck('/');
93
        $cacheHeadersCheck->client = $client;
0 ignored issues
show
Documentation Bug introduced by
It seems like $client of type GuzzleHttp\Client is incompatible with the declared type SilverStripe\Environment...raits\GuzzleHttp\Client of property $client.

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...
94
95
        // Run checks for each response above
96
        $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cacheHeadersCheck->check() targeting SilverStripe\Environment...heHeadersCheck::check() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
97
        $this->assertContains(EnvironmentCheck::ERROR, $cacheHeadersCheck->check());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cacheHeadersCheck->check() targeting SilverStripe\Environment...heHeadersCheck::check() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
98
        $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cacheHeadersCheck->check() targeting SilverStripe\Environment...heHeadersCheck::check() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
99
        $this->assertContains(EnvironmentCheck::ERROR, $cacheHeadersCheck->check());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cacheHeadersCheck->check() targeting SilverStripe\Environment...heHeadersCheck::check() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
100
    }
101
}
102