CacheAssertions::assertHit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCache package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCache\Test;
13
14
use FOS\HttpCache\Test\PHPUnit\IsCacheHitConstraint;
15
use FOS\HttpCache\Test\PHPUnit\IsCacheMissConstraint;
16
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Psr\Http\Message\ResponseInterface;
18
19
/**
20
 * Provides cache hit/miss assertions to PHPUnit tests.
21
 *
22
 * To enable the assertHit and assertMiss assertions, you need to configure your
23
 * caching proxy to set an X-Cache header with the cache status.
24
 *
25
 * Use this trait in conjunction with either the NginxTest, SymfonyTest or
26
 * VarnishTest trait to reset the cache between tests and properly isolate your
27
 * assertions.
28
 */
29
trait CacheAssertions
30
{
31
    /**
32
     * Assert a cache miss.
33
     *
34
     * @param string $message Test failure message (optional)
35
     */
36 22
    public function assertMiss(ResponseInterface $response, $message = '')
37
    {
38 22
        TestCase::assertThat($response, self::isCacheMiss(), $message);
39 22
    }
40
41
    /**
42
     * Assert a cache hit.
43
     *
44
     * @param string $message Test failure message (optional)
45
     */
46 25
    public function assertHit(ResponseInterface $response, $message = '')
47
    {
48 25
        TestCase::assertThat($response, self::isCacheHit(), $message);
49 25
    }
50
51 25
    public static function isCacheHit()
52
    {
53 25
        return new IsCacheHitConstraint();
54
    }
55
56 22
    public static function isCacheMiss()
57
    {
58 22
        return new IsCacheMissConstraint();
59
    }
60
}
61