/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterAndRedisAdapterTest.php
73 строки
2 KB
Dariusz Ruminski
PHP CS Fixer: modernize usage of `random_api_migration`
22 янв 2026, 23:20
22 янв 2026, 23:20
c28cc95
Код
Авторство
О чём код?
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Cache\Tests\Adapter; use PHPUnit\Framework\Attributes\Group; use Psr\Cache\CacheItemPoolInterface; use Symfony\Component\Cache\Adapter\AbstractAdapter; use Symfony\Component\Cache\Adapter\ProxyAdapter; use Symfony\Component\Cache\Adapter\RedisAdapter; use Symfony\Component\Cache\CacheItem; #[Group('integration')] class ProxyAdapterAndRedisAdapterTest extends AbstractRedisAdapterTestCase { protected $skippedTests = [ 'testPrune' => 'RedisAdapter does not implement PruneableInterface.', ]; public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); self::$redis = AbstractAdapter::createConnection('redis://'.getenv('REDIS_HOST')); } public function createCachePool($defaultLifetime = 0, ?string $testMethod = null): CacheItemPoolInterface { return new ProxyAdapter(new RedisAdapter(self::$redis, str_replace('\\', '.', __CLASS__), 100), 'ProxyNS', $defaultLifetime); } public function testSaveItemPermanently() { $setCacheItemExpiry = \Closure::bind( static function (CacheItem $item, $expiry) { $item->expiry = $expiry; return $item; }, null, CacheItem::class ); $cache = $this->createCachePool(1); $cache->clear(); $value = random_int(0, \PHP_INT_MAX); $item = $cache->getItem('foo'); $setCacheItemExpiry($item, 0); $cache->save($item->set($value)); $item = $cache->getItem('bar'); $setCacheItemExpiry($item, 0.0); $cache->save($item->set($value)); $item = $cache->getItem('baz'); $cache->save($item->set($value)); $this->assertSame($value, $this->cache->getItem('foo')->get()); $this->assertSame($value, $this->cache->getItem('bar')->get()); $this->assertSame($value, $this->cache->getItem('baz')->get()); sleep(1); usleep(100000); $this->assertSame($value, $this->cache->getItem('foo')->get()); $this->assertSame($value, $this->cache->getItem('bar')->get()); $this->assertFalse($this->cache->getItem('baz')->isHit()); } }