InteractsWithCache::assertOctaneCacheHas()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 2
rs 10
1
<?php
2
3
namespace Cerbero\OctaneTestbench\Concerns;
4
5
/**
6
 * The trait to interact with the Octane cache.
7
 *
8
 */
9
trait InteractsWithCache
10
{
11
    /**
12
     * Assert that the Laravel Octane cache has the given key set
13
     *
14
     * @param string $key
15
     * @param mixed|null $value
16
     * @return static
17
     */
18 1
    public function assertOctaneCacheHas(string $key, mixed $value = null): static
19
    {
20 1
        $cache = $this->app->cache->store('octane');
21
22 1
        if ($value === null) {
23 1
            $this->assertTrue($cache->has($key), "The Octane cache doesn't have the [$key] key set");
0 ignored issues
show
Bug introduced by
It seems like assertTrue() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
            $this->/** @scrutinizer ignore-call */ 
24
                   assertTrue($cache->has($key), "The Octane cache doesn't have the [$key] key set");
Loading history...
24
        } else {
25 1
            $actual = $cache->get($key);
26 1
            $this->assertSame($value, $actual, "Expected cached value [$value], got [$actual] instead");
0 ignored issues
show
Bug introduced by
It seems like assertSame() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
            $this->/** @scrutinizer ignore-call */ 
27
                   assertSame($value, $actual, "Expected cached value [$value], got [$actual] instead");
Loading history...
27
        }
28
29 1
        return $this;
30
    }
31
32
    /**
33
     * Assert that the Laravel Octane cache doesn't have the given key set
34
     *
35
     * @param string $key
36
     * @return static
37
     */
38 1
    public function assertOctaneCacheMissing(string $key): static
39
    {
40 1
        $cache = $this->app->cache->store('octane');
41
42 1
        $this->assertFalse($cache->has($key), "The Octane cache has the [$key] key set");
0 ignored issues
show
Bug introduced by
It seems like assertFalse() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
        $this->/** @scrutinizer ignore-call */ 
43
               assertFalse($cache->has($key), "The Octane cache has the [$key] key set");
Loading history...
43
44 1
        return $this;
45
    }
46
}
47