/
githubmirror
/
framework
Обзор
Документация
Войти
/
githubmirror
/
framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
13.x
tests/Cache/CacheStorageStoreTest.php
107 строк
3 KB
Lucas Michot
[13.x] Reset fake time globally after each test, drop redundant Carbon::setTestNow() cleanup (#60761)
14 июл 2026, 16:42
Не верифицирован
14 июл 2026, 16:42
87b2cbd
Код
Авторство
О чём код?
<?php namespace Illuminate\Tests\Cache; use Illuminate\Cache\Repository; use Illuminate\Cache\StorageStore; use Illuminate\Support\Carbon; use Illuminate\Tests\Cache\Fixtures\ArrayFilesystem; use PHPUnit\Framework\TestCase; class CacheStorageStoreTest extends TestCase { public function testValuesCanBeStoredAndRetrieved() { $disk = new ArrayFilesystem; $store = new StorageStore($disk, 'cache', 'prefix:'); $this->assertTrue($store->put('foo', 'bar', 60)); $this->assertSame('bar', $store->get('foo')); $this->assertStringStartsWith('cache/', $store->path('foo')); } public function testExpiredItemsReturnNullAndGetDeleted() { Carbon::setTestNow($now = Carbon::now()); $disk = new ArrayFilesystem; $store = new StorageStore($disk, 'cache'); $store->put('foo', 'bar', 1); Carbon::setTestNow($now->addSeconds(2)); $this->assertNull($store->get('foo')); $this->assertFalse($disk->exists($store->path('foo'))); } public function testAddDoesNotOverwriteExistingValues() { $store = new StorageStore(new ArrayFilesystem, 'cache'); $this->assertTrue($store->add('foo', 'bar', 60)); $this->assertFalse($store->add('foo', 'baz', 60)); $this->assertSame('bar', $store->get('foo')); } public function testIncrementAndDecrementRetainExpiration() { Carbon::setTestNow($now = Carbon::now()); $store = new StorageStore(new ArrayFilesystem, 'cache'); $store->put('foo', 5, 60); $this->assertSame(7, $store->increment('foo', 2)); $this->assertSame(4, $store->decrement('foo', 3)); Carbon::setTestNow($now->addSeconds(61)); $this->assertNull($store->get('foo')); } public function testTouchUpdatesExpiration() { Carbon::setTestNow($now = Carbon::now()); $store = new StorageStore(new ArrayFilesystem, 'cache'); $store->put('foo', 'bar', 2); Carbon::setTestNow($now->addSecond()); $this->assertTrue($store->touch('foo', 60)); Carbon::setTestNow($now->addSecond()); $this->assertSame('bar', $store->get('foo')); } public function testForgetRemovesFlexibleCreatedKeyOnlyWhenParentIsForgotten() { $disk = new ArrayFilesystem; $store = new StorageStore($disk, 'cache'); $store->put(Repository::FLEXIBLE_CREATED_KEY_PREFIX.'foo', true, 60); $this->assertFalse($store->forget('foo')); $this->assertTrue($disk->exists($store->path(Repository::FLEXIBLE_CREATED_KEY_PREFIX.'foo'))); $store->put('foo', 'bar', 60); $this->assertTrue($store->forget('foo')); $this->assertFalse($disk->exists($store->path('foo'))); $this->assertFalse($disk->exists($store->path(Repository::FLEXIBLE_CREATED_KEY_PREFIX.'foo'))); } public function testFlushRemovesScopedDirectory() { $disk = new ArrayFilesystem; $store = new StorageStore($disk, 'cache'); $store->put('foo', 'bar', 60); $disk->put('other/file', 'value'); $this->assertTrue($store->flush()); $this->assertNull($store->get('foo')); $this->assertTrue($disk->exists('other/file')); } }