-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathIsCacheHitConstraintTestCase.php
More file actions
60 lines (50 loc) · 2.22 KB
/
IsCacheHitConstraintTestCase.php
File metadata and controls
60 lines (50 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/*
* This file is part of the FOSHttpCache package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\HttpCache\Tests\Unit\Test\PHPUnit;
use FOS\HttpCache\Test\PHPUnit\IsCacheHitConstraint;
use GuzzleHttp\Psr7\Stream;
use PHPUnit\Framework\ExpectationFailedException;
class IsCacheHitConstraintTestCase extends AbstractCacheConstraintTestCase
{
private IsCacheHitConstraint $constraint;
public function setUp(): void
{
$this->constraint = new IsCacheHitConstraint('cache-header');
}
public function testMatches(): void
{
$response = $this->getResponseMock()
->shouldReceive('hasHeader')->with('cache-header')->andReturn(true)
// https://github.com/phpstan/phpstan-mockery/issues/8
/* @phpstan-ignore-next-line */
->shouldReceive('getHeaderLine')->with('cache-header')->once()->andReturn('MISS')
->shouldReceive('getStatusCode')->andReturn(500)
->shouldReceive('getHeaders')->andReturn([])
->shouldReceive('getBody')->andReturn(new Stream(fopen('php://temp', 'r+')))
->getMock();
$this->expectException(ExpectationFailedException::class);
$this->expectExceptionMessage('Failed asserting that response (with status code 500) is a cache hit');
$this->constraint->evaluate($response);
}
public function testMatchesThrowsExceptionIfHeaderIsMissing(): void
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Response has no "cache-header" header');
$response = $this->getResponseMock()
->shouldReceive('hasHeader')->with('cache-header')->once()->andReturn(false)
// https://github.com/phpstan/phpstan-mockery/issues/8
/* @phpstan-ignore-next-line */
->shouldReceive('getStatusCode')->andReturn(200)
->shouldReceive('getHeaders')->andReturn([])
->shouldReceive('getBody')->andReturn(new Stream(fopen('php://temp', 'r+')))
->getMock();
$this->constraint->evaluate($response);
}
}