silverstripe /
silverstripe-environmentcheck
| 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
|
|||
| 38 | |||
| 39 | // Run checks for each response above |
||
| 40 | $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check()); |
||
|
0 ignored issues
–
show
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 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
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 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
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 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
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 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
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
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 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
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 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
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 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
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 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
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
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 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
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 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
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 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
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 The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||
| 100 | } |
||
| 101 | } |
||
| 102 |
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..