mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +02:00
N°2651 - Remove test directories from lib
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
<?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 Symfony\Component\Cache\Adapter\RedisAdapter;
|
||||
|
||||
abstract class AbstractRedisAdapterTest extends AdapterTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testExpiration' => 'Testing expiration slows down the test suite',
|
||||
'testHasItemReturnsFalseWhenDeferredItemIsExpired' => 'Testing expiration slows down the test suite',
|
||||
'testDefaultLifeTime' => 'Testing expiration slows down the test suite',
|
||||
];
|
||||
|
||||
protected static $redis;
|
||||
|
||||
public function createCachePool($defaultLifetime = 0)
|
||||
{
|
||||
return new RedisAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime);
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
if (!\extension_loaded('redis')) {
|
||||
self::markTestSkipped('Extension redis required.');
|
||||
}
|
||||
if (!@((new \Redis())->connect(getenv('REDIS_HOST')))) {
|
||||
$e = error_get_last();
|
||||
self::markTestSkipped($e['message']);
|
||||
}
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
self::$redis = null;
|
||||
}
|
||||
}
|
||||
175
lib/symfony/cache/Tests/Adapter/AdapterTestCase.php
vendored
175
lib/symfony/cache/Tests/Adapter/AdapterTestCase.php
vendored
@@ -1,175 +0,0 @@
|
||||
<?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 Cache\IntegrationTests\CachePoolTest;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\Cache\PruneableInterface;
|
||||
|
||||
abstract class AdapterTestCase extends CachePoolTest
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!\array_key_exists('testDeferredSaveWithoutCommit', $this->skippedTests) && \defined('HHVM_VERSION')) {
|
||||
$this->skippedTests['testDeferredSaveWithoutCommit'] = 'Destructors are called late on HHVM.';
|
||||
}
|
||||
|
||||
if (!\array_key_exists('testPrune', $this->skippedTests) && !$this->createCachePool() instanceof PruneableInterface) {
|
||||
$this->skippedTests['testPrune'] = 'Not a pruneable cache pool.';
|
||||
}
|
||||
}
|
||||
|
||||
public function testDefaultLifeTime()
|
||||
{
|
||||
if (isset($this->skippedTests[__FUNCTION__])) {
|
||||
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
|
||||
}
|
||||
|
||||
$cache = $this->createCachePool(2);
|
||||
|
||||
$item = $cache->getItem('key.dlt');
|
||||
$item->set('value');
|
||||
$cache->save($item);
|
||||
sleep(1);
|
||||
|
||||
$item = $cache->getItem('key.dlt');
|
||||
$this->assertTrue($item->isHit());
|
||||
|
||||
sleep(2);
|
||||
$item = $cache->getItem('key.dlt');
|
||||
$this->assertFalse($item->isHit());
|
||||
}
|
||||
|
||||
public function testExpiration()
|
||||
{
|
||||
if (isset($this->skippedTests[__FUNCTION__])) {
|
||||
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
|
||||
}
|
||||
|
||||
$cache = $this->createCachePool();
|
||||
$cache->save($cache->getItem('k1')->set('v1')->expiresAfter(2));
|
||||
$cache->save($cache->getItem('k2')->set('v2')->expiresAfter(366 * 86400));
|
||||
|
||||
sleep(3);
|
||||
$item = $cache->getItem('k1');
|
||||
$this->assertFalse($item->isHit());
|
||||
$this->assertNull($item->get(), "Item's value must be null when isHit() is false.");
|
||||
|
||||
$item = $cache->getItem('k2');
|
||||
$this->assertTrue($item->isHit());
|
||||
$this->assertSame('v2', $item->get());
|
||||
}
|
||||
|
||||
public function testNotUnserializable()
|
||||
{
|
||||
if (isset($this->skippedTests[__FUNCTION__])) {
|
||||
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
|
||||
}
|
||||
|
||||
$cache = $this->createCachePool();
|
||||
|
||||
$item = $cache->getItem('foo');
|
||||
$cache->save($item->set(new NotUnserializable()));
|
||||
|
||||
$item = $cache->getItem('foo');
|
||||
$this->assertFalse($item->isHit());
|
||||
|
||||
foreach ($cache->getItems(['foo']) as $item) {
|
||||
}
|
||||
$cache->save($item->set(new NotUnserializable()));
|
||||
|
||||
foreach ($cache->getItems(['foo']) as $item) {
|
||||
}
|
||||
$this->assertFalse($item->isHit());
|
||||
}
|
||||
|
||||
public function testPrune()
|
||||
{
|
||||
if (isset($this->skippedTests[__FUNCTION__])) {
|
||||
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
|
||||
}
|
||||
|
||||
if (!method_exists($this, 'isPruned')) {
|
||||
$this->fail('Test classes for pruneable caches must implement `isPruned($cache, $name)` method.');
|
||||
}
|
||||
|
||||
/** @var PruneableInterface|CacheItemPoolInterface $cache */
|
||||
$cache = $this->createCachePool();
|
||||
|
||||
$doSet = function ($name, $value, \DateInterval $expiresAfter = null) use ($cache) {
|
||||
$item = $cache->getItem($name);
|
||||
$item->set($value);
|
||||
|
||||
if ($expiresAfter) {
|
||||
$item->expiresAfter($expiresAfter);
|
||||
}
|
||||
|
||||
$cache->save($item);
|
||||
};
|
||||
|
||||
$doSet('foo', 'foo-val', new \DateInterval('PT05S'));
|
||||
$doSet('bar', 'bar-val', new \DateInterval('PT10S'));
|
||||
$doSet('baz', 'baz-val', new \DateInterval('PT15S'));
|
||||
$doSet('qux', 'qux-val', new \DateInterval('PT20S'));
|
||||
|
||||
sleep(30);
|
||||
$cache->prune();
|
||||
$this->assertTrue($this->isPruned($cache, 'foo'));
|
||||
$this->assertTrue($this->isPruned($cache, 'bar'));
|
||||
$this->assertTrue($this->isPruned($cache, 'baz'));
|
||||
$this->assertTrue($this->isPruned($cache, 'qux'));
|
||||
|
||||
$doSet('foo', 'foo-val');
|
||||
$doSet('bar', 'bar-val', new \DateInterval('PT20S'));
|
||||
$doSet('baz', 'baz-val', new \DateInterval('PT40S'));
|
||||
$doSet('qux', 'qux-val', new \DateInterval('PT80S'));
|
||||
|
||||
$cache->prune();
|
||||
$this->assertFalse($this->isPruned($cache, 'foo'));
|
||||
$this->assertFalse($this->isPruned($cache, 'bar'));
|
||||
$this->assertFalse($this->isPruned($cache, 'baz'));
|
||||
$this->assertFalse($this->isPruned($cache, 'qux'));
|
||||
|
||||
sleep(30);
|
||||
$cache->prune();
|
||||
$this->assertFalse($this->isPruned($cache, 'foo'));
|
||||
$this->assertTrue($this->isPruned($cache, 'bar'));
|
||||
$this->assertFalse($this->isPruned($cache, 'baz'));
|
||||
$this->assertFalse($this->isPruned($cache, 'qux'));
|
||||
|
||||
sleep(30);
|
||||
$cache->prune();
|
||||
$this->assertFalse($this->isPruned($cache, 'foo'));
|
||||
$this->assertTrue($this->isPruned($cache, 'baz'));
|
||||
$this->assertFalse($this->isPruned($cache, 'qux'));
|
||||
|
||||
sleep(30);
|
||||
$cache->prune();
|
||||
$this->assertFalse($this->isPruned($cache, 'foo'));
|
||||
$this->assertTrue($this->isPruned($cache, 'qux'));
|
||||
}
|
||||
}
|
||||
|
||||
class NotUnserializable implements \Serializable
|
||||
{
|
||||
public function serialize()
|
||||
{
|
||||
return serialize(123);
|
||||
}
|
||||
|
||||
public function unserialize($ser)
|
||||
{
|
||||
throw new \Exception(__CLASS__);
|
||||
}
|
||||
}
|
||||
124
lib/symfony/cache/Tests/Adapter/ApcuAdapterTest.php
vendored
124
lib/symfony/cache/Tests/Adapter/ApcuAdapterTest.php
vendored
@@ -1,124 +0,0 @@
|
||||
<?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 Psr\Log\NullLogger;
|
||||
use Symfony\Component\Cache\Adapter\ApcuAdapter;
|
||||
|
||||
class ApcuAdapterTest extends AdapterTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testExpiration' => 'Testing expiration slows down the test suite',
|
||||
'testHasItemReturnsFalseWhenDeferredItemIsExpired' => 'Testing expiration slows down the test suite',
|
||||
'testDefaultLifeTime' => 'Testing expiration slows down the test suite',
|
||||
];
|
||||
|
||||
public function createCachePool($defaultLifetime = 0)
|
||||
{
|
||||
if (!\function_exists('apcu_fetch') || !filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN)) {
|
||||
$this->markTestSkipped('APCu extension is required.');
|
||||
}
|
||||
if ('cli' === \PHP_SAPI && !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN)) {
|
||||
if ('testWithCliSapi' !== $this->getName()) {
|
||||
$this->markTestSkipped('apc.enable_cli=1 is required.');
|
||||
}
|
||||
}
|
||||
if ('\\' === \DIRECTORY_SEPARATOR) {
|
||||
$this->markTestSkipped('Fails transiently on Windows.');
|
||||
}
|
||||
|
||||
return new ApcuAdapter(str_replace('\\', '.', __CLASS__), $defaultLifetime);
|
||||
}
|
||||
|
||||
public function testUnserializable()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
|
||||
$item = $pool->getItem('foo');
|
||||
$item->set(function () {});
|
||||
|
||||
$this->assertFalse($pool->save($item));
|
||||
|
||||
$item = $pool->getItem('foo');
|
||||
$this->assertFalse($item->isHit());
|
||||
}
|
||||
|
||||
public function testVersion()
|
||||
{
|
||||
$namespace = str_replace('\\', '.', \get_class($this));
|
||||
|
||||
$pool1 = new ApcuAdapter($namespace, 0, 'p1');
|
||||
|
||||
$item = $pool1->getItem('foo');
|
||||
$this->assertFalse($item->isHit());
|
||||
$this->assertTrue($pool1->save($item->set('bar')));
|
||||
|
||||
$item = $pool1->getItem('foo');
|
||||
$this->assertTrue($item->isHit());
|
||||
$this->assertSame('bar', $item->get());
|
||||
|
||||
$pool2 = new ApcuAdapter($namespace, 0, 'p2');
|
||||
|
||||
$item = $pool2->getItem('foo');
|
||||
$this->assertFalse($item->isHit());
|
||||
$this->assertNull($item->get());
|
||||
|
||||
$item = $pool1->getItem('foo');
|
||||
$this->assertFalse($item->isHit());
|
||||
$this->assertNull($item->get());
|
||||
}
|
||||
|
||||
public function testNamespace()
|
||||
{
|
||||
$namespace = str_replace('\\', '.', \get_class($this));
|
||||
|
||||
$pool1 = new ApcuAdapter($namespace.'_1', 0, 'p1');
|
||||
|
||||
$item = $pool1->getItem('foo');
|
||||
$this->assertFalse($item->isHit());
|
||||
$this->assertTrue($pool1->save($item->set('bar')));
|
||||
|
||||
$item = $pool1->getItem('foo');
|
||||
$this->assertTrue($item->isHit());
|
||||
$this->assertSame('bar', $item->get());
|
||||
|
||||
$pool2 = new ApcuAdapter($namespace.'_2', 0, 'p1');
|
||||
|
||||
$item = $pool2->getItem('foo');
|
||||
$this->assertFalse($item->isHit());
|
||||
$this->assertNull($item->get());
|
||||
|
||||
$item = $pool1->getItem('foo');
|
||||
$this->assertTrue($item->isHit());
|
||||
$this->assertSame('bar', $item->get());
|
||||
}
|
||||
|
||||
public function testWithCliSapi()
|
||||
{
|
||||
try {
|
||||
// disable PHPUnit error handler to mimic a production environment
|
||||
$isCalled = false;
|
||||
set_error_handler(function () use (&$isCalled) {
|
||||
$isCalled = true;
|
||||
});
|
||||
$pool = new ApcuAdapter(str_replace('\\', '.', __CLASS__));
|
||||
$pool->setLogger(new NullLogger());
|
||||
|
||||
$item = $pool->getItem('foo');
|
||||
$item->isHit();
|
||||
$pool->save($item->set('bar'));
|
||||
$this->assertFalse($isCalled);
|
||||
} finally {
|
||||
restore_error_handler();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
<?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 Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class ArrayAdapterTest extends AdapterTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testDeferredSaveWithoutCommit' => 'Assumes a shared cache which ArrayAdapter is not.',
|
||||
'testSaveWithoutExpire' => 'Assumes a shared cache which ArrayAdapter is not.',
|
||||
];
|
||||
|
||||
public function createCachePool($defaultLifetime = 0)
|
||||
{
|
||||
return new ArrayAdapter($defaultLifetime);
|
||||
}
|
||||
|
||||
public function testGetValuesHitAndMiss()
|
||||
{
|
||||
/** @var ArrayAdapter $cache */
|
||||
$cache = $this->createCachePool();
|
||||
|
||||
// Hit
|
||||
$item = $cache->getItem('foo');
|
||||
$item->set('4711');
|
||||
$cache->save($item);
|
||||
|
||||
$fooItem = $cache->getItem('foo');
|
||||
$this->assertTrue($fooItem->isHit());
|
||||
$this->assertEquals('4711', $fooItem->get());
|
||||
|
||||
// Miss (should be present as NULL in $values)
|
||||
$cache->getItem('bar');
|
||||
|
||||
$values = $cache->getValues();
|
||||
|
||||
$this->assertCount(2, $values);
|
||||
$this->assertArrayHasKey('foo', $values);
|
||||
$this->assertSame(serialize('4711'), $values['foo']);
|
||||
$this->assertArrayHasKey('bar', $values);
|
||||
$this->assertNull($values['bar']);
|
||||
}
|
||||
}
|
||||
115
lib/symfony/cache/Tests/Adapter/ChainAdapterTest.php
vendored
115
lib/symfony/cache/Tests/Adapter/ChainAdapterTest.php
vendored
@@ -1,115 +0,0 @@
|
||||
<?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\MockObject\MockObject;
|
||||
use Symfony\Component\Cache\Adapter\AdapterInterface;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Component\Cache\Adapter\ChainAdapter;
|
||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||
use Symfony\Component\Cache\PruneableInterface;
|
||||
use Symfony\Component\Cache\Tests\Fixtures\ExternalAdapter;
|
||||
|
||||
/**
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class ChainAdapterTest extends AdapterTestCase
|
||||
{
|
||||
public function createCachePool($defaultLifetime = 0)
|
||||
{
|
||||
return new ChainAdapter([new ArrayAdapter($defaultLifetime), new ExternalAdapter(), new FilesystemAdapter('', $defaultLifetime)], $defaultLifetime);
|
||||
}
|
||||
|
||||
public function testEmptyAdaptersException()
|
||||
{
|
||||
$this->expectException('Symfony\Component\Cache\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('At least one adapter must be specified.');
|
||||
new ChainAdapter([]);
|
||||
}
|
||||
|
||||
public function testInvalidAdapterException()
|
||||
{
|
||||
$this->expectException('Symfony\Component\Cache\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('The class "stdClass" does not implement');
|
||||
new ChainAdapter([new \stdClass()]);
|
||||
}
|
||||
|
||||
public function testPrune()
|
||||
{
|
||||
if (isset($this->skippedTests[__FUNCTION__])) {
|
||||
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
|
||||
}
|
||||
|
||||
$cache = new ChainAdapter([
|
||||
$this->getPruneableMock(),
|
||||
$this->getNonPruneableMock(),
|
||||
$this->getPruneableMock(),
|
||||
]);
|
||||
$this->assertTrue($cache->prune());
|
||||
|
||||
$cache = new ChainAdapter([
|
||||
$this->getPruneableMock(),
|
||||
$this->getFailingPruneableMock(),
|
||||
$this->getPruneableMock(),
|
||||
]);
|
||||
$this->assertFalse($cache->prune());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MockObject|PruneableCacheInterface
|
||||
*/
|
||||
private function getPruneableMock()
|
||||
{
|
||||
$pruneable = $this
|
||||
->getMockBuilder(PruneableCacheInterface::class)
|
||||
->getMock();
|
||||
|
||||
$pruneable
|
||||
->expects($this->atLeastOnce())
|
||||
->method('prune')
|
||||
->willReturn(true);
|
||||
|
||||
return $pruneable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MockObject|PruneableCacheInterface
|
||||
*/
|
||||
private function getFailingPruneableMock()
|
||||
{
|
||||
$pruneable = $this
|
||||
->getMockBuilder(PruneableCacheInterface::class)
|
||||
->getMock();
|
||||
|
||||
$pruneable
|
||||
->expects($this->atLeastOnce())
|
||||
->method('prune')
|
||||
->willReturn(false);
|
||||
|
||||
return $pruneable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MockObject|AdapterInterface
|
||||
*/
|
||||
private function getNonPruneableMock()
|
||||
{
|
||||
return $this
|
||||
->getMockBuilder(AdapterInterface::class)
|
||||
->getMock();
|
||||
}
|
||||
}
|
||||
|
||||
interface PruneableCacheInterface extends PruneableInterface, AdapterInterface
|
||||
{
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
<?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 Symfony\Component\Cache\Adapter\DoctrineAdapter;
|
||||
use Symfony\Component\Cache\Tests\Fixtures\ArrayCache;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class DoctrineAdapterTest extends AdapterTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testDeferredSaveWithoutCommit' => 'Assumes a shared cache which ArrayCache is not.',
|
||||
'testSaveWithoutExpire' => 'Assumes a shared cache which ArrayCache is not.',
|
||||
'testNotUnserializable' => 'ArrayCache does not use serialize/unserialize',
|
||||
];
|
||||
|
||||
public function createCachePool($defaultLifetime = 0)
|
||||
{
|
||||
return new DoctrineAdapter(new ArrayCache($defaultLifetime), '', $defaultLifetime);
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
<?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 Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class FilesystemAdapterTest extends AdapterTestCase
|
||||
{
|
||||
public function createCachePool($defaultLifetime = 0)
|
||||
{
|
||||
return new FilesystemAdapter('', $defaultLifetime);
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
self::rmdir(sys_get_temp_dir().'/symfony-cache');
|
||||
}
|
||||
|
||||
public static function rmdir($dir)
|
||||
{
|
||||
if (!file_exists($dir)) {
|
||||
return;
|
||||
}
|
||||
if (!$dir || 0 !== strpos(\dirname($dir), sys_get_temp_dir())) {
|
||||
throw new \Exception(__METHOD__."() operates only on subdirs of system's temp dir");
|
||||
}
|
||||
$children = new \RecursiveIteratorIterator(
|
||||
new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS),
|
||||
\RecursiveIteratorIterator::CHILD_FIRST
|
||||
);
|
||||
foreach ($children as $child) {
|
||||
if ($child->isDir()) {
|
||||
rmdir($child);
|
||||
} else {
|
||||
unlink($child);
|
||||
}
|
||||
}
|
||||
rmdir($dir);
|
||||
}
|
||||
|
||||
protected function isPruned(CacheItemPoolInterface $cache, $name)
|
||||
{
|
||||
$getFileMethod = (new \ReflectionObject($cache))->getMethod('getFile');
|
||||
$getFileMethod->setAccessible(true);
|
||||
|
||||
return !file_exists($getFileMethod->invoke($cache, $name));
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
<?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\TestCase;
|
||||
use Symfony\Component\Cache\Adapter\AbstractAdapter;
|
||||
|
||||
class MaxIdLengthAdapterTest extends TestCase
|
||||
{
|
||||
public function testLongKey()
|
||||
{
|
||||
$cache = $this->getMockBuilder(MaxIdLengthAdapter::class)
|
||||
->setConstructorArgs([str_repeat('-', 10)])
|
||||
->setMethods(['doHave', 'doFetch', 'doDelete', 'doSave', 'doClear'])
|
||||
->getMock();
|
||||
|
||||
$cache->expects($this->exactly(2))
|
||||
->method('doHave')
|
||||
->withConsecutive(
|
||||
[$this->equalTo('----------:0GTYWa9n4ed8vqNlOT2iEr:')],
|
||||
[$this->equalTo('----------:---------------------------------------')]
|
||||
);
|
||||
|
||||
$cache->hasItem(str_repeat('-', 40));
|
||||
$cache->hasItem(str_repeat('-', 39));
|
||||
}
|
||||
|
||||
public function testLongKeyVersioning()
|
||||
{
|
||||
$cache = $this->getMockBuilder(MaxIdLengthAdapter::class)
|
||||
->setConstructorArgs([str_repeat('-', 26)])
|
||||
->getMock();
|
||||
|
||||
$cache
|
||||
->method('doFetch')
|
||||
->willReturn(['2:']);
|
||||
|
||||
$reflectionClass = new \ReflectionClass(AbstractAdapter::class);
|
||||
|
||||
$reflectionMethod = $reflectionClass->getMethod('getId');
|
||||
$reflectionMethod->setAccessible(true);
|
||||
|
||||
// No versioning enabled
|
||||
$this->assertEquals('--------------------------:------------', $reflectionMethod->invokeArgs($cache, [str_repeat('-', 12)]));
|
||||
$this->assertLessThanOrEqual(50, \strlen($reflectionMethod->invokeArgs($cache, [str_repeat('-', 12)])));
|
||||
$this->assertLessThanOrEqual(50, \strlen($reflectionMethod->invokeArgs($cache, [str_repeat('-', 23)])));
|
||||
$this->assertLessThanOrEqual(50, \strlen($reflectionMethod->invokeArgs($cache, [str_repeat('-', 40)])));
|
||||
|
||||
$reflectionProperty = $reflectionClass->getProperty('versioningIsEnabled');
|
||||
$reflectionProperty->setAccessible(true);
|
||||
$reflectionProperty->setValue($cache, true);
|
||||
|
||||
// Versioning enabled
|
||||
$this->assertEquals('--------------------------:2:------------', $reflectionMethod->invokeArgs($cache, [str_repeat('-', 12)]));
|
||||
$this->assertLessThanOrEqual(50, \strlen($reflectionMethod->invokeArgs($cache, [str_repeat('-', 12)])));
|
||||
$this->assertLessThanOrEqual(50, \strlen($reflectionMethod->invokeArgs($cache, [str_repeat('-', 23)])));
|
||||
$this->assertLessThanOrEqual(50, \strlen($reflectionMethod->invokeArgs($cache, [str_repeat('-', 40)])));
|
||||
}
|
||||
|
||||
public function testTooLongNamespace()
|
||||
{
|
||||
$this->expectException('Symfony\Component\Cache\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Namespace must be 26 chars max, 40 given ("----------------------------------------")');
|
||||
$this->getMockBuilder(MaxIdLengthAdapter::class)
|
||||
->setConstructorArgs([str_repeat('-', 40)])
|
||||
->getMock();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class MaxIdLengthAdapter extends AbstractAdapter
|
||||
{
|
||||
protected $maxIdLength = 50;
|
||||
|
||||
public function __construct($ns)
|
||||
{
|
||||
parent::__construct($ns);
|
||||
}
|
||||
}
|
||||
@@ -1,198 +0,0 @@
|
||||
<?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 Symfony\Component\Cache\Adapter\AbstractAdapter;
|
||||
use Symfony\Component\Cache\Adapter\MemcachedAdapter;
|
||||
|
||||
class MemcachedAdapterTest extends AdapterTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testHasItemReturnsFalseWhenDeferredItemIsExpired' => 'Testing expiration slows down the test suite',
|
||||
'testDefaultLifeTime' => 'Testing expiration slows down the test suite',
|
||||
];
|
||||
|
||||
protected static $client;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
if (!MemcachedAdapter::isSupported()) {
|
||||
self::markTestSkipped('Extension memcached >=2.2.0 required.');
|
||||
}
|
||||
self::$client = AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'), ['binary_protocol' => false]);
|
||||
self::$client->get('foo');
|
||||
$code = self::$client->getResultCode();
|
||||
|
||||
if (\Memcached::RES_SUCCESS !== $code && \Memcached::RES_NOTFOUND !== $code) {
|
||||
self::markTestSkipped('Memcached error: '.strtolower(self::$client->getResultMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
public function createCachePool($defaultLifetime = 0)
|
||||
{
|
||||
$client = $defaultLifetime ? AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST')) : self::$client;
|
||||
|
||||
return new MemcachedAdapter($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
|
||||
}
|
||||
|
||||
public function testOptions()
|
||||
{
|
||||
$client = MemcachedAdapter::createConnection([], [
|
||||
'libketama_compatible' => false,
|
||||
'distribution' => 'modula',
|
||||
'compression' => true,
|
||||
'serializer' => 'php',
|
||||
'hash' => 'md5',
|
||||
]);
|
||||
|
||||
$this->assertSame(\Memcached::SERIALIZER_PHP, $client->getOption(\Memcached::OPT_SERIALIZER));
|
||||
$this->assertSame(\Memcached::HASH_MD5, $client->getOption(\Memcached::OPT_HASH));
|
||||
$this->assertTrue($client->getOption(\Memcached::OPT_COMPRESSION));
|
||||
$this->assertSame(0, $client->getOption(\Memcached::OPT_LIBKETAMA_COMPATIBLE));
|
||||
$this->assertSame(\Memcached::DISTRIBUTION_MODULA, $client->getOption(\Memcached::OPT_DISTRIBUTION));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideBadOptions
|
||||
*/
|
||||
public function testBadOptions($name, $value)
|
||||
{
|
||||
$this->expectException('ErrorException');
|
||||
$this->expectExceptionMessage('constant(): Couldn\'t find constant Memcached::');
|
||||
MemcachedAdapter::createConnection([], [$name => $value]);
|
||||
}
|
||||
|
||||
public function provideBadOptions()
|
||||
{
|
||||
return [
|
||||
['foo', 'bar'],
|
||||
['hash', 'zyx'],
|
||||
['serializer', 'zyx'],
|
||||
['distribution', 'zyx'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testDefaultOptions()
|
||||
{
|
||||
$this->assertTrue(MemcachedAdapter::isSupported());
|
||||
|
||||
$client = MemcachedAdapter::createConnection([]);
|
||||
|
||||
$this->assertTrue($client->getOption(\Memcached::OPT_COMPRESSION));
|
||||
$this->assertSame(1, $client->getOption(\Memcached::OPT_BINARY_PROTOCOL));
|
||||
$this->assertSame(1, $client->getOption(\Memcached::OPT_TCP_NODELAY));
|
||||
$this->assertSame(1, $client->getOption(\Memcached::OPT_LIBKETAMA_COMPATIBLE));
|
||||
}
|
||||
|
||||
public function testOptionSerializer()
|
||||
{
|
||||
$this->expectException('Symfony\Component\Cache\Exception\CacheException');
|
||||
$this->expectExceptionMessage('MemcachedAdapter: "serializer" option must be "php" or "igbinary".');
|
||||
if (!\Memcached::HAVE_JSON) {
|
||||
$this->markTestSkipped('Memcached::HAVE_JSON required');
|
||||
}
|
||||
|
||||
new MemcachedAdapter(MemcachedAdapter::createConnection([], ['serializer' => 'json']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideServersSetting
|
||||
*/
|
||||
public function testServersSetting($dsn, $host, $port)
|
||||
{
|
||||
$client1 = MemcachedAdapter::createConnection($dsn);
|
||||
$client2 = MemcachedAdapter::createConnection([$dsn]);
|
||||
$client3 = MemcachedAdapter::createConnection([[$host, $port]]);
|
||||
$expect = [
|
||||
'host' => $host,
|
||||
'port' => $port,
|
||||
];
|
||||
|
||||
$f = function ($s) { return ['host' => $s['host'], 'port' => $s['port']]; };
|
||||
$this->assertSame([$expect], array_map($f, $client1->getServerList()));
|
||||
$this->assertSame([$expect], array_map($f, $client2->getServerList()));
|
||||
$this->assertSame([$expect], array_map($f, $client3->getServerList()));
|
||||
}
|
||||
|
||||
public function provideServersSetting()
|
||||
{
|
||||
yield [
|
||||
'memcached://127.0.0.1/50',
|
||||
'127.0.0.1',
|
||||
11211,
|
||||
];
|
||||
yield [
|
||||
'memcached://localhost:11222?weight=25',
|
||||
'localhost',
|
||||
11222,
|
||||
];
|
||||
if (filter_var(ini_get('memcached.use_sasl'), FILTER_VALIDATE_BOOLEAN)) {
|
||||
yield [
|
||||
'memcached://user:password@127.0.0.1?weight=50',
|
||||
'127.0.0.1',
|
||||
11211,
|
||||
];
|
||||
}
|
||||
yield [
|
||||
'memcached:///var/run/memcached.sock?weight=25',
|
||||
'/var/run/memcached.sock',
|
||||
0,
|
||||
];
|
||||
yield [
|
||||
'memcached:///var/local/run/memcached.socket?weight=25',
|
||||
'/var/local/run/memcached.socket',
|
||||
0,
|
||||
];
|
||||
if (filter_var(ini_get('memcached.use_sasl'), FILTER_VALIDATE_BOOLEAN)) {
|
||||
yield [
|
||||
'memcached://user:password@/var/local/run/memcached.socket?weight=25',
|
||||
'/var/local/run/memcached.socket',
|
||||
0,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDsnWithOptions
|
||||
*/
|
||||
public function testDsnWithOptions($dsn, array $options, array $expectedOptions)
|
||||
{
|
||||
$client = MemcachedAdapter::createConnection($dsn, $options);
|
||||
|
||||
foreach ($expectedOptions as $option => $expect) {
|
||||
$this->assertSame($expect, $client->getOption($option));
|
||||
}
|
||||
}
|
||||
|
||||
public function provideDsnWithOptions()
|
||||
{
|
||||
if (!class_exists('\Memcached')) {
|
||||
self::markTestSkipped('Extension memcached required.');
|
||||
}
|
||||
|
||||
yield [
|
||||
'memcached://localhost:11222?retry_timeout=10',
|
||||
[\Memcached::OPT_RETRY_TIMEOUT => 8],
|
||||
[\Memcached::OPT_RETRY_TIMEOUT => 10],
|
||||
];
|
||||
yield [
|
||||
'memcached://localhost:11222?socket_recv_size=1&socket_send_size=2',
|
||||
[\Memcached::OPT_RETRY_TIMEOUT => 8],
|
||||
[\Memcached::OPT_SOCKET_RECV_SIZE => 1, \Memcached::OPT_SOCKET_SEND_SIZE => 2, \Memcached::OPT_RETRY_TIMEOUT => 8],
|
||||
];
|
||||
}
|
||||
|
||||
public function testClear()
|
||||
{
|
||||
$this->assertTrue($this->createCachePool()->clear());
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?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 Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Component\Cache\Adapter\ProxyAdapter;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class NamespacedProxyAdapterTest extends ProxyAdapterTest
|
||||
{
|
||||
public function createCachePool($defaultLifetime = 0)
|
||||
{
|
||||
return new ProxyAdapter(new ArrayAdapter($defaultLifetime), 'foo', $defaultLifetime);
|
||||
}
|
||||
}
|
||||
128
lib/symfony/cache/Tests/Adapter/NullAdapterTest.php
vendored
128
lib/symfony/cache/Tests/Adapter/NullAdapterTest.php
vendored
@@ -1,128 +0,0 @@
|
||||
<?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\TestCase;
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
use Symfony\Component\Cache\Adapter\NullAdapter;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class NullAdapterTest extends TestCase
|
||||
{
|
||||
public function createCachePool()
|
||||
{
|
||||
return new NullAdapter();
|
||||
}
|
||||
|
||||
public function testGetItem()
|
||||
{
|
||||
$adapter = $this->createCachePool();
|
||||
|
||||
$item = $adapter->getItem('key');
|
||||
$this->assertFalse($item->isHit());
|
||||
$this->assertNull($item->get(), "Item's value must be null when isHit is false.");
|
||||
}
|
||||
|
||||
public function testHasItem()
|
||||
{
|
||||
$this->assertFalse($this->createCachePool()->hasItem('key'));
|
||||
}
|
||||
|
||||
public function testGetItems()
|
||||
{
|
||||
$adapter = $this->createCachePool();
|
||||
|
||||
$keys = ['foo', 'bar', 'baz', 'biz'];
|
||||
|
||||
/** @var CacheItemInterface[] $items */
|
||||
$items = $adapter->getItems($keys);
|
||||
$count = 0;
|
||||
|
||||
foreach ($items as $key => $item) {
|
||||
$itemKey = $item->getKey();
|
||||
|
||||
$this->assertEquals($itemKey, $key, 'Keys must be preserved when fetching multiple items');
|
||||
$this->assertContains($key, $keys, 'Cache key can not change.');
|
||||
$this->assertFalse($item->isHit());
|
||||
|
||||
// Remove $key for $keys
|
||||
foreach ($keys as $k => $v) {
|
||||
if ($v === $key) {
|
||||
unset($keys[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
++$count;
|
||||
}
|
||||
|
||||
$this->assertSame(4, $count);
|
||||
}
|
||||
|
||||
public function testIsHit()
|
||||
{
|
||||
$adapter = $this->createCachePool();
|
||||
|
||||
$item = $adapter->getItem('key');
|
||||
$this->assertFalse($item->isHit());
|
||||
}
|
||||
|
||||
public function testClear()
|
||||
{
|
||||
$this->assertTrue($this->createCachePool()->clear());
|
||||
}
|
||||
|
||||
public function testDeleteItem()
|
||||
{
|
||||
$this->assertTrue($this->createCachePool()->deleteItem('key'));
|
||||
}
|
||||
|
||||
public function testDeleteItems()
|
||||
{
|
||||
$this->assertTrue($this->createCachePool()->deleteItems(['key', 'foo', 'bar']));
|
||||
}
|
||||
|
||||
public function testSave()
|
||||
{
|
||||
$adapter = $this->createCachePool();
|
||||
|
||||
$item = $adapter->getItem('key');
|
||||
$this->assertFalse($item->isHit());
|
||||
$this->assertNull($item->get(), "Item's value must be null when isHit is false.");
|
||||
|
||||
$this->assertFalse($adapter->save($item));
|
||||
}
|
||||
|
||||
public function testDeferredSave()
|
||||
{
|
||||
$adapter = $this->createCachePool();
|
||||
|
||||
$item = $adapter->getItem('key');
|
||||
$this->assertFalse($item->isHit());
|
||||
$this->assertNull($item->get(), "Item's value must be null when isHit is false.");
|
||||
|
||||
$this->assertFalse($adapter->saveDeferred($item));
|
||||
}
|
||||
|
||||
public function testCommit()
|
||||
{
|
||||
$adapter = $this->createCachePool();
|
||||
|
||||
$item = $adapter->getItem('key');
|
||||
$this->assertFalse($item->isHit());
|
||||
$this->assertNull($item->get(), "Item's value must be null when isHit is false.");
|
||||
|
||||
$this->assertFalse($adapter->saveDeferred($item));
|
||||
$this->assertFalse($this->createCachePool()->commit());
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
<?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 Symfony\Component\Cache\Adapter\PdoAdapter;
|
||||
use Symfony\Component\Cache\Tests\Traits\PdoPruneableTrait;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class PdoAdapterTest extends AdapterTestCase
|
||||
{
|
||||
use PdoPruneableTrait;
|
||||
|
||||
protected static $dbFile;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
if (!\extension_loaded('pdo_sqlite')) {
|
||||
self::markTestSkipped('Extension pdo_sqlite required.');
|
||||
}
|
||||
|
||||
self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache');
|
||||
|
||||
$pool = new PdoAdapter('sqlite:'.self::$dbFile);
|
||||
$pool->createTable();
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
@unlink(self::$dbFile);
|
||||
}
|
||||
|
||||
public function createCachePool($defaultLifetime = 0)
|
||||
{
|
||||
return new PdoAdapter('sqlite:'.self::$dbFile, 'ns', $defaultLifetime);
|
||||
}
|
||||
|
||||
public function testCleanupExpiredItems()
|
||||
{
|
||||
$pdo = new \PDO('sqlite:'.self::$dbFile);
|
||||
|
||||
$getCacheItemCount = function () use ($pdo) {
|
||||
return (int) $pdo->query('SELECT COUNT(*) FROM cache_items')->fetch(\PDO::FETCH_COLUMN);
|
||||
};
|
||||
|
||||
$this->assertSame(0, $getCacheItemCount());
|
||||
|
||||
$cache = $this->createCachePool();
|
||||
|
||||
$item = $cache->getItem('some_nice_key');
|
||||
$item->expiresAfter(1);
|
||||
$item->set(1);
|
||||
|
||||
$cache->save($item);
|
||||
$this->assertSame(1, $getCacheItemCount());
|
||||
|
||||
sleep(2);
|
||||
|
||||
$newItem = $cache->getItem($item->getKey());
|
||||
$this->assertFalse($newItem->isHit());
|
||||
$this->assertSame(0, $getCacheItemCount(), 'PDOAdapter must clean up expired items');
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
<?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 Doctrine\DBAL\DriverManager;
|
||||
use Symfony\Component\Cache\Adapter\PdoAdapter;
|
||||
use Symfony\Component\Cache\Tests\Traits\PdoPruneableTrait;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class PdoDbalAdapterTest extends AdapterTestCase
|
||||
{
|
||||
use PdoPruneableTrait;
|
||||
|
||||
protected static $dbFile;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
if (!\extension_loaded('pdo_sqlite')) {
|
||||
self::markTestSkipped('Extension pdo_sqlite required.');
|
||||
}
|
||||
|
||||
self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache');
|
||||
|
||||
$pool = new PdoAdapter(DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile]));
|
||||
$pool->createTable();
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
@unlink(self::$dbFile);
|
||||
}
|
||||
|
||||
public function createCachePool($defaultLifetime = 0)
|
||||
{
|
||||
return new PdoAdapter(DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile]), '', $defaultLifetime);
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
<?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 Psr\Cache\CacheItemInterface;
|
||||
use Symfony\Component\Cache\Adapter\NullAdapter;
|
||||
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class PhpArrayAdapterTest extends AdapterTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testBasicUsage' => 'PhpArrayAdapter is read-only.',
|
||||
'testBasicUsageWithLongKey' => 'PhpArrayAdapter is read-only.',
|
||||
'testClear' => 'PhpArrayAdapter is read-only.',
|
||||
'testClearWithDeferredItems' => 'PhpArrayAdapter is read-only.',
|
||||
'testDeleteItem' => 'PhpArrayAdapter is read-only.',
|
||||
'testSaveExpired' => 'PhpArrayAdapter is read-only.',
|
||||
'testSaveWithoutExpire' => 'PhpArrayAdapter is read-only.',
|
||||
'testDeferredSave' => 'PhpArrayAdapter is read-only.',
|
||||
'testDeferredSaveWithoutCommit' => 'PhpArrayAdapter is read-only.',
|
||||
'testDeleteItems' => 'PhpArrayAdapter is read-only.',
|
||||
'testDeleteDeferredItem' => 'PhpArrayAdapter is read-only.',
|
||||
'testCommit' => 'PhpArrayAdapter is read-only.',
|
||||
'testSaveDeferredWhenChangingValues' => 'PhpArrayAdapter is read-only.',
|
||||
'testSaveDeferredOverwrite' => 'PhpArrayAdapter is read-only.',
|
||||
'testIsHitDeferred' => 'PhpArrayAdapter is read-only.',
|
||||
|
||||
'testExpiresAt' => 'PhpArrayAdapter does not support expiration.',
|
||||
'testExpiresAtWithNull' => 'PhpArrayAdapter does not support expiration.',
|
||||
'testExpiresAfterWithNull' => 'PhpArrayAdapter does not support expiration.',
|
||||
'testDeferredExpired' => 'PhpArrayAdapter does not support expiration.',
|
||||
'testExpiration' => 'PhpArrayAdapter does not support expiration.',
|
||||
|
||||
'testGetItemInvalidKeys' => 'PhpArrayAdapter does not throw exceptions on invalid key.',
|
||||
'testGetItemsInvalidKeys' => 'PhpArrayAdapter does not throw exceptions on invalid key.',
|
||||
'testHasItemInvalidKeys' => 'PhpArrayAdapter does not throw exceptions on invalid key.',
|
||||
'testDeleteItemInvalidKeys' => 'PhpArrayAdapter does not throw exceptions on invalid key.',
|
||||
'testDeleteItemsInvalidKeys' => 'PhpArrayAdapter does not throw exceptions on invalid key.',
|
||||
|
||||
'testDefaultLifeTime' => 'PhpArrayAdapter does not allow configuring a default lifetime.',
|
||||
'testPrune' => 'PhpArrayAdapter just proxies',
|
||||
];
|
||||
|
||||
protected static $file;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$file = sys_get_temp_dir().'/symfony-cache/php-array-adapter-test.php';
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
if (file_exists(sys_get_temp_dir().'/symfony-cache')) {
|
||||
FilesystemAdapterTest::rmdir(sys_get_temp_dir().'/symfony-cache');
|
||||
}
|
||||
}
|
||||
|
||||
public function createCachePool()
|
||||
{
|
||||
return new PhpArrayAdapterWrapper(self::$file, new NullAdapter());
|
||||
}
|
||||
|
||||
public function testStore()
|
||||
{
|
||||
$arrayWithRefs = [];
|
||||
$arrayWithRefs[0] = 123;
|
||||
$arrayWithRefs[1] = &$arrayWithRefs[0];
|
||||
|
||||
$object = (object) [
|
||||
'foo' => 'bar',
|
||||
'foo2' => 'bar2',
|
||||
];
|
||||
|
||||
$expected = [
|
||||
'null' => null,
|
||||
'serializedString' => serialize($object),
|
||||
'arrayWithRefs' => $arrayWithRefs,
|
||||
'object' => $object,
|
||||
'arrayWithObject' => ['bar' => $object],
|
||||
];
|
||||
|
||||
$adapter = $this->createCachePool();
|
||||
$adapter->warmUp($expected);
|
||||
|
||||
foreach ($expected as $key => $value) {
|
||||
$this->assertSame(serialize($value), serialize($adapter->getItem($key)->get()), 'Warm up should create a PHP file that OPCache can load in memory');
|
||||
}
|
||||
}
|
||||
|
||||
public function testStoredFile()
|
||||
{
|
||||
$expected = [
|
||||
'integer' => 42,
|
||||
'float' => 42.42,
|
||||
'boolean' => true,
|
||||
'array_simple' => ['foo', 'bar'],
|
||||
'array_associative' => ['foo' => 'bar', 'foo2' => 'bar2'],
|
||||
];
|
||||
|
||||
$adapter = $this->createCachePool();
|
||||
$adapter->warmUp($expected);
|
||||
|
||||
$values = eval(substr(file_get_contents(self::$file), 6));
|
||||
|
||||
$this->assertSame($expected, $values, 'Warm up should create a PHP file that OPCache can load in memory');
|
||||
}
|
||||
}
|
||||
|
||||
class PhpArrayAdapterWrapper extends PhpArrayAdapter
|
||||
{
|
||||
public function save(CacheItemInterface $item)
|
||||
{
|
||||
\call_user_func(\Closure::bind(function () use ($item) {
|
||||
$this->values[$item->getKey()] = $item->get();
|
||||
$this->warmUp($this->values);
|
||||
$this->values = eval(substr(file_get_contents($this->file), 6));
|
||||
}, $this, PhpArrayAdapter::class));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?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 Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class PhpArrayAdapterWithFallbackTest extends AdapterTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testGetItemInvalidKeys' => 'PhpArrayAdapter does not throw exceptions on invalid key.',
|
||||
'testGetItemsInvalidKeys' => 'PhpArrayAdapter does not throw exceptions on invalid key.',
|
||||
'testHasItemInvalidKeys' => 'PhpArrayAdapter does not throw exceptions on invalid key.',
|
||||
'testDeleteItemInvalidKeys' => 'PhpArrayAdapter does not throw exceptions on invalid key.',
|
||||
'testDeleteItemsInvalidKeys' => 'PhpArrayAdapter does not throw exceptions on invalid key.',
|
||||
'testPrune' => 'PhpArrayAdapter just proxies',
|
||||
];
|
||||
|
||||
protected static $file;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$file = sys_get_temp_dir().'/symfony-cache/php-array-adapter-test.php';
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
if (file_exists(sys_get_temp_dir().'/symfony-cache')) {
|
||||
FilesystemAdapterTest::rmdir(sys_get_temp_dir().'/symfony-cache');
|
||||
}
|
||||
}
|
||||
|
||||
public function createCachePool($defaultLifetime = 0)
|
||||
{
|
||||
return new PhpArrayAdapter(self::$file, new FilesystemAdapter('php-array-fallback', $defaultLifetime));
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
<?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 Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class PhpFilesAdapterTest extends AdapterTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testDefaultLifeTime' => 'PhpFilesAdapter does not allow configuring a default lifetime.',
|
||||
];
|
||||
|
||||
public function createCachePool()
|
||||
{
|
||||
if (!PhpFilesAdapter::isSupported()) {
|
||||
$this->markTestSkipped('OPcache extension is not enabled.');
|
||||
}
|
||||
|
||||
return new PhpFilesAdapter('sf-cache');
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
FilesystemAdapterTest::rmdir(sys_get_temp_dir().'/symfony-cache');
|
||||
}
|
||||
|
||||
protected function isPruned(CacheItemPoolInterface $cache, $name)
|
||||
{
|
||||
$getFileMethod = (new \ReflectionObject($cache))->getMethod('getFile');
|
||||
$getFileMethod->setAccessible(true);
|
||||
|
||||
return !file_exists($getFileMethod->invoke($cache, $name));
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
<?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 Predis\Connection\StreamConnection;
|
||||
use Symfony\Component\Cache\Adapter\RedisAdapter;
|
||||
|
||||
class PredisAdapterTest extends AbstractRedisAdapterTest
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
self::$redis = new \Predis\Client(['host' => getenv('REDIS_HOST')]);
|
||||
}
|
||||
|
||||
public function testCreateConnection()
|
||||
{
|
||||
$redisHost = getenv('REDIS_HOST');
|
||||
|
||||
$redis = RedisAdapter::createConnection('redis://'.$redisHost.'/1', ['class' => \Predis\Client::class, 'timeout' => 3]);
|
||||
$this->assertInstanceOf(\Predis\Client::class, $redis);
|
||||
|
||||
$connection = $redis->getConnection();
|
||||
$this->assertInstanceOf(StreamConnection::class, $connection);
|
||||
|
||||
$params = [
|
||||
'scheme' => 'tcp',
|
||||
'host' => $redisHost,
|
||||
'path' => '',
|
||||
'dbindex' => '1',
|
||||
'port' => 6379,
|
||||
'class' => 'Predis\Client',
|
||||
'timeout' => 3,
|
||||
'persistent' => 0,
|
||||
'persistent_id' => null,
|
||||
'read_timeout' => 0,
|
||||
'retry_interval' => 0,
|
||||
'lazy' => false,
|
||||
'database' => '1',
|
||||
'password' => null,
|
||||
];
|
||||
$this->assertSame($params, $connection->getParameters()->toArray());
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?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;
|
||||
|
||||
class PredisClusterAdapterTest extends AbstractRedisAdapterTest
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
self::$redis = new \Predis\Client([['host' => getenv('REDIS_HOST')]]);
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
self::$redis = null;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<?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;
|
||||
|
||||
class PredisRedisClusterAdapterTest extends AbstractRedisAdapterTest
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
if (!$hosts = getenv('REDIS_CLUSTER_HOSTS')) {
|
||||
self::markTestSkipped('REDIS_CLUSTER_HOSTS env var is not defined.');
|
||||
}
|
||||
self::$redis = new \Predis\Client(explode(' ', $hosts), ['cluster' => 'redis']);
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
self::$redis = null;
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
<?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 Psr\Cache\CacheItemInterface;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Component\Cache\Adapter\ProxyAdapter;
|
||||
use Symfony\Component\Cache\CacheItem;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class ProxyAdapterTest extends AdapterTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testDeferredSaveWithoutCommit' => 'Assumes a shared cache which ArrayAdapter is not.',
|
||||
'testSaveWithoutExpire' => 'Assumes a shared cache which ArrayAdapter is not.',
|
||||
'testPrune' => 'ProxyAdapter just proxies',
|
||||
];
|
||||
|
||||
public function createCachePool($defaultLifetime = 0)
|
||||
{
|
||||
return new ProxyAdapter(new ArrayAdapter(), '', $defaultLifetime);
|
||||
}
|
||||
|
||||
public function testProxyfiedItem()
|
||||
{
|
||||
$this->expectException('Exception');
|
||||
$this->expectExceptionMessage('OK bar');
|
||||
$item = new CacheItem();
|
||||
$pool = new ProxyAdapter(new TestingArrayAdapter($item));
|
||||
|
||||
$proxyItem = $pool->getItem('foo');
|
||||
|
||||
$this->assertNotSame($item, $proxyItem);
|
||||
$pool->save($proxyItem->set('bar'));
|
||||
}
|
||||
}
|
||||
|
||||
class TestingArrayAdapter extends ArrayAdapter
|
||||
{
|
||||
private $item;
|
||||
|
||||
public function __construct(CacheItemInterface $item)
|
||||
{
|
||||
$this->item = $item;
|
||||
}
|
||||
|
||||
public function getItem($key)
|
||||
{
|
||||
return $this->item;
|
||||
}
|
||||
|
||||
public function save(CacheItemInterface $item)
|
||||
{
|
||||
if ($item === $this->item) {
|
||||
throw new \Exception('OK '.$item->get());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
<?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 Symfony\Component\Cache\Adapter\AbstractAdapter;
|
||||
use Symfony\Component\Cache\Adapter\RedisAdapter;
|
||||
use Symfony\Component\Cache\Traits\RedisProxy;
|
||||
|
||||
class RedisAdapterTest extends AbstractRedisAdapterTest
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
self::$redis = AbstractAdapter::createConnection('redis://'.getenv('REDIS_HOST'), ['lazy' => true]);
|
||||
}
|
||||
|
||||
public function createCachePool($defaultLifetime = 0)
|
||||
{
|
||||
$adapter = parent::createCachePool($defaultLifetime);
|
||||
$this->assertInstanceOf(RedisProxy::class, self::$redis);
|
||||
|
||||
return $adapter;
|
||||
}
|
||||
|
||||
public function testCreateConnection()
|
||||
{
|
||||
$redisHost = getenv('REDIS_HOST');
|
||||
|
||||
$redis = RedisAdapter::createConnection('redis://'.$redisHost);
|
||||
$this->assertInstanceOf(\Redis::class, $redis);
|
||||
$this->assertTrue($redis->isConnected());
|
||||
$this->assertSame(0, $redis->getDbNum());
|
||||
|
||||
$redis = RedisAdapter::createConnection('redis://'.$redisHost.'/2');
|
||||
$this->assertSame(2, $redis->getDbNum());
|
||||
|
||||
$redis = RedisAdapter::createConnection('redis://'.$redisHost, ['timeout' => 3]);
|
||||
$this->assertEquals(3, $redis->getTimeout());
|
||||
|
||||
$redis = RedisAdapter::createConnection('redis://'.$redisHost.'?timeout=4');
|
||||
$this->assertEquals(4, $redis->getTimeout());
|
||||
|
||||
$redis = RedisAdapter::createConnection('redis://'.$redisHost, ['read_timeout' => 5]);
|
||||
$this->assertEquals(5, $redis->getReadTimeout());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideFailedCreateConnection
|
||||
*/
|
||||
public function testFailedCreateConnection($dsn)
|
||||
{
|
||||
$this->expectException('Symfony\Component\Cache\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Redis connection failed');
|
||||
RedisAdapter::createConnection($dsn);
|
||||
}
|
||||
|
||||
public function provideFailedCreateConnection()
|
||||
{
|
||||
return [
|
||||
['redis://localhost:1234'],
|
||||
['redis://foo@localhost'],
|
||||
['redis://localhost/123'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInvalidCreateConnection
|
||||
*/
|
||||
public function testInvalidCreateConnection($dsn)
|
||||
{
|
||||
$this->expectException('Symfony\Component\Cache\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Invalid Redis DSN');
|
||||
RedisAdapter::createConnection($dsn);
|
||||
}
|
||||
|
||||
public function provideInvalidCreateConnection()
|
||||
{
|
||||
return [
|
||||
['foo://localhost'],
|
||||
['redis://'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
<?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;
|
||||
|
||||
class RedisArrayAdapterTest extends AbstractRedisAdapterTest
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setupBeforeClass();
|
||||
if (!class_exists('RedisArray')) {
|
||||
self::markTestSkipped('The RedisArray class is required.');
|
||||
}
|
||||
self::$redis = new \RedisArray([getenv('REDIS_HOST')], ['lazy_connect' => true]);
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
<?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;
|
||||
|
||||
class RedisClusterAdapterTest extends AbstractRedisAdapterTest
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
if (!class_exists('RedisCluster')) {
|
||||
self::markTestSkipped('The RedisCluster class is required.');
|
||||
}
|
||||
if (!$hosts = getenv('REDIS_CLUSTER_HOSTS')) {
|
||||
self::markTestSkipped('REDIS_CLUSTER_HOSTS env var is not defined.');
|
||||
}
|
||||
|
||||
self::$redis = new \RedisCluster(null, explode(' ', $hosts));
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
<?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 Symfony\Component\Cache\Adapter\SimpleCacheAdapter;
|
||||
use Symfony\Component\Cache\Simple\ArrayCache;
|
||||
use Symfony\Component\Cache\Simple\FilesystemCache;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class SimpleCacheAdapterTest extends AdapterTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testPrune' => 'SimpleCache just proxies',
|
||||
];
|
||||
|
||||
public function createCachePool($defaultLifetime = 0)
|
||||
{
|
||||
return new SimpleCacheAdapter(new FilesystemCache(), '', $defaultLifetime);
|
||||
}
|
||||
|
||||
public function testValidCacheKeyWithNamespace()
|
||||
{
|
||||
$cache = new SimpleCacheAdapter(new ArrayCache(), 'some_namespace', 0);
|
||||
$item = $cache->getItem('my_key');
|
||||
$item->set('someValue');
|
||||
$cache->save($item);
|
||||
|
||||
$this->assertTrue($cache->getItem('my_key')->isHit(), 'Stored item is successfully retrieved.');
|
||||
}
|
||||
}
|
||||
@@ -1,318 +0,0 @@
|
||||
<?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\MockObject\MockObject;
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
use Symfony\Component\Cache\Adapter\AdapterInterface;
|
||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class TagAwareAdapterTest extends AdapterTestCase
|
||||
{
|
||||
public function createCachePool($defaultLifetime = 0)
|
||||
{
|
||||
return new TagAwareAdapter(new FilesystemAdapter('', $defaultLifetime));
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
FilesystemAdapterTest::rmdir(sys_get_temp_dir().'/symfony-cache');
|
||||
}
|
||||
|
||||
public function testInvalidTag()
|
||||
{
|
||||
$this->expectException('Psr\Cache\InvalidArgumentException');
|
||||
$pool = $this->createCachePool();
|
||||
$item = $pool->getItem('foo');
|
||||
$item->tag(':');
|
||||
}
|
||||
|
||||
public function testInvalidateTags()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
|
||||
$i0 = $pool->getItem('i0');
|
||||
$i1 = $pool->getItem('i1');
|
||||
$i2 = $pool->getItem('i2');
|
||||
$i3 = $pool->getItem('i3');
|
||||
$foo = $pool->getItem('foo');
|
||||
|
||||
$pool->save($i0->tag('bar'));
|
||||
$pool->save($i1->tag('foo'));
|
||||
$pool->save($i2->tag('foo')->tag('bar'));
|
||||
$pool->save($i3->tag('foo')->tag('baz'));
|
||||
$pool->save($foo);
|
||||
|
||||
$pool->invalidateTags(['bar']);
|
||||
|
||||
$this->assertFalse($pool->getItem('i0')->isHit());
|
||||
$this->assertTrue($pool->getItem('i1')->isHit());
|
||||
$this->assertFalse($pool->getItem('i2')->isHit());
|
||||
$this->assertTrue($pool->getItem('i3')->isHit());
|
||||
$this->assertTrue($pool->getItem('foo')->isHit());
|
||||
|
||||
$pool->invalidateTags(['foo']);
|
||||
|
||||
$this->assertFalse($pool->getItem('i1')->isHit());
|
||||
$this->assertFalse($pool->getItem('i3')->isHit());
|
||||
$this->assertTrue($pool->getItem('foo')->isHit());
|
||||
|
||||
$anotherPoolInstance = $this->createCachePool();
|
||||
|
||||
$this->assertFalse($anotherPoolInstance->getItem('i1')->isHit());
|
||||
$this->assertFalse($anotherPoolInstance->getItem('i3')->isHit());
|
||||
$this->assertTrue($anotherPoolInstance->getItem('foo')->isHit());
|
||||
}
|
||||
|
||||
public function testInvalidateCommits()
|
||||
{
|
||||
$pool1 = $this->createCachePool();
|
||||
|
||||
$foo = $pool1->getItem('foo');
|
||||
$foo->tag('tag');
|
||||
|
||||
$pool1->saveDeferred($foo->set('foo'));
|
||||
$pool1->invalidateTags(['tag']);
|
||||
|
||||
$pool2 = $this->createCachePool();
|
||||
$foo = $pool2->getItem('foo');
|
||||
|
||||
$this->assertTrue($foo->isHit());
|
||||
}
|
||||
|
||||
public function testTagsAreCleanedOnSave()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
|
||||
$i = $pool->getItem('k');
|
||||
$pool->save($i->tag('foo'));
|
||||
|
||||
$i = $pool->getItem('k');
|
||||
$pool->save($i->tag('bar'));
|
||||
|
||||
$pool->invalidateTags(['foo']);
|
||||
$this->assertTrue($pool->getItem('k')->isHit());
|
||||
}
|
||||
|
||||
public function testTagsAreCleanedOnDelete()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
|
||||
$i = $pool->getItem('k');
|
||||
$pool->save($i->tag('foo'));
|
||||
$pool->deleteItem('k');
|
||||
|
||||
$pool->save($pool->getItem('k'));
|
||||
$pool->invalidateTags(['foo']);
|
||||
|
||||
$this->assertTrue($pool->getItem('k')->isHit());
|
||||
}
|
||||
|
||||
public function testTagItemExpiry()
|
||||
{
|
||||
$pool = $this->createCachePool(10);
|
||||
|
||||
$item = $pool->getItem('foo');
|
||||
$item->tag(['baz']);
|
||||
$item->expiresAfter(100);
|
||||
|
||||
$pool->save($item);
|
||||
$pool->invalidateTags(['baz']);
|
||||
$this->assertFalse($pool->getItem('foo')->isHit());
|
||||
|
||||
sleep(20);
|
||||
|
||||
$this->assertFalse($pool->getItem('foo')->isHit());
|
||||
}
|
||||
|
||||
public function testGetPreviousTags()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
|
||||
$i = $pool->getItem('k');
|
||||
$pool->save($i->tag('foo'));
|
||||
|
||||
$i = $pool->getItem('k');
|
||||
$this->assertSame(['foo' => 'foo'], $i->getPreviousTags());
|
||||
}
|
||||
|
||||
public function testPrune()
|
||||
{
|
||||
$cache = new TagAwareAdapter($this->getPruneableMock());
|
||||
$this->assertTrue($cache->prune());
|
||||
|
||||
$cache = new TagAwareAdapter($this->getNonPruneableMock());
|
||||
$this->assertFalse($cache->prune());
|
||||
|
||||
$cache = new TagAwareAdapter($this->getFailingPruneableMock());
|
||||
$this->assertFalse($cache->prune());
|
||||
}
|
||||
|
||||
public function testKnownTagVersionsTtl()
|
||||
{
|
||||
$itemsPool = new FilesystemAdapter('', 10);
|
||||
$tagsPool = $this
|
||||
->getMockBuilder(AdapterInterface::class)
|
||||
->getMock();
|
||||
|
||||
$pool = new TagAwareAdapter($itemsPool, $tagsPool, 10);
|
||||
|
||||
$item = $pool->getItem('foo');
|
||||
$item->tag(['baz']);
|
||||
$item->expiresAfter(100);
|
||||
|
||||
$tag = $this->getMockBuilder(CacheItemInterface::class)->getMock();
|
||||
$tag->expects(self::exactly(2))->method('get')->willReturn(10);
|
||||
|
||||
$tagsPool->expects(self::exactly(2))->method('getItems')->willReturn([
|
||||
'baz'.TagAwareAdapter::TAGS_PREFIX => $tag,
|
||||
]);
|
||||
|
||||
$pool->save($item);
|
||||
$this->assertTrue($pool->getItem('foo')->isHit());
|
||||
$this->assertTrue($pool->getItem('foo')->isHit());
|
||||
|
||||
sleep(20);
|
||||
|
||||
$this->assertTrue($pool->getItem('foo')->isHit());
|
||||
|
||||
sleep(5);
|
||||
|
||||
$this->assertTrue($pool->getItem('foo')->isHit());
|
||||
}
|
||||
|
||||
public function testTagEntryIsCreatedForItemWithoutTags()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
|
||||
$itemKey = 'foo';
|
||||
$item = $pool->getItem($itemKey);
|
||||
$pool->save($item);
|
||||
|
||||
$adapter = new FilesystemAdapter();
|
||||
$this->assertTrue($adapter->hasItem(TagAwareAdapter::TAGS_PREFIX.$itemKey));
|
||||
}
|
||||
|
||||
public function testHasItemReturnsFalseWhenPoolDoesNotHaveItemTags()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
|
||||
$itemKey = 'foo';
|
||||
$item = $pool->getItem($itemKey);
|
||||
$pool->save($item);
|
||||
|
||||
$anotherPool = $this->createCachePool();
|
||||
|
||||
$adapter = new FilesystemAdapter();
|
||||
$adapter->deleteItem(TagAwareAdapter::TAGS_PREFIX.$itemKey); //simulate item losing tags pair
|
||||
|
||||
$this->assertFalse($anotherPool->hasItem($itemKey));
|
||||
}
|
||||
|
||||
public function testGetItemReturnsCacheMissWhenPoolDoesNotHaveItemTags()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
|
||||
$itemKey = 'foo';
|
||||
$item = $pool->getItem($itemKey);
|
||||
$pool->save($item);
|
||||
|
||||
$anotherPool = $this->createCachePool();
|
||||
|
||||
$adapter = new FilesystemAdapter();
|
||||
$adapter->deleteItem(TagAwareAdapter::TAGS_PREFIX.$itemKey); //simulate item losing tags pair
|
||||
|
||||
$item = $anotherPool->getItem($itemKey);
|
||||
$this->assertFalse($item->isHit());
|
||||
}
|
||||
|
||||
public function testHasItemReturnsFalseWhenPoolDoesNotHaveItemAndOnlyHasTags()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
|
||||
$itemKey = 'foo';
|
||||
$item = $pool->getItem($itemKey);
|
||||
$pool->save($item);
|
||||
|
||||
$anotherPool = $this->createCachePool();
|
||||
|
||||
$adapter = new FilesystemAdapter();
|
||||
$adapter->deleteItem($itemKey); //simulate losing item but keeping tags
|
||||
|
||||
$this->assertFalse($anotherPool->hasItem($itemKey));
|
||||
}
|
||||
|
||||
public function testGetItemReturnsCacheMissWhenPoolDoesNotHaveItemAndOnlyHasTags()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
|
||||
$itemKey = 'foo';
|
||||
$item = $pool->getItem($itemKey);
|
||||
$pool->save($item);
|
||||
|
||||
$anotherPool = $this->createCachePool();
|
||||
|
||||
$adapter = new FilesystemAdapter();
|
||||
$adapter->deleteItem($itemKey); //simulate losing item but keeping tags
|
||||
|
||||
$item = $anotherPool->getItem($itemKey);
|
||||
$this->assertFalse($item->isHit());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MockObject|PruneableCacheInterface
|
||||
*/
|
||||
private function getPruneableMock()
|
||||
{
|
||||
$pruneable = $this
|
||||
->getMockBuilder(PruneableCacheInterface::class)
|
||||
->getMock();
|
||||
|
||||
$pruneable
|
||||
->expects($this->atLeastOnce())
|
||||
->method('prune')
|
||||
->willReturn(true);
|
||||
|
||||
return $pruneable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MockObject|PruneableCacheInterface
|
||||
*/
|
||||
private function getFailingPruneableMock()
|
||||
{
|
||||
$pruneable = $this
|
||||
->getMockBuilder(PruneableCacheInterface::class)
|
||||
->getMock();
|
||||
|
||||
$pruneable
|
||||
->expects($this->atLeastOnce())
|
||||
->method('prune')
|
||||
->willReturn(false);
|
||||
|
||||
return $pruneable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MockObject|AdapterInterface
|
||||
*/
|
||||
private function getNonPruneableMock()
|
||||
{
|
||||
return $this
|
||||
->getMockBuilder(AdapterInterface::class)
|
||||
->getMock();
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Cache\Tests\Adapter;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Component\Cache\Adapter\ProxyAdapter;
|
||||
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
|
||||
use Symfony\Component\Cache\Tests\Fixtures\ExternalAdapter;
|
||||
|
||||
class TagAwareAndProxyAdapterIntegrationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
public function testIntegrationUsingProxiedAdapter(CacheItemPoolInterface $proxiedAdapter)
|
||||
{
|
||||
$cache = new TagAwareAdapter(new ProxyAdapter($proxiedAdapter));
|
||||
|
||||
$item = $cache->getItem('foo');
|
||||
$item->tag(['tag1', 'tag2']);
|
||||
$item->set('bar');
|
||||
$cache->save($item);
|
||||
|
||||
$this->assertSame('bar', $cache->getItem('foo')->get());
|
||||
}
|
||||
|
||||
public function dataProvider()
|
||||
{
|
||||
return [
|
||||
[new ArrayAdapter()],
|
||||
// also testing with a non-AdapterInterface implementation
|
||||
// because the ProxyAdapter behaves slightly different for those
|
||||
[new ExternalAdapter()],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,191 +0,0 @@
|
||||
<?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 Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||
use Symfony\Component\Cache\Adapter\TraceableAdapter;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class TraceableAdapterTest extends AdapterTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testPrune' => 'TraceableAdapter just proxies',
|
||||
];
|
||||
|
||||
public function createCachePool($defaultLifetime = 0)
|
||||
{
|
||||
return new TraceableAdapter(new FilesystemAdapter('', $defaultLifetime));
|
||||
}
|
||||
|
||||
public function testGetItemMissTrace()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
$pool->getItem('k');
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(1, $calls);
|
||||
|
||||
$call = $calls[0];
|
||||
$this->assertSame('getItem', $call->name);
|
||||
$this->assertSame(['k' => false], $call->result);
|
||||
$this->assertSame(0, $call->hits);
|
||||
$this->assertSame(1, $call->misses);
|
||||
$this->assertNotEmpty($call->start);
|
||||
$this->assertNotEmpty($call->end);
|
||||
}
|
||||
|
||||
public function testGetItemHitTrace()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
$item = $pool->getItem('k')->set('foo');
|
||||
$pool->save($item);
|
||||
$pool->getItem('k');
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(3, $calls);
|
||||
|
||||
$call = $calls[2];
|
||||
$this->assertSame(1, $call->hits);
|
||||
$this->assertSame(0, $call->misses);
|
||||
}
|
||||
|
||||
public function testGetItemsMissTrace()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
$arg = ['k0', 'k1'];
|
||||
$items = $pool->getItems($arg);
|
||||
foreach ($items as $item) {
|
||||
}
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(1, $calls);
|
||||
|
||||
$call = $calls[0];
|
||||
$this->assertSame('getItems', $call->name);
|
||||
$this->assertSame(['k0' => false, 'k1' => false], $call->result);
|
||||
$this->assertSame(2, $call->misses);
|
||||
$this->assertNotEmpty($call->start);
|
||||
$this->assertNotEmpty($call->end);
|
||||
}
|
||||
|
||||
public function testHasItemMissTrace()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
$pool->hasItem('k');
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(1, $calls);
|
||||
|
||||
$call = $calls[0];
|
||||
$this->assertSame('hasItem', $call->name);
|
||||
$this->assertSame(['k' => false], $call->result);
|
||||
$this->assertNotEmpty($call->start);
|
||||
$this->assertNotEmpty($call->end);
|
||||
}
|
||||
|
||||
public function testHasItemHitTrace()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
$item = $pool->getItem('k')->set('foo');
|
||||
$pool->save($item);
|
||||
$pool->hasItem('k');
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(3, $calls);
|
||||
|
||||
$call = $calls[2];
|
||||
$this->assertSame('hasItem', $call->name);
|
||||
$this->assertSame(['k' => true], $call->result);
|
||||
$this->assertNotEmpty($call->start);
|
||||
$this->assertNotEmpty($call->end);
|
||||
}
|
||||
|
||||
public function testDeleteItemTrace()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
$pool->deleteItem('k');
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(1, $calls);
|
||||
|
||||
$call = $calls[0];
|
||||
$this->assertSame('deleteItem', $call->name);
|
||||
$this->assertSame(['k' => true], $call->result);
|
||||
$this->assertSame(0, $call->hits);
|
||||
$this->assertSame(0, $call->misses);
|
||||
$this->assertNotEmpty($call->start);
|
||||
$this->assertNotEmpty($call->end);
|
||||
}
|
||||
|
||||
public function testDeleteItemsTrace()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
$arg = ['k0', 'k1'];
|
||||
$pool->deleteItems($arg);
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(1, $calls);
|
||||
|
||||
$call = $calls[0];
|
||||
$this->assertSame('deleteItems', $call->name);
|
||||
$this->assertSame(['keys' => $arg, 'result' => true], $call->result);
|
||||
$this->assertSame(0, $call->hits);
|
||||
$this->assertSame(0, $call->misses);
|
||||
$this->assertNotEmpty($call->start);
|
||||
$this->assertNotEmpty($call->end);
|
||||
}
|
||||
|
||||
public function testSaveTrace()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
$item = $pool->getItem('k')->set('foo');
|
||||
$pool->save($item);
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(2, $calls);
|
||||
|
||||
$call = $calls[1];
|
||||
$this->assertSame('save', $call->name);
|
||||
$this->assertSame(['k' => true], $call->result);
|
||||
$this->assertSame(0, $call->hits);
|
||||
$this->assertSame(0, $call->misses);
|
||||
$this->assertNotEmpty($call->start);
|
||||
$this->assertNotEmpty($call->end);
|
||||
}
|
||||
|
||||
public function testSaveDeferredTrace()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
$item = $pool->getItem('k')->set('foo');
|
||||
$pool->saveDeferred($item);
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(2, $calls);
|
||||
|
||||
$call = $calls[1];
|
||||
$this->assertSame('saveDeferred', $call->name);
|
||||
$this->assertSame(['k' => true], $call->result);
|
||||
$this->assertSame(0, $call->hits);
|
||||
$this->assertSame(0, $call->misses);
|
||||
$this->assertNotEmpty($call->start);
|
||||
$this->assertNotEmpty($call->end);
|
||||
}
|
||||
|
||||
public function testCommitTrace()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
$pool->commit();
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(1, $calls);
|
||||
|
||||
$call = $calls[0];
|
||||
$this->assertSame('commit', $call->name);
|
||||
$this->assertTrue($call->result);
|
||||
$this->assertSame(0, $call->hits);
|
||||
$this->assertSame(0, $call->misses);
|
||||
$this->assertNotEmpty($call->start);
|
||||
$this->assertNotEmpty($call->end);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
<?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 Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
|
||||
use Symfony\Component\Cache\Adapter\TraceableTagAwareAdapter;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class TraceableTagAwareAdapterTest extends TraceableAdapterTest
|
||||
{
|
||||
public function testInvalidateTags()
|
||||
{
|
||||
$pool = new TraceableTagAwareAdapter(new TagAwareAdapter(new FilesystemAdapter()));
|
||||
$pool->invalidateTags(['foo']);
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(1, $calls);
|
||||
|
||||
$call = $calls[0];
|
||||
$this->assertSame('invalidateTags', $call->name);
|
||||
$this->assertSame(0, $call->hits);
|
||||
$this->assertSame(0, $call->misses);
|
||||
$this->assertNotEmpty($call->start);
|
||||
$this->assertNotEmpty($call->end);
|
||||
}
|
||||
}
|
||||
77
lib/symfony/cache/Tests/CacheItemTest.php
vendored
77
lib/symfony/cache/Tests/CacheItemTest.php
vendored
@@ -1,77 +0,0 @@
|
||||
<?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;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Cache\CacheItem;
|
||||
|
||||
class CacheItemTest extends TestCase
|
||||
{
|
||||
public function testValidKey()
|
||||
{
|
||||
$this->assertSame('foo', CacheItem::validateKey('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInvalidKey
|
||||
*/
|
||||
public function testInvalidKey($key)
|
||||
{
|
||||
$this->expectException('Symfony\Component\Cache\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Cache key');
|
||||
CacheItem::validateKey($key);
|
||||
}
|
||||
|
||||
public function provideInvalidKey()
|
||||
{
|
||||
return [
|
||||
[''],
|
||||
['{'],
|
||||
['}'],
|
||||
['('],
|
||||
[')'],
|
||||
['/'],
|
||||
['\\'],
|
||||
['@'],
|
||||
[':'],
|
||||
[true],
|
||||
[null],
|
||||
[1],
|
||||
[1.1],
|
||||
[[[]]],
|
||||
[new \Exception('foo')],
|
||||
];
|
||||
}
|
||||
|
||||
public function testTag()
|
||||
{
|
||||
$item = new CacheItem();
|
||||
|
||||
$this->assertSame($item, $item->tag('foo'));
|
||||
$this->assertSame($item, $item->tag(['bar', 'baz']));
|
||||
|
||||
\call_user_func(\Closure::bind(function () use ($item) {
|
||||
$this->assertSame(['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'], $item->tags);
|
||||
}, $this, CacheItem::class));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInvalidKey
|
||||
*/
|
||||
public function testInvalidTag($tag)
|
||||
{
|
||||
$this->expectException('Symfony\Component\Cache\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Cache tag');
|
||||
$item = new CacheItem();
|
||||
$item->tag($tag);
|
||||
}
|
||||
}
|
||||
45
lib/symfony/cache/Tests/DoctrineProviderTest.php
vendored
45
lib/symfony/cache/Tests/DoctrineProviderTest.php
vendored
@@ -1,45 +0,0 @@
|
||||
<?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;
|
||||
|
||||
use Doctrine\Common\Cache\CacheProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Component\Cache\DoctrineProvider;
|
||||
|
||||
class DoctrineProviderTest extends TestCase
|
||||
{
|
||||
public function testProvider()
|
||||
{
|
||||
$pool = new ArrayAdapter();
|
||||
$cache = new DoctrineProvider($pool);
|
||||
|
||||
$this->assertInstanceOf(CacheProvider::class, $cache);
|
||||
|
||||
$key = '{}()/\@:';
|
||||
|
||||
$this->assertTrue($cache->delete($key));
|
||||
$this->assertFalse($cache->contains($key));
|
||||
|
||||
$this->assertTrue($cache->save($key, 'bar'));
|
||||
$this->assertTrue($cache->contains($key));
|
||||
$this->assertSame('bar', $cache->fetch($key));
|
||||
|
||||
$this->assertTrue($cache->delete($key));
|
||||
$this->assertFalse($cache->fetch($key));
|
||||
$this->assertTrue($cache->save($key, 'bar'));
|
||||
|
||||
$cache->flushAll();
|
||||
$this->assertFalse($cache->fetch($key));
|
||||
$this->assertFalse($cache->contains($key));
|
||||
}
|
||||
}
|
||||
52
lib/symfony/cache/Tests/Fixtures/ArrayCache.php
vendored
52
lib/symfony/cache/Tests/Fixtures/ArrayCache.php
vendored
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Cache\Tests\Fixtures;
|
||||
|
||||
use Doctrine\Common\Cache\CacheProvider;
|
||||
|
||||
class ArrayCache extends CacheProvider
|
||||
{
|
||||
private $data = [];
|
||||
|
||||
protected function doFetch($id)
|
||||
{
|
||||
return $this->doContains($id) ? $this->data[$id][0] : false;
|
||||
}
|
||||
|
||||
protected function doContains($id)
|
||||
{
|
||||
if (!isset($this->data[$id])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$expiry = $this->data[$id][1];
|
||||
|
||||
return !$expiry || time() < $expiry || !$this->doDelete($id);
|
||||
}
|
||||
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
$this->data[$id] = [$data, $lifeTime ? time() + $lifeTime : false];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function doDelete($id)
|
||||
{
|
||||
unset($this->data[$id]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function doFlush()
|
||||
{
|
||||
$this->data = [];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function doGetStats()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
<?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\Fixtures;
|
||||
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
|
||||
/**
|
||||
* Adapter not implementing the {@see \Symfony\Component\Cache\Adapter\AdapterInterface}.
|
||||
*
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class ExternalAdapter implements CacheItemPoolInterface
|
||||
{
|
||||
private $cache;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->cache = new ArrayAdapter();
|
||||
}
|
||||
|
||||
public function getItem($key)
|
||||
{
|
||||
return $this->cache->getItem($key);
|
||||
}
|
||||
|
||||
public function getItems(array $keys = [])
|
||||
{
|
||||
return $this->cache->getItems($keys);
|
||||
}
|
||||
|
||||
public function hasItem($key)
|
||||
{
|
||||
return $this->cache->hasItem($key);
|
||||
}
|
||||
|
||||
public function clear()
|
||||
{
|
||||
return $this->cache->clear();
|
||||
}
|
||||
|
||||
public function deleteItem($key)
|
||||
{
|
||||
return $this->cache->deleteItem($key);
|
||||
}
|
||||
|
||||
public function deleteItems(array $keys)
|
||||
{
|
||||
return $this->cache->deleteItems($keys);
|
||||
}
|
||||
|
||||
public function save(CacheItemInterface $item)
|
||||
{
|
||||
return $this->cache->save($item);
|
||||
}
|
||||
|
||||
public function saveDeferred(CacheItemInterface $item)
|
||||
{
|
||||
return $this->cache->saveDeferred($item);
|
||||
}
|
||||
|
||||
public function commit()
|
||||
{
|
||||
return $this->cache->commit();
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
use Symfony\Component\Cache\Simple\RedisCache;
|
||||
|
||||
abstract class AbstractRedisCacheTest extends CacheTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testSetTtl' => 'Testing expiration slows down the test suite',
|
||||
'testSetMultipleTtl' => 'Testing expiration slows down the test suite',
|
||||
'testDefaultLifeTime' => 'Testing expiration slows down the test suite',
|
||||
];
|
||||
|
||||
protected static $redis;
|
||||
|
||||
public function createSimpleCache($defaultLifetime = 0)
|
||||
{
|
||||
return new RedisCache(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime);
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
if (!\extension_loaded('redis')) {
|
||||
self::markTestSkipped('Extension redis required.');
|
||||
}
|
||||
if (!@((new \Redis())->connect(getenv('REDIS_HOST')))) {
|
||||
$e = error_get_last();
|
||||
self::markTestSkipped($e['message']);
|
||||
}
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
self::$redis = null;
|
||||
}
|
||||
}
|
||||
35
lib/symfony/cache/Tests/Simple/ApcuCacheTest.php
vendored
35
lib/symfony/cache/Tests/Simple/ApcuCacheTest.php
vendored
@@ -1,35 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
use Symfony\Component\Cache\Simple\ApcuCache;
|
||||
|
||||
class ApcuCacheTest extends CacheTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testSetTtl' => 'Testing expiration slows down the test suite',
|
||||
'testSetMultipleTtl' => 'Testing expiration slows down the test suite',
|
||||
'testDefaultLifeTime' => 'Testing expiration slows down the test suite',
|
||||
];
|
||||
|
||||
public function createSimpleCache($defaultLifetime = 0)
|
||||
{
|
||||
if (!\function_exists('apcu_fetch') || !filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) || ('cli' === \PHP_SAPI && !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN))) {
|
||||
$this->markTestSkipped('APCu extension is required.');
|
||||
}
|
||||
if ('\\' === \DIRECTORY_SEPARATOR) {
|
||||
$this->markTestSkipped('Fails transiently on Windows.');
|
||||
}
|
||||
|
||||
return new ApcuCache(str_replace('\\', '.', __CLASS__), $defaultLifetime);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
use Symfony\Component\Cache\Simple\ArrayCache;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class ArrayCacheTest extends CacheTestCase
|
||||
{
|
||||
public function createSimpleCache($defaultLifetime = 0)
|
||||
{
|
||||
return new ArrayCache($defaultLifetime);
|
||||
}
|
||||
}
|
||||
150
lib/symfony/cache/Tests/Simple/CacheTestCase.php
vendored
150
lib/symfony/cache/Tests/Simple/CacheTestCase.php
vendored
@@ -1,150 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
use Cache\IntegrationTests\SimpleCacheTest;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
use Symfony\Component\Cache\PruneableInterface;
|
||||
|
||||
abstract class CacheTestCase extends SimpleCacheTest
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!\array_key_exists('testPrune', $this->skippedTests) && !$this->createSimpleCache() instanceof PruneableInterface) {
|
||||
$this->skippedTests['testPrune'] = 'Not a pruneable cache pool.';
|
||||
}
|
||||
}
|
||||
|
||||
public static function validKeys()
|
||||
{
|
||||
if (\defined('HHVM_VERSION')) {
|
||||
return parent::validKeys();
|
||||
}
|
||||
|
||||
return array_merge(parent::validKeys(), [["a\0b"]]);
|
||||
}
|
||||
|
||||
public function testDefaultLifeTime()
|
||||
{
|
||||
if (isset($this->skippedTests[__FUNCTION__])) {
|
||||
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
|
||||
}
|
||||
|
||||
$cache = $this->createSimpleCache(2);
|
||||
$cache->clear();
|
||||
|
||||
$cache->set('key.dlt', 'value');
|
||||
sleep(1);
|
||||
|
||||
$this->assertSame('value', $cache->get('key.dlt'));
|
||||
|
||||
sleep(2);
|
||||
$this->assertNull($cache->get('key.dlt'));
|
||||
|
||||
$cache->clear();
|
||||
}
|
||||
|
||||
public function testNotUnserializable()
|
||||
{
|
||||
if (isset($this->skippedTests[__FUNCTION__])) {
|
||||
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
|
||||
}
|
||||
|
||||
$cache = $this->createSimpleCache();
|
||||
$cache->clear();
|
||||
|
||||
$cache->set('foo', new NotUnserializable());
|
||||
|
||||
$this->assertNull($cache->get('foo'));
|
||||
|
||||
$cache->setMultiple(['foo' => new NotUnserializable()]);
|
||||
|
||||
foreach ($cache->getMultiple(['foo']) as $value) {
|
||||
}
|
||||
$this->assertNull($value);
|
||||
|
||||
$cache->clear();
|
||||
}
|
||||
|
||||
public function testPrune()
|
||||
{
|
||||
if (isset($this->skippedTests[__FUNCTION__])) {
|
||||
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
|
||||
}
|
||||
|
||||
if (!method_exists($this, 'isPruned')) {
|
||||
$this->fail('Test classes for pruneable caches must implement `isPruned($cache, $name)` method.');
|
||||
}
|
||||
|
||||
/** @var PruneableInterface|CacheInterface $cache */
|
||||
$cache = $this->createSimpleCache();
|
||||
$cache->clear();
|
||||
|
||||
$cache->set('foo', 'foo-val', new \DateInterval('PT05S'));
|
||||
$cache->set('bar', 'bar-val', new \DateInterval('PT10S'));
|
||||
$cache->set('baz', 'baz-val', new \DateInterval('PT15S'));
|
||||
$cache->set('qux', 'qux-val', new \DateInterval('PT20S'));
|
||||
|
||||
sleep(30);
|
||||
$cache->prune();
|
||||
$this->assertTrue($this->isPruned($cache, 'foo'));
|
||||
$this->assertTrue($this->isPruned($cache, 'bar'));
|
||||
$this->assertTrue($this->isPruned($cache, 'baz'));
|
||||
$this->assertTrue($this->isPruned($cache, 'qux'));
|
||||
|
||||
$cache->set('foo', 'foo-val');
|
||||
$cache->set('bar', 'bar-val', new \DateInterval('PT20S'));
|
||||
$cache->set('baz', 'baz-val', new \DateInterval('PT40S'));
|
||||
$cache->set('qux', 'qux-val', new \DateInterval('PT80S'));
|
||||
|
||||
$cache->prune();
|
||||
$this->assertFalse($this->isPruned($cache, 'foo'));
|
||||
$this->assertFalse($this->isPruned($cache, 'bar'));
|
||||
$this->assertFalse($this->isPruned($cache, 'baz'));
|
||||
$this->assertFalse($this->isPruned($cache, 'qux'));
|
||||
|
||||
sleep(30);
|
||||
$cache->prune();
|
||||
$this->assertFalse($this->isPruned($cache, 'foo'));
|
||||
$this->assertTrue($this->isPruned($cache, 'bar'));
|
||||
$this->assertFalse($this->isPruned($cache, 'baz'));
|
||||
$this->assertFalse($this->isPruned($cache, 'qux'));
|
||||
|
||||
sleep(30);
|
||||
$cache->prune();
|
||||
$this->assertFalse($this->isPruned($cache, 'foo'));
|
||||
$this->assertTrue($this->isPruned($cache, 'baz'));
|
||||
$this->assertFalse($this->isPruned($cache, 'qux'));
|
||||
|
||||
sleep(30);
|
||||
$cache->prune();
|
||||
$this->assertFalse($this->isPruned($cache, 'foo'));
|
||||
$this->assertTrue($this->isPruned($cache, 'qux'));
|
||||
|
||||
$cache->clear();
|
||||
}
|
||||
}
|
||||
|
||||
class NotUnserializable implements \Serializable
|
||||
{
|
||||
public function serialize()
|
||||
{
|
||||
return serialize(123);
|
||||
}
|
||||
|
||||
public function unserialize($ser)
|
||||
{
|
||||
throw new \Exception(__CLASS__);
|
||||
}
|
||||
}
|
||||
113
lib/symfony/cache/Tests/Simple/ChainCacheTest.php
vendored
113
lib/symfony/cache/Tests/Simple/ChainCacheTest.php
vendored
@@ -1,113 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
use Symfony\Component\Cache\PruneableInterface;
|
||||
use Symfony\Component\Cache\Simple\ArrayCache;
|
||||
use Symfony\Component\Cache\Simple\ChainCache;
|
||||
use Symfony\Component\Cache\Simple\FilesystemCache;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class ChainCacheTest extends CacheTestCase
|
||||
{
|
||||
public function createSimpleCache($defaultLifetime = 0)
|
||||
{
|
||||
return new ChainCache([new ArrayCache($defaultLifetime), new FilesystemCache('', $defaultLifetime)], $defaultLifetime);
|
||||
}
|
||||
|
||||
public function testEmptyCachesException()
|
||||
{
|
||||
$this->expectException('Symfony\Component\Cache\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('At least one cache must be specified.');
|
||||
new ChainCache([]);
|
||||
}
|
||||
|
||||
public function testInvalidCacheException()
|
||||
{
|
||||
$this->expectException('Symfony\Component\Cache\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('The class "stdClass" does not implement');
|
||||
new ChainCache([new \stdClass()]);
|
||||
}
|
||||
|
||||
public function testPrune()
|
||||
{
|
||||
if (isset($this->skippedTests[__FUNCTION__])) {
|
||||
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
|
||||
}
|
||||
|
||||
$cache = new ChainCache([
|
||||
$this->getPruneableMock(),
|
||||
$this->getNonPruneableMock(),
|
||||
$this->getPruneableMock(),
|
||||
]);
|
||||
$this->assertTrue($cache->prune());
|
||||
|
||||
$cache = new ChainCache([
|
||||
$this->getPruneableMock(),
|
||||
$this->getFailingPruneableMock(),
|
||||
$this->getPruneableMock(),
|
||||
]);
|
||||
$this->assertFalse($cache->prune());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MockObject|PruneableCacheInterface
|
||||
*/
|
||||
private function getPruneableMock()
|
||||
{
|
||||
$pruneable = $this
|
||||
->getMockBuilder(PruneableCacheInterface::class)
|
||||
->getMock();
|
||||
|
||||
$pruneable
|
||||
->expects($this->atLeastOnce())
|
||||
->method('prune')
|
||||
->willReturn(true);
|
||||
|
||||
return $pruneable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MockObject|PruneableCacheInterface
|
||||
*/
|
||||
private function getFailingPruneableMock()
|
||||
{
|
||||
$pruneable = $this
|
||||
->getMockBuilder(PruneableCacheInterface::class)
|
||||
->getMock();
|
||||
|
||||
$pruneable
|
||||
->expects($this->atLeastOnce())
|
||||
->method('prune')
|
||||
->willReturn(false);
|
||||
|
||||
return $pruneable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MockObject|CacheInterface
|
||||
*/
|
||||
private function getNonPruneableMock()
|
||||
{
|
||||
return $this
|
||||
->getMockBuilder(CacheInterface::class)
|
||||
->getMock();
|
||||
}
|
||||
}
|
||||
|
||||
interface PruneableCacheInterface extends PruneableInterface, CacheInterface
|
||||
{
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
use Symfony\Component\Cache\Simple\DoctrineCache;
|
||||
use Symfony\Component\Cache\Tests\Fixtures\ArrayCache;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class DoctrineCacheTest extends CacheTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testObjectDoesNotChangeInCache' => 'ArrayCache does not use serialize/unserialize',
|
||||
'testNotUnserializable' => 'ArrayCache does not use serialize/unserialize',
|
||||
];
|
||||
|
||||
public function createSimpleCache($defaultLifetime = 0)
|
||||
{
|
||||
return new DoctrineCache(new ArrayCache($defaultLifetime), '', $defaultLifetime);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
use Symfony\Component\Cache\Simple\FilesystemCache;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class FilesystemCacheTest extends CacheTestCase
|
||||
{
|
||||
public function createSimpleCache($defaultLifetime = 0)
|
||||
{
|
||||
return new FilesystemCache('', $defaultLifetime);
|
||||
}
|
||||
|
||||
protected function isPruned(CacheInterface $cache, $name)
|
||||
{
|
||||
$getFileMethod = (new \ReflectionObject($cache))->getMethod('getFile');
|
||||
$getFileMethod->setAccessible(true);
|
||||
|
||||
return !file_exists($getFileMethod->invoke($cache, $name));
|
||||
}
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
use Symfony\Component\Cache\Adapter\AbstractAdapter;
|
||||
use Symfony\Component\Cache\Simple\MemcachedCache;
|
||||
|
||||
class MemcachedCacheTest extends CacheTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testSetTtl' => 'Testing expiration slows down the test suite',
|
||||
'testSetMultipleTtl' => 'Testing expiration slows down the test suite',
|
||||
'testDefaultLifeTime' => 'Testing expiration slows down the test suite',
|
||||
];
|
||||
|
||||
protected static $client;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
if (!MemcachedCache::isSupported()) {
|
||||
self::markTestSkipped('Extension memcached >=2.2.0 required.');
|
||||
}
|
||||
self::$client = AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'));
|
||||
self::$client->get('foo');
|
||||
$code = self::$client->getResultCode();
|
||||
|
||||
if (\Memcached::RES_SUCCESS !== $code && \Memcached::RES_NOTFOUND !== $code) {
|
||||
self::markTestSkipped('Memcached error: '.strtolower(self::$client->getResultMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
public function createSimpleCache($defaultLifetime = 0)
|
||||
{
|
||||
$client = $defaultLifetime ? AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'), ['binary_protocol' => false]) : self::$client;
|
||||
|
||||
return new MemcachedCache($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
|
||||
}
|
||||
|
||||
public function testCreatePersistentConnectionShouldNotDupServerList()
|
||||
{
|
||||
$instance = MemcachedCache::createConnection('memcached://'.getenv('MEMCACHED_HOST'), ['persistent_id' => 'persistent']);
|
||||
$this->assertCount(1, $instance->getServerList());
|
||||
|
||||
$instance = MemcachedCache::createConnection('memcached://'.getenv('MEMCACHED_HOST'), ['persistent_id' => 'persistent']);
|
||||
$this->assertCount(1, $instance->getServerList());
|
||||
}
|
||||
|
||||
public function testOptions()
|
||||
{
|
||||
$client = MemcachedCache::createConnection([], [
|
||||
'libketama_compatible' => false,
|
||||
'distribution' => 'modula',
|
||||
'compression' => true,
|
||||
'serializer' => 'php',
|
||||
'hash' => 'md5',
|
||||
]);
|
||||
|
||||
$this->assertSame(\Memcached::SERIALIZER_PHP, $client->getOption(\Memcached::OPT_SERIALIZER));
|
||||
$this->assertSame(\Memcached::HASH_MD5, $client->getOption(\Memcached::OPT_HASH));
|
||||
$this->assertTrue($client->getOption(\Memcached::OPT_COMPRESSION));
|
||||
$this->assertSame(0, $client->getOption(\Memcached::OPT_LIBKETAMA_COMPATIBLE));
|
||||
$this->assertSame(\Memcached::DISTRIBUTION_MODULA, $client->getOption(\Memcached::OPT_DISTRIBUTION));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideBadOptions
|
||||
*/
|
||||
public function testBadOptions($name, $value)
|
||||
{
|
||||
$this->expectException('ErrorException');
|
||||
$this->expectExceptionMessage('constant(): Couldn\'t find constant Memcached::');
|
||||
MemcachedCache::createConnection([], [$name => $value]);
|
||||
}
|
||||
|
||||
public function provideBadOptions()
|
||||
{
|
||||
return [
|
||||
['foo', 'bar'],
|
||||
['hash', 'zyx'],
|
||||
['serializer', 'zyx'],
|
||||
['distribution', 'zyx'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testDefaultOptions()
|
||||
{
|
||||
$this->assertTrue(MemcachedCache::isSupported());
|
||||
|
||||
$client = MemcachedCache::createConnection([]);
|
||||
|
||||
$this->assertTrue($client->getOption(\Memcached::OPT_COMPRESSION));
|
||||
$this->assertSame(1, $client->getOption(\Memcached::OPT_BINARY_PROTOCOL));
|
||||
$this->assertSame(1, $client->getOption(\Memcached::OPT_LIBKETAMA_COMPATIBLE));
|
||||
}
|
||||
|
||||
public function testOptionSerializer()
|
||||
{
|
||||
$this->expectException('Symfony\Component\Cache\Exception\CacheException');
|
||||
$this->expectExceptionMessage('MemcachedAdapter: "serializer" option must be "php" or "igbinary".');
|
||||
if (!\Memcached::HAVE_JSON) {
|
||||
$this->markTestSkipped('Memcached::HAVE_JSON required');
|
||||
}
|
||||
|
||||
new MemcachedCache(MemcachedCache::createConnection([], ['serializer' => 'json']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideServersSetting
|
||||
*/
|
||||
public function testServersSetting($dsn, $host, $port)
|
||||
{
|
||||
$client1 = MemcachedCache::createConnection($dsn);
|
||||
$client2 = MemcachedCache::createConnection([$dsn]);
|
||||
$client3 = MemcachedCache::createConnection([[$host, $port]]);
|
||||
$expect = [
|
||||
'host' => $host,
|
||||
'port' => $port,
|
||||
];
|
||||
|
||||
$f = function ($s) { return ['host' => $s['host'], 'port' => $s['port']]; };
|
||||
$this->assertSame([$expect], array_map($f, $client1->getServerList()));
|
||||
$this->assertSame([$expect], array_map($f, $client2->getServerList()));
|
||||
$this->assertSame([$expect], array_map($f, $client3->getServerList()));
|
||||
}
|
||||
|
||||
public function provideServersSetting()
|
||||
{
|
||||
yield [
|
||||
'memcached://127.0.0.1/50',
|
||||
'127.0.0.1',
|
||||
11211,
|
||||
];
|
||||
yield [
|
||||
'memcached://localhost:11222?weight=25',
|
||||
'localhost',
|
||||
11222,
|
||||
];
|
||||
if (filter_var(ini_get('memcached.use_sasl'), FILTER_VALIDATE_BOOLEAN)) {
|
||||
yield [
|
||||
'memcached://user:password@127.0.0.1?weight=50',
|
||||
'127.0.0.1',
|
||||
11211,
|
||||
];
|
||||
}
|
||||
yield [
|
||||
'memcached:///var/run/memcached.sock?weight=25',
|
||||
'/var/run/memcached.sock',
|
||||
0,
|
||||
];
|
||||
yield [
|
||||
'memcached:///var/local/run/memcached.socket?weight=25',
|
||||
'/var/local/run/memcached.socket',
|
||||
0,
|
||||
];
|
||||
if (filter_var(ini_get('memcached.use_sasl'), FILTER_VALIDATE_BOOLEAN)) {
|
||||
yield [
|
||||
'memcached://user:password@/var/local/run/memcached.socket?weight=25',
|
||||
'/var/local/run/memcached.socket',
|
||||
0,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
use Symfony\Component\Cache\Adapter\AbstractAdapter;
|
||||
use Symfony\Component\Cache\Simple\MemcachedCache;
|
||||
|
||||
class MemcachedCacheTextModeTest extends MemcachedCacheTest
|
||||
{
|
||||
public function createSimpleCache($defaultLifetime = 0)
|
||||
{
|
||||
$client = AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'), ['binary_protocol' => false]);
|
||||
|
||||
return new MemcachedCache($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
|
||||
}
|
||||
}
|
||||
96
lib/symfony/cache/Tests/Simple/NullCacheTest.php
vendored
96
lib/symfony/cache/Tests/Simple/NullCacheTest.php
vendored
@@ -1,96 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Cache\Simple\NullCache;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class NullCacheTest extends TestCase
|
||||
{
|
||||
public function createCachePool()
|
||||
{
|
||||
return new NullCache();
|
||||
}
|
||||
|
||||
public function testGetItem()
|
||||
{
|
||||
$cache = $this->createCachePool();
|
||||
|
||||
$this->assertNull($cache->get('key'));
|
||||
}
|
||||
|
||||
public function testHas()
|
||||
{
|
||||
$this->assertFalse($this->createCachePool()->has('key'));
|
||||
}
|
||||
|
||||
public function testGetMultiple()
|
||||
{
|
||||
$cache = $this->createCachePool();
|
||||
|
||||
$keys = ['foo', 'bar', 'baz', 'biz'];
|
||||
|
||||
$default = new \stdClass();
|
||||
$items = $cache->getMultiple($keys, $default);
|
||||
$count = 0;
|
||||
|
||||
foreach ($items as $key => $item) {
|
||||
$this->assertContains($key, $keys, 'Cache key can not change.');
|
||||
$this->assertSame($default, $item);
|
||||
|
||||
// Remove $key for $keys
|
||||
foreach ($keys as $k => $v) {
|
||||
if ($v === $key) {
|
||||
unset($keys[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
++$count;
|
||||
}
|
||||
|
||||
$this->assertSame(4, $count);
|
||||
}
|
||||
|
||||
public function testClear()
|
||||
{
|
||||
$this->assertTrue($this->createCachePool()->clear());
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$this->assertTrue($this->createCachePool()->delete('key'));
|
||||
}
|
||||
|
||||
public function testDeleteMultiple()
|
||||
{
|
||||
$this->assertTrue($this->createCachePool()->deleteMultiple(['key', 'foo', 'bar']));
|
||||
}
|
||||
|
||||
public function testSet()
|
||||
{
|
||||
$cache = $this->createCachePool();
|
||||
|
||||
$this->assertFalse($cache->set('key', 'val'));
|
||||
$this->assertNull($cache->get('key'));
|
||||
}
|
||||
|
||||
public function testSetMultiple()
|
||||
{
|
||||
$cache = $this->createCachePool();
|
||||
|
||||
$this->assertFalse($cache->setMultiple(['key' => 'val']));
|
||||
$this->assertNull($cache->get('key'));
|
||||
}
|
||||
}
|
||||
47
lib/symfony/cache/Tests/Simple/PdoCacheTest.php
vendored
47
lib/symfony/cache/Tests/Simple/PdoCacheTest.php
vendored
@@ -1,47 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
use Symfony\Component\Cache\Simple\PdoCache;
|
||||
use Symfony\Component\Cache\Tests\Traits\PdoPruneableTrait;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class PdoCacheTest extends CacheTestCase
|
||||
{
|
||||
use PdoPruneableTrait;
|
||||
|
||||
protected static $dbFile;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
if (!\extension_loaded('pdo_sqlite')) {
|
||||
self::markTestSkipped('Extension pdo_sqlite required.');
|
||||
}
|
||||
|
||||
self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache');
|
||||
|
||||
$pool = new PdoCache('sqlite:'.self::$dbFile);
|
||||
$pool->createTable();
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
@unlink(self::$dbFile);
|
||||
}
|
||||
|
||||
public function createSimpleCache($defaultLifetime = 0)
|
||||
{
|
||||
return new PdoCache('sqlite:'.self::$dbFile, 'ns', $defaultLifetime);
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
use Doctrine\DBAL\DriverManager;
|
||||
use Symfony\Component\Cache\Simple\PdoCache;
|
||||
use Symfony\Component\Cache\Tests\Traits\PdoPruneableTrait;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class PdoDbalCacheTest extends CacheTestCase
|
||||
{
|
||||
use PdoPruneableTrait;
|
||||
|
||||
protected static $dbFile;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
if (!\extension_loaded('pdo_sqlite')) {
|
||||
self::markTestSkipped('Extension pdo_sqlite required.');
|
||||
}
|
||||
|
||||
self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache');
|
||||
|
||||
$pool = new PdoCache(DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile]));
|
||||
$pool->createTable();
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
@unlink(self::$dbFile);
|
||||
}
|
||||
|
||||
public function createSimpleCache($defaultLifetime = 0)
|
||||
{
|
||||
return new PdoCache(DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile]), '', $defaultLifetime);
|
||||
}
|
||||
}
|
||||
143
lib/symfony/cache/Tests/Simple/PhpArrayCacheTest.php
vendored
143
lib/symfony/cache/Tests/Simple/PhpArrayCacheTest.php
vendored
@@ -1,143 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
use Symfony\Component\Cache\Simple\NullCache;
|
||||
use Symfony\Component\Cache\Simple\PhpArrayCache;
|
||||
use Symfony\Component\Cache\Tests\Adapter\FilesystemAdapterTest;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class PhpArrayCacheTest extends CacheTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testBasicUsageWithLongKey' => 'PhpArrayCache does no writes',
|
||||
|
||||
'testDelete' => 'PhpArrayCache does no writes',
|
||||
'testDeleteMultiple' => 'PhpArrayCache does no writes',
|
||||
'testDeleteMultipleGenerator' => 'PhpArrayCache does no writes',
|
||||
|
||||
'testSetTtl' => 'PhpArrayCache does no expiration',
|
||||
'testSetMultipleTtl' => 'PhpArrayCache does no expiration',
|
||||
'testSetExpiredTtl' => 'PhpArrayCache does no expiration',
|
||||
'testSetMultipleExpiredTtl' => 'PhpArrayCache does no expiration',
|
||||
|
||||
'testGetInvalidKeys' => 'PhpArrayCache does no validation',
|
||||
'testGetMultipleInvalidKeys' => 'PhpArrayCache does no validation',
|
||||
'testSetInvalidKeys' => 'PhpArrayCache does no validation',
|
||||
'testDeleteInvalidKeys' => 'PhpArrayCache does no validation',
|
||||
'testDeleteMultipleInvalidKeys' => 'PhpArrayCache does no validation',
|
||||
'testSetInvalidTtl' => 'PhpArrayCache does no validation',
|
||||
'testSetMultipleInvalidKeys' => 'PhpArrayCache does no validation',
|
||||
'testSetMultipleInvalidTtl' => 'PhpArrayCache does no validation',
|
||||
'testHasInvalidKeys' => 'PhpArrayCache does no validation',
|
||||
'testSetValidData' => 'PhpArrayCache does no validation',
|
||||
|
||||
'testDefaultLifeTime' => 'PhpArrayCache does not allow configuring a default lifetime.',
|
||||
'testPrune' => 'PhpArrayCache just proxies',
|
||||
];
|
||||
|
||||
protected static $file;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$file = sys_get_temp_dir().'/symfony-cache/php-array-adapter-test.php';
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
if (file_exists(sys_get_temp_dir().'/symfony-cache')) {
|
||||
FilesystemAdapterTest::rmdir(sys_get_temp_dir().'/symfony-cache');
|
||||
}
|
||||
}
|
||||
|
||||
public function createSimpleCache()
|
||||
{
|
||||
return new PhpArrayCacheWrapper(self::$file, new NullCache());
|
||||
}
|
||||
|
||||
public function testStore()
|
||||
{
|
||||
$arrayWithRefs = [];
|
||||
$arrayWithRefs[0] = 123;
|
||||
$arrayWithRefs[1] = &$arrayWithRefs[0];
|
||||
|
||||
$object = (object) [
|
||||
'foo' => 'bar',
|
||||
'foo2' => 'bar2',
|
||||
];
|
||||
|
||||
$expected = [
|
||||
'null' => null,
|
||||
'serializedString' => serialize($object),
|
||||
'arrayWithRefs' => $arrayWithRefs,
|
||||
'object' => $object,
|
||||
'arrayWithObject' => ['bar' => $object],
|
||||
];
|
||||
|
||||
$cache = new PhpArrayCache(self::$file, new NullCache());
|
||||
$cache->warmUp($expected);
|
||||
|
||||
foreach ($expected as $key => $value) {
|
||||
$this->assertSame(serialize($value), serialize($cache->get($key)), 'Warm up should create a PHP file that OPCache can load in memory');
|
||||
}
|
||||
}
|
||||
|
||||
public function testStoredFile()
|
||||
{
|
||||
$expected = [
|
||||
'integer' => 42,
|
||||
'float' => 42.42,
|
||||
'boolean' => true,
|
||||
'array_simple' => ['foo', 'bar'],
|
||||
'array_associative' => ['foo' => 'bar', 'foo2' => 'bar2'],
|
||||
];
|
||||
|
||||
$cache = new PhpArrayCache(self::$file, new NullCache());
|
||||
$cache->warmUp($expected);
|
||||
|
||||
$values = eval(substr(file_get_contents(self::$file), 6));
|
||||
|
||||
$this->assertSame($expected, $values, 'Warm up should create a PHP file that OPCache can load in memory');
|
||||
}
|
||||
}
|
||||
|
||||
class PhpArrayCacheWrapper extends PhpArrayCache
|
||||
{
|
||||
public function set($key, $value, $ttl = null)
|
||||
{
|
||||
\call_user_func(\Closure::bind(function () use ($key, $value) {
|
||||
$this->values[$key] = $value;
|
||||
$this->warmUp($this->values);
|
||||
$this->values = eval(substr(file_get_contents($this->file), 6));
|
||||
}, $this, PhpArrayCache::class));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function setMultiple($values, $ttl = null)
|
||||
{
|
||||
if (!\is_array($values) && !$values instanceof \Traversable) {
|
||||
return parent::setMultiple($values, $ttl);
|
||||
}
|
||||
\call_user_func(\Closure::bind(function () use ($values) {
|
||||
foreach ($values as $key => $value) {
|
||||
$this->values[$key] = $value;
|
||||
}
|
||||
$this->warmUp($this->values);
|
||||
$this->values = eval(substr(file_get_contents($this->file), 6));
|
||||
}, $this, PhpArrayCache::class));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
use Symfony\Component\Cache\Simple\FilesystemCache;
|
||||
use Symfony\Component\Cache\Simple\PhpArrayCache;
|
||||
use Symfony\Component\Cache\Tests\Adapter\FilesystemAdapterTest;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class PhpArrayCacheWithFallbackTest extends CacheTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testGetInvalidKeys' => 'PhpArrayCache does no validation',
|
||||
'testGetMultipleInvalidKeys' => 'PhpArrayCache does no validation',
|
||||
'testDeleteInvalidKeys' => 'PhpArrayCache does no validation',
|
||||
'testDeleteMultipleInvalidKeys' => 'PhpArrayCache does no validation',
|
||||
//'testSetValidData' => 'PhpArrayCache does no validation',
|
||||
'testSetInvalidKeys' => 'PhpArrayCache does no validation',
|
||||
'testSetInvalidTtl' => 'PhpArrayCache does no validation',
|
||||
'testSetMultipleInvalidKeys' => 'PhpArrayCache does no validation',
|
||||
'testSetMultipleInvalidTtl' => 'PhpArrayCache does no validation',
|
||||
'testHasInvalidKeys' => 'PhpArrayCache does no validation',
|
||||
'testPrune' => 'PhpArrayCache just proxies',
|
||||
];
|
||||
|
||||
protected static $file;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$file = sys_get_temp_dir().'/symfony-cache/php-array-adapter-test.php';
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
if (file_exists(sys_get_temp_dir().'/symfony-cache')) {
|
||||
FilesystemAdapterTest::rmdir(sys_get_temp_dir().'/symfony-cache');
|
||||
}
|
||||
}
|
||||
|
||||
public function createSimpleCache($defaultLifetime = 0)
|
||||
{
|
||||
return new PhpArrayCache(self::$file, new FilesystemCache('php-array-fallback', $defaultLifetime));
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
use Symfony\Component\Cache\Simple\PhpFilesCache;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class PhpFilesCacheTest extends CacheTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testDefaultLifeTime' => 'PhpFilesCache does not allow configuring a default lifetime.',
|
||||
];
|
||||
|
||||
public function createSimpleCache()
|
||||
{
|
||||
if (!PhpFilesCache::isSupported()) {
|
||||
$this->markTestSkipped('OPcache extension is not enabled.');
|
||||
}
|
||||
|
||||
return new PhpFilesCache('sf-cache');
|
||||
}
|
||||
|
||||
protected function isPruned(CacheInterface $cache, $name)
|
||||
{
|
||||
$getFileMethod = (new \ReflectionObject($cache))->getMethod('getFile');
|
||||
$getFileMethod->setAccessible(true);
|
||||
|
||||
return !file_exists($getFileMethod->invoke($cache, $name));
|
||||
}
|
||||
}
|
||||
30
lib/symfony/cache/Tests/Simple/Psr6CacheTest.php
vendored
30
lib/symfony/cache/Tests/Simple/Psr6CacheTest.php
vendored
@@ -1,30 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||
use Symfony\Component\Cache\Simple\Psr6Cache;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class Psr6CacheTest extends CacheTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testPrune' => 'Psr6Cache just proxies',
|
||||
];
|
||||
|
||||
public function createSimpleCache($defaultLifetime = 0)
|
||||
{
|
||||
return new Psr6Cache(new FilesystemAdapter('', $defaultLifetime));
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
class RedisArrayCacheTest extends AbstractRedisCacheTest
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setupBeforeClass();
|
||||
if (!class_exists('RedisArray')) {
|
||||
self::markTestSkipped('The RedisArray class is required.');
|
||||
}
|
||||
self::$redis = new \RedisArray([getenv('REDIS_HOST')], ['lazy_connect' => true]);
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
use Symfony\Component\Cache\Simple\RedisCache;
|
||||
|
||||
class RedisCacheTest extends AbstractRedisCacheTest
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setupBeforeClass();
|
||||
self::$redis = RedisCache::createConnection('redis://'.getenv('REDIS_HOST'));
|
||||
}
|
||||
|
||||
public function testCreateConnection()
|
||||
{
|
||||
$redisHost = getenv('REDIS_HOST');
|
||||
|
||||
$redis = RedisCache::createConnection('redis://'.$redisHost);
|
||||
$this->assertInstanceOf(\Redis::class, $redis);
|
||||
$this->assertTrue($redis->isConnected());
|
||||
$this->assertSame(0, $redis->getDbNum());
|
||||
|
||||
$redis = RedisCache::createConnection('redis://'.$redisHost.'/2');
|
||||
$this->assertSame(2, $redis->getDbNum());
|
||||
|
||||
$redis = RedisCache::createConnection('redis://'.$redisHost, ['timeout' => 3]);
|
||||
$this->assertEquals(3, $redis->getTimeout());
|
||||
|
||||
$redis = RedisCache::createConnection('redis://'.$redisHost.'?timeout=4');
|
||||
$this->assertEquals(4, $redis->getTimeout());
|
||||
|
||||
$redis = RedisCache::createConnection('redis://'.$redisHost, ['read_timeout' => 5]);
|
||||
$this->assertEquals(5, $redis->getReadTimeout());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideFailedCreateConnection
|
||||
*/
|
||||
public function testFailedCreateConnection($dsn)
|
||||
{
|
||||
$this->expectException('Symfony\Component\Cache\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Redis connection failed');
|
||||
RedisCache::createConnection($dsn);
|
||||
}
|
||||
|
||||
public function provideFailedCreateConnection()
|
||||
{
|
||||
return [
|
||||
['redis://localhost:1234'],
|
||||
['redis://foo@localhost'],
|
||||
['redis://localhost/123'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInvalidCreateConnection
|
||||
*/
|
||||
public function testInvalidCreateConnection($dsn)
|
||||
{
|
||||
$this->expectException('Symfony\Component\Cache\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Invalid Redis DSN');
|
||||
RedisCache::createConnection($dsn);
|
||||
}
|
||||
|
||||
public function provideInvalidCreateConnection()
|
||||
{
|
||||
return [
|
||||
['foo://localhost'],
|
||||
['redis://'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
class RedisClusterCacheTest extends AbstractRedisCacheTest
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
if (!class_exists('RedisCluster')) {
|
||||
self::markTestSkipped('The RedisCluster class is required.');
|
||||
}
|
||||
if (!$hosts = getenv('REDIS_CLUSTER_HOSTS')) {
|
||||
self::markTestSkipped('REDIS_CLUSTER_HOSTS env var is not defined.');
|
||||
}
|
||||
|
||||
self::$redis = new \RedisCluster(null, explode(' ', $hosts));
|
||||
}
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
<?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\Simple;
|
||||
|
||||
use Symfony\Component\Cache\Simple\FilesystemCache;
|
||||
use Symfony\Component\Cache\Simple\TraceableCache;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class TraceableCacheTest extends CacheTestCase
|
||||
{
|
||||
protected $skippedTests = [
|
||||
'testPrune' => 'TraceableCache just proxies',
|
||||
];
|
||||
|
||||
public function createSimpleCache($defaultLifetime = 0)
|
||||
{
|
||||
return new TraceableCache(new FilesystemCache('', $defaultLifetime));
|
||||
}
|
||||
|
||||
public function testGetMissTrace()
|
||||
{
|
||||
$pool = $this->createSimpleCache();
|
||||
$pool->get('k');
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(1, $calls);
|
||||
|
||||
$call = $calls[0];
|
||||
$this->assertSame('get', $call->name);
|
||||
$this->assertSame(['k' => false], $call->result);
|
||||
$this->assertSame(0, $call->hits);
|
||||
$this->assertSame(1, $call->misses);
|
||||
$this->assertNotEmpty($call->start);
|
||||
$this->assertNotEmpty($call->end);
|
||||
}
|
||||
|
||||
public function testGetHitTrace()
|
||||
{
|
||||
$pool = $this->createSimpleCache();
|
||||
$pool->set('k', 'foo');
|
||||
$pool->get('k');
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(2, $calls);
|
||||
|
||||
$call = $calls[1];
|
||||
$this->assertSame(1, $call->hits);
|
||||
$this->assertSame(0, $call->misses);
|
||||
}
|
||||
|
||||
public function testGetMultipleMissTrace()
|
||||
{
|
||||
$pool = $this->createSimpleCache();
|
||||
$pool->set('k1', 123);
|
||||
$values = $pool->getMultiple(['k0', 'k1']);
|
||||
foreach ($values as $value) {
|
||||
}
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(2, $calls);
|
||||
|
||||
$call = $calls[1];
|
||||
$this->assertSame('getMultiple', $call->name);
|
||||
$this->assertSame(['k1' => true, 'k0' => false], $call->result);
|
||||
$this->assertSame(1, $call->misses);
|
||||
$this->assertNotEmpty($call->start);
|
||||
$this->assertNotEmpty($call->end);
|
||||
}
|
||||
|
||||
public function testHasMissTrace()
|
||||
{
|
||||
$pool = $this->createSimpleCache();
|
||||
$pool->has('k');
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(1, $calls);
|
||||
|
||||
$call = $calls[0];
|
||||
$this->assertSame('has', $call->name);
|
||||
$this->assertSame(['k' => false], $call->result);
|
||||
$this->assertNotEmpty($call->start);
|
||||
$this->assertNotEmpty($call->end);
|
||||
}
|
||||
|
||||
public function testHasHitTrace()
|
||||
{
|
||||
$pool = $this->createSimpleCache();
|
||||
$pool->set('k', 'foo');
|
||||
$pool->has('k');
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(2, $calls);
|
||||
|
||||
$call = $calls[1];
|
||||
$this->assertSame('has', $call->name);
|
||||
$this->assertSame(['k' => true], $call->result);
|
||||
$this->assertNotEmpty($call->start);
|
||||
$this->assertNotEmpty($call->end);
|
||||
}
|
||||
|
||||
public function testDeleteTrace()
|
||||
{
|
||||
$pool = $this->createSimpleCache();
|
||||
$pool->delete('k');
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(1, $calls);
|
||||
|
||||
$call = $calls[0];
|
||||
$this->assertSame('delete', $call->name);
|
||||
$this->assertSame(['k' => true], $call->result);
|
||||
$this->assertSame(0, $call->hits);
|
||||
$this->assertSame(0, $call->misses);
|
||||
$this->assertNotEmpty($call->start);
|
||||
$this->assertNotEmpty($call->end);
|
||||
}
|
||||
|
||||
public function testDeleteMultipleTrace()
|
||||
{
|
||||
$pool = $this->createSimpleCache();
|
||||
$arg = ['k0', 'k1'];
|
||||
$pool->deleteMultiple($arg);
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(1, $calls);
|
||||
|
||||
$call = $calls[0];
|
||||
$this->assertSame('deleteMultiple', $call->name);
|
||||
$this->assertSame(['keys' => $arg, 'result' => true], $call->result);
|
||||
$this->assertSame(0, $call->hits);
|
||||
$this->assertSame(0, $call->misses);
|
||||
$this->assertNotEmpty($call->start);
|
||||
$this->assertNotEmpty($call->end);
|
||||
}
|
||||
|
||||
public function testTraceSetTrace()
|
||||
{
|
||||
$pool = $this->createSimpleCache();
|
||||
$pool->set('k', 'foo');
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(1, $calls);
|
||||
|
||||
$call = $calls[0];
|
||||
$this->assertSame('set', $call->name);
|
||||
$this->assertSame(['k' => true], $call->result);
|
||||
$this->assertSame(0, $call->hits);
|
||||
$this->assertSame(0, $call->misses);
|
||||
$this->assertNotEmpty($call->start);
|
||||
$this->assertNotEmpty($call->end);
|
||||
}
|
||||
|
||||
public function testSetMultipleTrace()
|
||||
{
|
||||
$pool = $this->createSimpleCache();
|
||||
$pool->setMultiple(['k' => 'foo']);
|
||||
$calls = $pool->getCalls();
|
||||
$this->assertCount(1, $calls);
|
||||
|
||||
$call = $calls[0];
|
||||
$this->assertSame('setMultiple', $call->name);
|
||||
$this->assertSame(['keys' => ['k'], 'result' => true], $call->result);
|
||||
$this->assertSame(0, $call->hits);
|
||||
$this->assertSame(0, $call->misses);
|
||||
$this->assertNotEmpty($call->start);
|
||||
$this->assertNotEmpty($call->end);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?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\Traits;
|
||||
|
||||
trait PdoPruneableTrait
|
||||
{
|
||||
protected function isPruned($cache, $name)
|
||||
{
|
||||
$o = new \ReflectionObject($cache);
|
||||
|
||||
if (!$o->hasMethod('getConnection')) {
|
||||
self::fail('Cache does not have "getConnection()" method.');
|
||||
}
|
||||
|
||||
$getPdoConn = $o->getMethod('getConnection');
|
||||
$getPdoConn->setAccessible(true);
|
||||
|
||||
/** @var \Doctrine\DBAL\Statement $select */
|
||||
$select = $getPdoConn->invoke($cache)->prepare('SELECT 1 FROM cache_items WHERE item_id LIKE :id');
|
||||
$select->bindValue(':id', sprintf('%%%s', $name));
|
||||
$select->execute();
|
||||
|
||||
return 0 === \count($select->fetchAll(\PDO::FETCH_COLUMN));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user