|
2 | 2 |
|
3 | 3 | namespace Illuminate\Tests\Integration\Cache;
|
4 | 4 |
|
| 5 | +use BadMethodCallException; |
5 | 6 | use Illuminate\Cache\Events\CacheEvent;
|
6 | 7 | use Illuminate\Cache\Events\CacheMissed;
|
7 | 8 | use Illuminate\Cache\Events\ForgettingKey;
|
|
10 | 11 | use Illuminate\Cache\Events\RetrievingKey;
|
11 | 12 | use Illuminate\Cache\Events\RetrievingManyKeys;
|
12 | 13 | use Illuminate\Cache\Events\WritingKey;
|
| 14 | +use Illuminate\Contracts\Cache\Store; |
13 | 15 | use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis;
|
14 | 16 | use Illuminate\Support\Facades\Cache;
|
15 | 17 | use Illuminate\Support\Facades\Config;
|
16 | 18 | use Illuminate\Support\Facades\Event;
|
| 19 | +use Illuminate\Support\Facades\Exceptions; |
17 | 20 | use Illuminate\Support\Facades\Redis;
|
| 21 | +use Illuminate\Support\Facades\Route; |
18 | 22 | use Orchestra\Testbench\TestCase;
|
| 23 | +use Throwable; |
19 | 24 |
|
20 | 25 | class MemoizedStoreTest extends TestCase
|
21 | 26 | {
|
@@ -406,4 +411,84 @@ public function test_it_resets_cache_store_with_scoped_instances()
|
406 | 411 | $this->assertSame('Taylor', $live);
|
407 | 412 | $this->assertSame('Taylor', $memoized);
|
408 | 413 | }
|
| 414 | + |
| 415 | + public function test_it_throws_when_underlying_store_does_not_support_locks() |
| 416 | + { |
| 417 | + $this->freezeTime(); |
| 418 | + $exceptions = []; |
| 419 | + Exceptions::reportable(function (Throwable $e) use (&$exceptions) { |
| 420 | + $exceptions[] = $e; |
| 421 | + }); |
| 422 | + Config::set('cache.stores.no-lock', ['driver' => 'no-lock']); |
| 423 | + Cache::extend('no-lock', fn () => Cache::repository(new class implements Store { |
| 424 | + public function get($key) |
| 425 | + { |
| 426 | + return Cache::get(...func_get_args()); |
| 427 | + } |
| 428 | + |
| 429 | + public function many(array $keys) |
| 430 | + { |
| 431 | + return Cache::many(...func_get_args()); |
| 432 | + } |
| 433 | + |
| 434 | + public function put($key, $value, $seconds) { |
| 435 | + |
| 436 | + return Cache::put(...func_get_args()); |
| 437 | + } |
| 438 | + |
| 439 | + public function putMany(array $values, $seconds) { |
| 440 | + return Cache::putMany(...func_get_args()); |
| 441 | + } |
| 442 | + |
| 443 | + public function increment($key, $value = 1) { |
| 444 | + |
| 445 | + return Cache::increment(...func_get_args()); |
| 446 | + } |
| 447 | + |
| 448 | + public function decrement($key, $value = 1) { |
| 449 | + return Cache::decrement(...func_get_args()); |
| 450 | + } |
| 451 | + |
| 452 | + public function forever($key, $value) { |
| 453 | + return Cache::forever(...func_get_args()); |
| 454 | + |
| 455 | + } |
| 456 | + |
| 457 | + public function forget($key) { |
| 458 | + return Cache::forget(...func_get_args()); |
| 459 | + } |
| 460 | + |
| 461 | + public function flush() { |
| 462 | + return Cache::flush(...func_get_args()); |
| 463 | + |
| 464 | + } |
| 465 | + |
| 466 | + public function getPrefix() { |
| 467 | + return Cache::getPrefix(...func_get_args()); |
| 468 | + } |
| 469 | + })); |
| 470 | + Cache::flexible('key', [10, 20], 'value-1'); |
| 471 | + |
| 472 | + $this->travel(11)->seconds(); |
| 473 | + Cache::memo('no-lock')->flexible('key', [10, 20], 'value-2'); |
| 474 | + defer()->invoke(); |
| 475 | + $value = Cache::get('key'); |
| 476 | + |
| 477 | + $this->assertCount(1, $exceptions); |
| 478 | + $this->assertInstanceOf(BadMethodCallException::class, $exceptions[0]); |
| 479 | + $this->assertSame('This cache store does not support locks.', $exceptions[0]->getMessage()); |
| 480 | + } |
| 481 | + |
| 482 | + public function test_it_supports_with_flexible() |
| 483 | + { |
| 484 | + $this->freezeTime(); |
| 485 | + Cache::flexible('key', [10, 20], 'value-1'); |
| 486 | + |
| 487 | + $this->travel(11)->seconds(); |
| 488 | + Cache::memo()->flexible('key', [10, 20], 'value-2'); |
| 489 | + defer()->invoke(); |
| 490 | + $value = Cache::get('key'); |
| 491 | + |
| 492 | + $this->assertSame('value-2', $value); |
| 493 | + } |
409 | 494 | }
|
0 commit comments