Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
55 / 55
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3// ╔════════════════════════════════════════════════════════════╗
4// ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║
5// ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com>     ║
6// ╚════════════════════════════════════════════════════════════╝
7
8declare(strict_types=1);
9
10use Phexium\Plugin\Cache\Adapter\NullCache;
11
12beforeEach(function (): void {
13    $this->cache = new NullCache();
14});
15
16test('set does nothing', function (): void {
17    $this->cache->set('key', 'value');
18
19    expect($this->cache->has('key'))->toBeFalse();
20    expect($this->cache->get('key'))->toBeNull();
21});
22
23test('set with TTL does nothing', function (): void {
24    $this->cache->set('key', 'value', 3600);
25
26    expect($this->cache->has('key'))->toBeFalse();
27    expect($this->cache->get('key'))->toBeNull();
28});
29
30test('set returns true', function (): void {
31    expect($this->cache->set('key', 'value'))->toBeTrue();
32});
33
34test('set with DateInterval TTL does nothing', function (): void {
35    $this->cache->set('key', 'value', new DateInterval('PT1H'));
36
37    expect($this->cache->has('key'))->toBeFalse();
38});
39
40test('get always returns null without default', function (): void {
41    expect($this->cache->get('unknown'))->toBeNull();
42
43    $this->cache->set('key', 'value');
44
45    expect($this->cache->get('key'))->toBeNull();
46});
47
48test('get returns default value for non-existent key', function (): void {
49    expect($this->cache->get('unknown', 'default'))->toBe('default');
50});
51
52test('has always returns false', function (): void {
53    expect($this->cache->has('unknown'))->toBeFalse();
54
55    $this->cache->set('key', 'value');
56
57    expect($this->cache->has('key'))->toBeFalse();
58});
59
60test('delete always returns false', function (): void {
61    expect($this->cache->delete('unknown'))->toBeFalse();
62
63    $this->cache->set('key', 'value');
64
65    expect($this->cache->delete('key'))->toBeFalse();
66});
67
68test('clear does nothing and returns true', function (): void {
69    $this->cache->set('key', 'value');
70
71    expect($this->cache->clear())->toBeTrue();
72
73    expect($this->cache->has('key'))->toBeFalse();
74});
75
76test('getMultiple returns defaults for all keys', function (): void {
77    $result = $this->cache->getMultiple(['key1', 'key2'], 'default');
78
79    expect($result)->toBe(['key1' => 'default', 'key2' => 'default']);
80});
81
82test('setMultiple returns true', function (): void {
83    $result = $this->cache->setMultiple(['key1' => 'value1', 'key2' => 'value2']);
84
85    expect($result)->toBeTrue();
86});
87
88test('deleteMultiple returns true', function (): void {
89    $result = $this->cache->deleteMultiple(['key1', 'key2']);
90
91    expect($result)->toBeTrue();
92});