|
13 | 13 |
|
14 | 14 | namespace CodeIgniter\Cache\Handlers; |
15 | 15 |
|
| 16 | +use ArgumentCountError; |
16 | 17 | use CodeIgniter\Cache\CacheFactory; |
17 | 18 | use CodeIgniter\Cache\LockStoreInterface; |
18 | 19 | use CodeIgniter\Cache\LockStoreProviderInterface; |
@@ -101,6 +102,48 @@ public function testRemember(): void |
101 | 102 | $this->assertNull($this->handler->get(self::$key1)); |
102 | 103 | } |
103 | 104 |
|
| 105 | + /** |
| 106 | + * This test waits for 3 seconds before last assertion so this |
| 107 | + * is naturally a "slow" test on the perspective of the default limit. |
| 108 | + * |
| 109 | + * @timeLimit 3.5 |
| 110 | + */ |
| 111 | + public function testRememberWithTTLCallable(): void |
| 112 | + { |
| 113 | + $this->handler->remember(self::$key1, static fn (): int => 2, static fn (): string => 'value'); |
| 114 | + |
| 115 | + $this->assertSame('value', $this->handler->get(self::$key1)); |
| 116 | + $this->assertNull($this->handler->get(self::$dummy)); |
| 117 | + |
| 118 | + CLI::wait(3); |
| 119 | + $this->assertNull($this->handler->get(self::$key1)); |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * This test waits for 3 seconds before last assertion so this |
| 124 | + * is naturally a "slow" test on the perspective of the default limit. |
| 125 | + * |
| 126 | + * @timeLimit 3.5 |
| 127 | + */ |
| 128 | + public function testRememberWithTTLCallableAndValuePassed(): void |
| 129 | + { |
| 130 | + $this->handler->remember(self::$key1, static fn ($value): int => $value[0], static fn (): array => [2, 3]); |
| 131 | + |
| 132 | + $this->assertSame([2, 3], $this->handler->get(self::$key1)); |
| 133 | + $this->assertNull($this->handler->get(self::$dummy)); |
| 134 | + |
| 135 | + CLI::wait(3); |
| 136 | + $this->assertNull($this->handler->get(self::$key1)); |
| 137 | + } |
| 138 | + |
| 139 | + public function testRememberWithTTLCallableAndMultipleParameters(): void |
| 140 | + { |
| 141 | + $this->expectException(ArgumentCountError::class); |
| 142 | + |
| 143 | + /** @phpstan-ignore argument.type */ |
| 144 | + $this->handler->remember(self::$key1, static fn ($a, $b): int => 2, static fn (): string => 'value'); |
| 145 | + } |
| 146 | + |
104 | 147 | public function testSave(): void |
105 | 148 | { |
106 | 149 | $this->assertTrue($this->handler->save(self::$key1, 'value')); |
|
0 commit comments