scratch
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/ApcCacheTest.php |
---|
@@ -0,0 +1,28 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\ApcCache; |
/** |
* @requires extension apc |
*/ |
class ApcCacheTest extends CacheTest |
{ |
protected function setUp() |
{ |
if (!ini_get('apc.enable_cli')) { |
$this->markTestSkipped('APC must be enabled for the CLI with the ini setting apc.enable_cli=1'); |
} |
} |
protected function _getCacheDriver() |
{ |
return new ApcCache(); |
} |
public function testLifetime() |
{ |
$this->markTestSkipped('The APC cache TTL is not working in a single process/request. See https://bugs.php.net/bug.php?id=58084'); |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/ApcuCacheTest.php |
---|
@@ -0,0 +1,28 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\ApcuCache; |
/** |
* @requires extension apcu |
*/ |
class ApcuCacheTest extends CacheTest |
{ |
protected function setUp() |
{ |
if (!ini_get('apc.enable_cli')) { |
$this->markTestSkipped('APC must be enabled for the CLI with the ini setting apc.enable_cli=1'); |
} |
} |
protected function _getCacheDriver() |
{ |
return new ApcuCache(); |
} |
public function testLifetime() |
{ |
$this->markTestSkipped('The APC cache TTL is not working in a single process/request. See https://bugs.php.net/bug.php?id=58084'); |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/ArrayCacheTest.php |
---|
@@ -0,0 +1,52 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\ArrayCache; |
use Doctrine\Common\Cache\Cache; |
class ArrayCacheTest extends CacheTest |
{ |
protected function _getCacheDriver() |
{ |
return new ArrayCache(); |
} |
public function testGetStats() |
{ |
$cache = $this->_getCacheDriver(); |
$cache->fetch('test1'); |
$cache->fetch('test2'); |
$cache->fetch('test3'); |
$cache->save('test1', 123); |
$cache->save('test2', 123); |
$cache->fetch('test1'); |
$cache->fetch('test2'); |
$cache->fetch('test3'); |
$stats = $cache->getStats(); |
$this->assertEquals(2, $stats[Cache::STATS_HITS]); |
$this->assertEquals(5, $stats[Cache::STATS_MISSES]); // +1 for internal call to DoctrineNamespaceCacheKey |
$this->assertNotNull($stats[Cache::STATS_UPTIME]); |
$this->assertNull($stats[Cache::STATS_MEMORY_USAGE]); |
$this->assertNull($stats[Cache::STATS_MEMORY_AVAILABLE]); |
$cache->delete('test1'); |
$cache->delete('test2'); |
$cache->fetch('test1'); |
$cache->fetch('test2'); |
$cache->fetch('test3'); |
$stats = $cache->getStats(); |
$this->assertEquals(2, $stats[Cache::STATS_HITS]); |
$this->assertEquals(8, $stats[Cache::STATS_MISSES]); // +1 for internal call to DoctrineNamespaceCacheKey |
} |
protected function isSharedStorage() |
{ |
return false; |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/BaseFileCacheTest.php |
---|
@@ -0,0 +1,155 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\FileCache; |
use RecursiveDirectoryIterator; |
use RecursiveIteratorIterator; |
abstract class BaseFileCacheTest extends CacheTest |
{ |
protected $directory; |
protected function setUp() |
{ |
do { |
$this->directory = sys_get_temp_dir() . '/doctrine_cache_'. uniqid(); |
} while (file_exists($this->directory)); |
} |
protected function tearDown() |
{ |
if ( ! is_dir($this->directory)) { |
return; |
} |
$iterator = new RecursiveDirectoryIterator($this->directory); |
foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) { |
if ($file->isFile()) { |
@unlink($file->getRealPath()); |
} elseif ($file->isDir()) { |
@rmdir($file->getRealPath()); |
} |
} |
@rmdir($this->directory); |
} |
public function testFlushAllRemovesBalancingDirectories() |
{ |
$cache = $this->_getCacheDriver(); |
$this->assertTrue($cache->save('key1', 1)); |
$this->assertTrue($cache->save('key2', 2)); |
$this->assertTrue($cache->flushAll()); |
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->directory, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); |
$this->assertCount(0, $iterator); |
} |
protected function isSharedStorage() |
{ |
return false; |
} |
public function getPathLengthsToTest() |
{ |
// Windows officially supports 260 bytes including null terminator |
// 258 bytes available to use due to php bug #70943 |
// Windows officially supports 260 bytes including null terminator |
// 259 characters is too large due to PHP bug (https://bugs.php.net/bug.php?id=70943) |
// 260 characters is too large - null terminator is included in allowable length |
return array( |
array(257, false), |
array(258, false), |
array(259, true), |
array(260, true) |
); |
} |
private static function getBasePathForWindowsPathLengthTests($pathLength) |
{ |
return FileCacheTest::getBasePathForWindowsPathLengthTests($pathLength); |
} |
/** |
* @param int $length |
* @param string $basePath |
* |
* @return array |
*/ |
private static function getKeyAndPathFittingLength($length, $basePath) |
{ |
$baseDirLength = strlen($basePath); |
$extensionLength = strlen('.doctrine.cache'); |
$directoryLength = strlen(DIRECTORY_SEPARATOR . 'aa' . DIRECTORY_SEPARATOR); |
$namespaceAndBracketLength = strlen(bin2hex("[][1]")); |
$keyLength = $length |
- ($baseDirLength |
+ $extensionLength |
+ $directoryLength |
+ $namespaceAndBracketLength); |
$key = str_repeat('a', floor($keyLength / 2)); |
$namespacedKey = '[' . $key . '][1]'; |
$keyHash = hash('sha256', $namespacedKey); |
$keyPath = $basePath |
. DIRECTORY_SEPARATOR |
. substr($keyHash, 0, 2) |
. DIRECTORY_SEPARATOR |
. bin2hex($namespacedKey) |
. '.doctrine.cache'; |
$hashedKeyPath = $basePath |
. DIRECTORY_SEPARATOR |
. substr($keyHash, 0, 2) |
. DIRECTORY_SEPARATOR |
. '_' . $keyHash |
. '.doctrine.cache'; |
return array($key, $keyPath, $hashedKeyPath); |
} |
/** |
* @dataProvider getPathLengthsToTest |
* |
* @param int $length |
* @param bool $pathShouldBeHashed |
*/ |
public function testWindowsPathLengthLimitIsCorrectlyHandled($length, $pathShouldBeHashed) |
{ |
$this->directory = self::getBasePathForWindowsPathLengthTests($length); |
list($key, $keyPath, $hashedKeyPath) = self::getKeyAndPathFittingLength($length, $this->directory); |
$this->assertEquals($length, strlen($keyPath), 'Unhashed path should be of correct length.'); |
$cacheClass = get_class($this->_getCacheDriver()); |
/* @var $cache \Doctrine\Common\Cache\FileCache */ |
$cache = new $cacheClass($this->directory, '.doctrine.cache'); |
// Trick it into thinking this is windows. |
$reflClass = new \ReflectionClass(FileCache::class); |
$reflProp = $reflClass->getProperty('isRunningOnWindows'); |
$reflProp->setAccessible(true); |
$reflProp->setValue($cache, true); |
$reflProp->setAccessible(false); |
$value = uniqid('value', true); |
$cache->save($key, $value); |
$this->assertEquals($value, $cache->fetch($key)); |
if ($pathShouldBeHashed) { |
$this->assertFileExists($hashedKeyPath, 'Path generated for key should be hashed.'); |
unlink($hashedKeyPath); |
} else { |
$this->assertFileExists($keyPath, 'Path generated for key should not be hashed.'); |
unlink($keyPath); |
} |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/CacheProviderTest.php |
---|
@@ -0,0 +1,103 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
class CacheProviderTest extends \Doctrine\Tests\DoctrineTestCase |
{ |
public function testFetchMultiWillFilterNonRequestedKeys() |
{ |
/* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */ |
$cache = $this->getMockForAbstractClass( |
'Doctrine\Common\Cache\CacheProvider', |
array(), |
'', |
true, |
true, |
true, |
array('doFetchMultiple') |
); |
$cache |
->expects($this->once()) |
->method('doFetchMultiple') |
->will($this->returnValue(array( |
'[foo][1]' => 'bar', |
'[bar][1]' => 'baz', |
'[baz][1]' => 'tab', |
))); |
$this->assertEquals( |
array('foo' => 'bar', 'bar' => 'baz'), |
$cache->fetchMultiple(array('foo', 'bar')) |
); |
} |
public function testFailedDeleteAllDoesNotChangeNamespaceVersion() |
{ |
/* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */ |
$cache = $this->getMockForAbstractClass( |
'Doctrine\Common\Cache\CacheProvider', |
array(), |
'', |
true, |
true, |
true, |
array('doFetch', 'doSave', 'doContains') |
); |
$cache |
->expects($this->once()) |
->method('doFetch') |
->with('DoctrineNamespaceCacheKey[]') |
->will($this->returnValue(false)); |
// doSave is only called once from deleteAll as we do not need to persist the default version in getNamespaceVersion() |
$cache |
->expects($this->once()) |
->method('doSave') |
->with('DoctrineNamespaceCacheKey[]') |
->will($this->returnValue(false)); |
// After a failed deleteAll() the local namespace version is not increased (still 1). Otherwise all data written afterwards |
// would be lost outside the current instance. |
$cache |
->expects($this->once()) |
->method('doContains') |
->with('[key][1]') |
->will($this->returnValue(true)); |
$this->assertFalse($cache->deleteAll(), 'deleteAll() returns false when saving the namespace version fails'); |
$cache->contains('key'); |
} |
public function testSaveMultipleNoFail() |
{ |
/* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */ |
$cache = $this->getMockForAbstractClass( |
'Doctrine\Common\Cache\CacheProvider', |
array(), |
'', |
true, |
true, |
true, |
array('doSave') |
); |
$cache |
->expects($this->at(1)) |
->method('doSave') |
->with('[kerr][1]', 'verr', 0) |
->will($this->returnValue(false)); |
$cache |
->expects($this->at(2)) |
->method('doSave') |
->with('[kok][1]', 'vok', 0) |
->will($this->returnValue(true)); |
$cache->saveMultiple(array( |
'kerr' => 'verr', |
'kok' => 'vok', |
)); |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/CacheTest.php |
---|
@@ -0,0 +1,463 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\Cache; |
use ArrayObject; |
abstract class CacheTest extends \Doctrine\Tests\DoctrineTestCase |
{ |
/** |
* @dataProvider provideDataToCache |
*/ |
public function testSetContainsFetchDelete($value) |
{ |
$cache = $this->_getCacheDriver(); |
// Test saving a value, checking if it exists, and fetching it back |
$this->assertTrue($cache->save('key', $value)); |
$this->assertTrue($cache->contains('key')); |
if (is_object($value)) { |
$this->assertEquals($value, $cache->fetch('key'), 'Objects retrieved from the cache must be equal but not necessarily the same reference'); |
} else { |
$this->assertSame($value, $cache->fetch('key'), 'Scalar and array data retrieved from the cache must be the same as the original, e.g. same type'); |
} |
// Test deleting a value |
$this->assertTrue($cache->delete('key')); |
$this->assertFalse($cache->contains('key')); |
$this->assertFalse($cache->fetch('key')); |
} |
/** |
* @dataProvider provideDataToCache |
*/ |
public function testUpdateExistingEntry($value) |
{ |
$cache = $this->_getCacheDriver(); |
$this->assertTrue($cache->save('key', 'old-value')); |
$this->assertTrue($cache->contains('key')); |
$this->assertTrue($cache->save('key', $value)); |
$this->assertTrue($cache->contains('key')); |
if (is_object($value)) { |
$this->assertEquals($value, $cache->fetch('key'), 'Objects retrieved from the cache must be equal but not necessarily the same reference'); |
} else { |
$this->assertSame($value, $cache->fetch('key'), 'Scalar and array data retrieved from the cache must be the same as the original, e.g. same type'); |
} |
} |
public function testCacheKeyIsCaseSensitive() |
{ |
$cache = $this->_getCacheDriver(); |
$this->assertTrue($cache->save('key', 'value')); |
$this->assertTrue($cache->contains('key')); |
$this->assertSame('value', $cache->fetch('key')); |
$this->assertFalse($cache->contains('KEY')); |
$this->assertFalse($cache->fetch('KEY')); |
$cache->delete('KEY'); |
$this->assertTrue($cache->contains('key', 'Deleting cache item with different case must not affect other cache item')); |
} |
public function testFetchMultiple() |
{ |
$cache = $this->_getCacheDriver(); |
$values = $this->provideDataToCache(); |
$saved = array(); |
foreach ($values as $key => $value) { |
$cache->save($key, $value[0]); |
$saved[$key] = $value[0]; |
} |
$keys = array_keys($saved); |
$this->assertEquals( |
$saved, |
$cache->fetchMultiple($keys), |
'Testing fetchMultiple with different data types' |
); |
$this->assertEquals( |
array_slice($saved, 0, 1), |
$cache->fetchMultiple(array_slice($keys, 0, 1)), |
'Testing fetchMultiple with a single key' |
); |
$keysWithNonExisting = array(); |
$keysWithNonExisting[] = 'non_existing1'; |
$keysWithNonExisting[] = $keys[0]; |
$keysWithNonExisting[] = 'non_existing2'; |
$keysWithNonExisting[] = $keys[1]; |
$keysWithNonExisting[] = 'non_existing3'; |
$this->assertEquals( |
array_slice($saved, 0, 2), |
$cache->fetchMultiple($keysWithNonExisting), |
'Testing fetchMultiple with a subset of keys and mixed with non-existing ones' |
); |
} |
public function testFetchMultipleWithNoKeys() |
{ |
$cache = $this->_getCacheDriver(); |
$this->assertSame(array(), $cache->fetchMultiple(array())); |
} |
public function testSaveMultiple() |
{ |
$cache = $this->_getCacheDriver(); |
$cache->deleteAll(); |
$data = array_map(function ($value) { |
return $value[0]; |
}, $this->provideDataToCache()); |
$this->assertTrue($cache->saveMultiple($data)); |
$keys = array_keys($data); |
$this->assertEquals($data, $cache->fetchMultiple($keys)); |
} |
public function provideDataToCache() |
{ |
$obj = new \stdClass(); |
$obj->foo = 'bar'; |
$obj2 = new \stdClass(); |
$obj2->bar = 'foo'; |
$obj2->obj = $obj; |
$obj->obj2 = $obj2; |
return array( |
'array' => array(array('one', 2, 3.01)), |
'string' => array('value'), |
'string_invalid_utf8' => array("\xc3\x28"), |
'string_null_byte' => array('with'."\0".'null char'), |
'integer' => array(1), |
'float' => array(1.5), |
'object' => array(new ArrayObject(array('one', 2, 3.01))), |
'object_recursive' => array($obj), |
'true' => array(true), |
// the following are considered FALSE in boolean context, but caches should still recognize their existence |
'null' => array(null), |
'false' => array(false), |
'array_empty' => array(array()), |
'string_zero' => array('0'), |
'integer_zero' => array(0), |
'float_zero' => array(0.0), |
'string_empty' => array(''), |
); |
} |
public function testDeleteIsSuccessfulWhenKeyDoesNotExist() |
{ |
$cache = $this->_getCacheDriver(); |
$cache->delete('key'); |
$this->assertFalse($cache->contains('key')); |
$this->assertTrue($cache->delete('key')); |
} |
public function testDeleteAll() |
{ |
$cache = $this->_getCacheDriver(); |
$this->assertTrue($cache->save('key1', 1)); |
$this->assertTrue($cache->save('key2', 2)); |
$this->assertTrue($cache->deleteAll()); |
$this->assertFalse($cache->contains('key1')); |
$this->assertFalse($cache->contains('key2')); |
} |
/** |
* @dataProvider provideCacheIds |
*/ |
public function testCanHandleSpecialCacheIds($id) |
{ |
$cache = $this->_getCacheDriver(); |
$this->assertTrue($cache->save($id, 'value')); |
$this->assertTrue($cache->contains($id)); |
$this->assertEquals('value', $cache->fetch($id)); |
$this->assertTrue($cache->delete($id)); |
$this->assertFalse($cache->contains($id)); |
$this->assertFalse($cache->fetch($id)); |
} |
public function testNoCacheIdCollisions() |
{ |
$cache = $this->_getCacheDriver(); |
$ids = $this->provideCacheIds(); |
// fill cache with each id having a different value |
foreach ($ids as $index => $id) { |
$cache->save($id[0], $index); |
} |
// then check value of each cache id |
foreach ($ids as $index => $id) { |
$value = $cache->fetch($id[0]); |
$this->assertNotFalse($value, sprintf('Failed to retrieve data for cache id "%s".', $id[0])); |
if ($index !== $value) { |
$this->fail(sprintf('Cache id "%s" collides with id "%s".', $id[0], $ids[$value][0])); |
} |
} |
} |
/** |
* Returns cache ids with special characters that should still work. |
* |
* For example, the characters :\/<>"*?| are not valid in Windows filenames. So they must be encoded properly. |
* Each cache id should be considered different from the others. |
* |
* @return array |
*/ |
public function provideCacheIds() |
{ |
return array( |
array(':'), |
array('\\'), |
array('/'), |
array('<'), |
array('>'), |
array('"'), |
array('*'), |
array('?'), |
array('|'), |
array('['), |
array(']'), |
array('ä'), |
array('a'), |
array('é'), |
array('e'), |
array('.'), // directory traversal |
array('..'), // directory traversal |
array('-'), |
array('_'), |
array('$'), |
array('%'), |
array(' '), |
array("\0"), |
array(''), |
array(str_repeat('a', 300)), // long key |
array(str_repeat('a', 113)), |
); |
} |
public function testLifetime() |
{ |
$cache = $this->_getCacheDriver(); |
$cache->save('expire', 'value', 1); |
$this->assertTrue($cache->contains('expire'), 'Data should not be expired yet'); |
// @TODO should more TTL-based tests pop up, so then we should mock the `time` API instead |
sleep(2); |
$this->assertFalse($cache->contains('expire'), 'Data should be expired'); |
} |
public function testNoExpire() |
{ |
$cache = $this->_getCacheDriver(); |
$cache->save('noexpire', 'value', 0); |
// @TODO should more TTL-based tests pop up, so then we should mock the `time` API instead |
sleep(1); |
$this->assertTrue($cache->contains('noexpire'), 'Data with lifetime of zero should not expire'); |
} |
public function testLongLifetime() |
{ |
$cache = $this->_getCacheDriver(); |
$cache->save('longlifetime', 'value', 30 * 24 * 3600 + 1); |
$this->assertTrue($cache->contains('longlifetime'), 'Data with lifetime > 30 days should be accepted'); |
} |
public function testDeleteAllAndNamespaceVersioningBetweenCaches() |
{ |
if ( ! $this->isSharedStorage()) { |
$this->markTestSkipped('The cache storage needs to be shared.'); |
} |
$cache1 = $this->_getCacheDriver(); |
$cache2 = $this->_getCacheDriver(); |
$this->assertTrue($cache1->save('key1', 1)); |
$this->assertTrue($cache2->save('key2', 2)); |
/* Both providers are initialized with the same namespace version, so |
* they can see entries set by each other. |
*/ |
$this->assertTrue($cache1->contains('key1')); |
$this->assertTrue($cache1->contains('key2')); |
$this->assertTrue($cache2->contains('key1')); |
$this->assertTrue($cache2->contains('key2')); |
/* Deleting all entries through one provider will only increment the |
* namespace version on that object (and in the cache itself, which new |
* instances will use to initialize). The second provider will retain |
* its original version and still see stale data. |
*/ |
$this->assertTrue($cache1->deleteAll()); |
$this->assertFalse($cache1->contains('key1')); |
$this->assertFalse($cache1->contains('key2')); |
$this->assertTrue($cache2->contains('key1')); |
$this->assertTrue($cache2->contains('key2')); |
/* A new cache provider should not see the deleted entries, since its |
* namespace version will be initialized. |
*/ |
$cache3 = $this->_getCacheDriver(); |
$this->assertFalse($cache3->contains('key1')); |
$this->assertFalse($cache3->contains('key2')); |
} |
public function testFlushAll() |
{ |
$cache = $this->_getCacheDriver(); |
$this->assertTrue($cache->save('key1', 1)); |
$this->assertTrue($cache->save('key2', 2)); |
$this->assertTrue($cache->flushAll()); |
$this->assertFalse($cache->contains('key1')); |
$this->assertFalse($cache->contains('key2')); |
} |
public function testFlushAllAndNamespaceVersioningBetweenCaches() |
{ |
if ( ! $this->isSharedStorage()) { |
$this->markTestSkipped('The cache storage needs to be shared.'); |
} |
$cache1 = $this->_getCacheDriver(); |
$cache2 = $this->_getCacheDriver(); |
/* Deleting all elements from the first provider should increment its |
* namespace version before saving the first entry. |
*/ |
$cache1->deleteAll(); |
$this->assertTrue($cache1->save('key1', 1)); |
/* The second provider will be initialized with the same namespace |
* version upon its first save operation. |
*/ |
$this->assertTrue($cache2->save('key2', 2)); |
/* Both providers have the same namespace version and can see entries |
* set by each other. |
*/ |
$this->assertTrue($cache1->contains('key1')); |
$this->assertTrue($cache1->contains('key2')); |
$this->assertTrue($cache2->contains('key1')); |
$this->assertTrue($cache2->contains('key2')); |
/* Flushing all entries through one cache will remove all entries from |
* the cache but leave their namespace version as-is. |
*/ |
$this->assertTrue($cache1->flushAll()); |
$this->assertFalse($cache1->contains('key1')); |
$this->assertFalse($cache1->contains('key2')); |
$this->assertFalse($cache2->contains('key1')); |
$this->assertFalse($cache2->contains('key2')); |
/* Inserting a new entry will use the same, incremented namespace |
* version, and it will be visible to both providers. |
*/ |
$this->assertTrue($cache1->save('key1', 1)); |
$this->assertTrue($cache1->contains('key1')); |
$this->assertTrue($cache2->contains('key1')); |
/* A new cache provider will be initialized with the original namespace |
* version and not share any visibility with the first two providers. |
*/ |
$cache3 = $this->_getCacheDriver(); |
$this->assertFalse($cache3->contains('key1')); |
$this->assertFalse($cache3->contains('key2')); |
$this->assertTrue($cache3->save('key3', 3)); |
$this->assertTrue($cache3->contains('key3')); |
} |
public function testNamespace() |
{ |
$cache = $this->_getCacheDriver(); |
$cache->setNamespace('ns1_'); |
$this->assertTrue($cache->save('key1', 1)); |
$this->assertTrue($cache->contains('key1')); |
$cache->setNamespace('ns2_'); |
$this->assertFalse($cache->contains('key1')); |
} |
public function testDeleteAllNamespace() |
{ |
$cache = $this->_getCacheDriver(); |
$cache->setNamespace('ns1'); |
$this->assertFalse($cache->contains('key1')); |
$cache->save('key1', 'test'); |
$this->assertTrue($cache->contains('key1')); |
$cache->setNamespace('ns2'); |
$this->assertFalse($cache->contains('key1')); |
$cache->save('key1', 'test'); |
$this->assertTrue($cache->contains('key1')); |
$cache->setNamespace('ns1'); |
$this->assertTrue($cache->contains('key1')); |
$cache->deleteAll(); |
$this->assertFalse($cache->contains('key1')); |
$cache->setNamespace('ns2'); |
$this->assertTrue($cache->contains('key1')); |
$cache->deleteAll(); |
$this->assertFalse($cache->contains('key1')); |
} |
/** |
* @group DCOM-43 |
*/ |
public function testGetStats() |
{ |
$cache = $this->_getCacheDriver(); |
$stats = $cache->getStats(); |
$this->assertArrayHasKey(Cache::STATS_HITS, $stats); |
$this->assertArrayHasKey(Cache::STATS_MISSES, $stats); |
$this->assertArrayHasKey(Cache::STATS_UPTIME, $stats); |
$this->assertArrayHasKey(Cache::STATS_MEMORY_USAGE, $stats); |
$this->assertArrayHasKey(Cache::STATS_MEMORY_AVAILABLE, $stats); |
} |
public function testSaveReturnsTrueWithAndWithoutTTlSet() |
{ |
$cache = $this->_getCacheDriver(); |
$cache->deleteAll(); |
$this->assertTrue($cache->save('without_ttl', 'without_ttl')); |
$this->assertTrue($cache->save('with_ttl', 'with_ttl', 3600)); |
} |
/** |
* Return whether multiple cache providers share the same storage. |
* |
* This is used for skipping certain tests for shared storage behavior. |
* |
* @return bool |
*/ |
protected function isSharedStorage() |
{ |
return true; |
} |
/** |
* @return \Doctrine\Common\Cache\CacheProvider |
*/ |
abstract protected function _getCacheDriver(); |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/ChainCacheTest.php |
---|
@@ -0,0 +1,99 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\ApcCache; |
use Doctrine\Common\Cache\ArrayCache; |
use Doctrine\Common\Cache\ChainCache; |
class ChainCacheTest extends CacheTest |
{ |
protected function _getCacheDriver() |
{ |
return new ChainCache(array(new ArrayCache())); |
} |
public function testLifetime() |
{ |
$this->markTestSkipped('The ChainCache test uses ArrayCache which does not implement TTL currently.'); |
} |
public function testGetStats() |
{ |
$cache = $this->_getCacheDriver(); |
$stats = $cache->getStats(); |
$this->assertInternalType('array', $stats); |
} |
public function testOnlyFetchFirstOne() |
{ |
$cache1 = new ArrayCache(); |
$cache2 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider'); |
$cache2->expects($this->never())->method('doFetch'); |
$chainCache = new ChainCache(array($cache1, $cache2)); |
$chainCache->save('id', 'bar'); |
$this->assertEquals('bar', $chainCache->fetch('id')); |
} |
public function testFetchPropagateToFastestCache() |
{ |
$cache1 = new ArrayCache(); |
$cache2 = new ArrayCache(); |
$cache2->save('bar', 'value'); |
$chainCache = new ChainCache(array($cache1, $cache2)); |
$this->assertFalse($cache1->contains('bar')); |
$result = $chainCache->fetch('bar'); |
$this->assertEquals('value', $result); |
$this->assertTrue($cache2->contains('bar')); |
} |
public function testNamespaceIsPropagatedToAllProviders() |
{ |
$cache1 = new ArrayCache(); |
$cache2 = new ArrayCache(); |
$chainCache = new ChainCache(array($cache1, $cache2)); |
$chainCache->setNamespace('bar'); |
$this->assertEquals('bar', $cache1->getNamespace()); |
$this->assertEquals('bar', $cache2->getNamespace()); |
} |
public function testDeleteToAllProviders() |
{ |
$cache1 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider'); |
$cache2 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider'); |
$cache1->expects($this->once())->method('doDelete'); |
$cache2->expects($this->once())->method('doDelete'); |
$chainCache = new ChainCache(array($cache1, $cache2)); |
$chainCache->delete('bar'); |
} |
public function testFlushToAllProviders() |
{ |
$cache1 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider'); |
$cache2 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider'); |
$cache1->expects($this->once())->method('doFlush'); |
$cache2->expects($this->once())->method('doFlush'); |
$chainCache = new ChainCache(array($cache1, $cache2)); |
$chainCache->flushAll(); |
} |
protected function isSharedStorage() |
{ |
return false; |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/CouchbaseCacheTest.php |
---|
@@ -0,0 +1,30 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Couchbase; |
use Doctrine\Common\Cache\CouchbaseCache; |
/** |
* @requires extension couchbase |
*/ |
class CouchbaseCacheTest extends CacheTest |
{ |
private $couchbase; |
protected function setUp() |
{ |
try { |
$this->couchbase = new Couchbase('127.0.0.1', 'Administrator', 'password', 'default'); |
} catch(Exception $ex) { |
$this->markTestSkipped('Could not instantiate the Couchbase cache because of: ' . $ex); |
} |
} |
protected function _getCacheDriver() |
{ |
$driver = new CouchbaseCache(); |
$driver->setCouchbase($this->couchbase); |
return $driver; |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/FileCacheTest.php |
---|
@@ -0,0 +1,268 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\Cache; |
/** |
* @group DCOM-101 |
*/ |
class FileCacheTest extends \Doctrine\Tests\DoctrineTestCase |
{ |
/** |
* @var \Doctrine\Common\Cache\FileCache |
*/ |
private $driver; |
protected function setUp() |
{ |
$this->driver = $this->getMock( |
'Doctrine\Common\Cache\FileCache', |
array('doFetch', 'doContains', 'doSave'), |
array(), '', false |
); |
} |
public function testFilenameShouldCreateThePathWithOneSubDirectory() |
{ |
$cache = $this->driver; |
$method = new \ReflectionMethod($cache, 'getFilename'); |
$key = 'item-key'; |
$expectedDir = array( |
'84', |
); |
$expectedDir = implode(DIRECTORY_SEPARATOR, $expectedDir); |
$method->setAccessible(true); |
$path = $method->invoke($cache, $key); |
$dirname = pathinfo($path, PATHINFO_DIRNAME); |
$this->assertEquals(DIRECTORY_SEPARATOR . $expectedDir, $dirname); |
} |
public function testFileExtensionCorrectlyEscaped() |
{ |
$driver1 = $this->getMock( |
'Doctrine\Common\Cache\FileCache', |
array('doFetch', 'doContains', 'doSave'), |
array(__DIR__, '.*') |
); |
$driver2 = $this->getMock( |
'Doctrine\Common\Cache\FileCache', |
array('doFetch', 'doContains', 'doSave'), |
array(__DIR__, '.php') |
); |
$doGetStats = new \ReflectionMethod($driver1, 'doGetStats'); |
$doGetStats->setAccessible(true); |
$stats1 = $doGetStats->invoke($driver1); |
$stats2 = $doGetStats->invoke($driver2); |
$this->assertSame(0, $stats1[Cache::STATS_MEMORY_USAGE]); |
$this->assertGreaterThan(0, $stats2[Cache::STATS_MEMORY_USAGE]); |
} |
/** |
* @group DCOM-266 |
*/ |
public function testFileExtensionSlashCorrectlyEscaped() |
{ |
$driver = $this->getMock( |
'Doctrine\Common\Cache\FileCache', |
array('doFetch', 'doContains', 'doSave'), |
array(__DIR__ . '/../', DIRECTORY_SEPARATOR . basename(__FILE__)) |
); |
$doGetStats = new \ReflectionMethod($driver, 'doGetStats'); |
$doGetStats->setAccessible(true); |
$stats = $doGetStats->invoke($driver); |
$this->assertGreaterThan(0, $stats[Cache::STATS_MEMORY_USAGE]); |
} |
public function testNonIntUmaskThrowsInvalidArgumentException() |
{ |
$this->setExpectedException('InvalidArgumentException'); |
$this->getMock( |
'Doctrine\Common\Cache\FileCache', |
array('doFetch', 'doContains', 'doSave'), |
array('', '', 'invalid') |
); |
} |
public function testGetDirectoryReturnsRealpathDirectoryString() |
{ |
$directory = __DIR__ . '/../'; |
$driver = $this->getMock( |
'Doctrine\Common\Cache\FileCache', |
array('doFetch', 'doContains', 'doSave'), |
array($directory) |
); |
$doGetDirectory = new \ReflectionMethod($driver, 'getDirectory'); |
$actualDirectory = $doGetDirectory->invoke($driver); |
$expectedDirectory = realpath($directory); |
$this->assertEquals($expectedDirectory, $actualDirectory); |
} |
public function testGetExtensionReturnsExtensionString() |
{ |
$directory = __DIR__ . '/../'; |
$extension = DIRECTORY_SEPARATOR . basename(__FILE__); |
$driver = $this->getMock( |
'Doctrine\Common\Cache\FileCache', |
array('doFetch', 'doContains', 'doSave'), |
array($directory, $extension) |
); |
$doGetExtension = new \ReflectionMethod($driver, 'getExtension'); |
$actualExtension = $doGetExtension->invoke($driver); |
$this->assertEquals($extension, $actualExtension); |
} |
const WIN_MAX_PATH_LEN = 258; |
public static function getBasePathForWindowsPathLengthTests($pathLength) |
{ |
// Not using __DIR__ because it can get screwed up when xdebug debugger is attached. |
$basePath = realpath(sys_get_temp_dir()) . '/' . uniqid('doctrine-cache', true); |
/** @noinspection MkdirRaceConditionInspection */ |
@mkdir($basePath); |
$basePath = realpath($basePath); |
// Test whether the desired path length is odd or even. |
$desiredPathLengthIsOdd = ($pathLength % 2) == 1; |
// If the cache key is not too long, the filecache codepath will add |
// a slash and bin2hex($key). The length of the added portion will be an odd number. |
// len(desired) = len(base path) + len(slash . bin2hex($key)) |
// odd = even + odd |
// even = odd + odd |
$basePathLengthShouldBeOdd = !$desiredPathLengthIsOdd; |
$basePathLengthIsOdd = (strlen($basePath) % 2) == 1; |
// If the base path needs to be odd or even where it is not, we add an odd number of |
// characters as a pad. In this case, we're adding '\aa' (or '/aa' depending on platform) |
// This is all to make it so that the key we're testing would result in |
// a path that is exactly the length we want to test IF the path length limit |
// were not in place in FileCache. |
if ($basePathLengthIsOdd != $basePathLengthShouldBeOdd) { |
$basePath .= DIRECTORY_SEPARATOR . "aa"; |
} |
return $basePath; |
} |
/** |
* @param int $length |
* @param string $basePath |
* |
* @return array |
*/ |
public static function getKeyAndPathFittingLength($length, $basePath) |
{ |
$baseDirLength = strlen($basePath); |
$extensionLength = strlen('.doctrine.cache'); |
$directoryLength = strlen(DIRECTORY_SEPARATOR . 'aa' . DIRECTORY_SEPARATOR); |
$keyLength = $length - ($baseDirLength + $extensionLength + $directoryLength); // - 1 because of slash |
$key = str_repeat('a', floor($keyLength / 2)); |
$keyHash = hash('sha256', $key); |
$keyPath = $basePath |
. DIRECTORY_SEPARATOR |
. substr($keyHash, 0, 2) |
. DIRECTORY_SEPARATOR |
. bin2hex($key) |
. '.doctrine.cache'; |
$hashedKeyPath = $basePath |
. DIRECTORY_SEPARATOR |
. substr($keyHash, 0, 2) |
. DIRECTORY_SEPARATOR |
. '_' . $keyHash |
. '.doctrine.cache'; |
return array($key, $keyPath, $hashedKeyPath); |
} |
public function getPathLengthsToTest() |
{ |
// Windows officially supports 260 bytes including null terminator |
// 259 characters is too large due to PHP bug (https://bugs.php.net/bug.php?id=70943) |
// 260 characters is too large - null terminator is included in allowable length |
return array( |
array(257, false), |
array(258, false), |
array(259, true), |
array(260, true) |
); |
} |
/** |
* @runInSeparateProcess |
* @dataProvider getPathLengthsToTest |
* |
* @covers \Doctrine\Common\Cache\FileCache::getFilename |
* |
* @param int $length |
* @param bool $pathShouldBeHashed |
*/ |
public function testWindowsPathLengthLimitationsAreCorrectlyRespected($length, $pathShouldBeHashed) |
{ |
if (! defined('PHP_WINDOWS_VERSION_BUILD')) { |
define('PHP_WINDOWS_VERSION_BUILD', 'Yes, this is the "usual suspect", with the usual limitations'); |
} |
$basePath = self::getBasePathForWindowsPathLengthTests($length); |
$fileCache = $this->getMockForAbstractClass( |
'Doctrine\Common\Cache\FileCache', |
array($basePath, '.doctrine.cache') |
); |
list($key, $keyPath, $hashedKeyPath) = self::getKeyAndPathFittingLength($length, $basePath); |
$getFileName = new \ReflectionMethod($fileCache, 'getFilename'); |
$getFileName->setAccessible(true); |
$this->assertEquals( |
$length, |
strlen($keyPath), |
sprintf('Path expected to be %d characters long is %d characters long', $length, strlen($keyPath)) |
); |
if ($pathShouldBeHashed) { |
$keyPath = $hashedKeyPath; |
} |
if ($pathShouldBeHashed) { |
$this->assertSame( |
$hashedKeyPath, |
$getFileName->invoke($fileCache, $key), |
'Keys should be hashed correctly if they are over the limit.' |
); |
} else { |
$this->assertSame( |
$keyPath, |
$getFileName->invoke($fileCache, $key), |
'Keys below limit of the allowed length are used directly, unhashed' |
); |
} |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/FilesystemCacheTest.php |
---|
@@ -0,0 +1,61 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\Cache; |
use Doctrine\Common\Cache\FilesystemCache; |
/** |
* @group DCOM-101 |
*/ |
class FilesystemCacheTest extends BaseFileCacheTest |
{ |
public function testGetStats() |
{ |
$cache = $this->_getCacheDriver(); |
$stats = $cache->getStats(); |
$this->assertNull($stats[Cache::STATS_HITS]); |
$this->assertNull($stats[Cache::STATS_MISSES]); |
$this->assertNull($stats[Cache::STATS_UPTIME]); |
$this->assertEquals(0, $stats[Cache::STATS_MEMORY_USAGE]); |
$this->assertGreaterThan(0, $stats[Cache::STATS_MEMORY_AVAILABLE]); |
} |
public function testCacheInSharedDirectoryIsPerExtension() |
{ |
$cache1 = new FilesystemCache($this->directory, '.foo'); |
$cache2 = new FilesystemCache($this->directory, '.bar'); |
$this->assertTrue($cache1->save('key1', 11)); |
$this->assertTrue($cache1->save('key2', 12)); |
$this->assertTrue($cache2->save('key1', 21)); |
$this->assertTrue($cache2->save('key2', 22)); |
$this->assertSame(11, $cache1->fetch('key1'), 'Cache value must not be influenced by a different cache in the same directory but different extension'); |
$this->assertSame(12, $cache1->fetch('key2')); |
$this->assertTrue($cache1->flushAll()); |
$this->assertFalse($cache1->fetch('key1'), 'flushAll() must delete all items with the current extension'); |
$this->assertFalse($cache1->fetch('key2')); |
$this->assertSame(21, $cache2->fetch('key1'), 'flushAll() must not remove items with a different extension in a shared directory'); |
$this->assertSame(22, $cache2->fetch('key2')); |
} |
public function testFlushAllWithNoExtension() |
{ |
$cache = new FilesystemCache($this->directory, ''); |
$this->assertTrue($cache->save('key1', 1)); |
$this->assertTrue($cache->save('key2', 2)); |
$this->assertTrue($cache->flushAll()); |
$this->assertFalse($cache->contains('key1')); |
$this->assertFalse($cache->contains('key2')); |
} |
protected function _getCacheDriver() |
{ |
return new FilesystemCache($this->directory); |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/MemcacheCacheTest.php |
---|
@@ -0,0 +1,59 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\MemcacheCache; |
use Memcache; |
/** |
* @requires extension memcache |
*/ |
class MemcacheCacheTest extends CacheTest |
{ |
private $memcache; |
protected function setUp() |
{ |
$this->memcache = new Memcache(); |
if (@$this->memcache->connect('localhost', 11211) === false) { |
unset($this->memcache); |
$this->markTestSkipped('Cannot connect to Memcache.'); |
} |
} |
protected function tearDown() |
{ |
if ($this->memcache instanceof Memcache) { |
$this->memcache->flush(); |
} |
} |
/** |
* {@inheritdoc} |
* |
* Memcache does not support " " and null byte as key so we remove them from the tests. |
*/ |
public function provideCacheIds() |
{ |
$ids = parent::provideCacheIds(); |
unset($ids[21], $ids[22]); |
return $ids; |
} |
public function testGetMemcacheReturnsInstanceOfMemcache() |
{ |
$this->assertInstanceOf('Memcache', $this->_getCacheDriver()->getMemcache()); |
} |
/** |
* {@inheritDoc} |
*/ |
protected function _getCacheDriver() |
{ |
$driver = new MemcacheCache(); |
$driver->setMemcache($this->memcache); |
return $driver; |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/MemcachedCacheTest.php |
---|
@@ -0,0 +1,61 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\MemcachedCache; |
use Memcached; |
/** |
* @requires extension memcached |
*/ |
class MemcachedCacheTest extends CacheTest |
{ |
private $memcached; |
protected function setUp() |
{ |
$this->memcached = new Memcached(); |
$this->memcached->setOption(Memcached::OPT_COMPRESSION, false); |
$this->memcached->addServer('127.0.0.1', 11211); |
if (@fsockopen('127.0.0.1', 11211) === false) { |
unset($this->memcached); |
$this->markTestSkipped('Cannot connect to Memcached.'); |
} |
} |
protected function tearDown() |
{ |
if ($this->memcached instanceof Memcached) { |
$this->memcached->flush(); |
} |
} |
/** |
* {@inheritdoc} |
* |
* Memcached does not support " ", null byte and very long keys so we remove them from the tests. |
*/ |
public function provideCacheIds() |
{ |
$ids = parent::provideCacheIds(); |
unset($ids[21], $ids[22], $ids[24]); |
return $ids; |
} |
public function testGetMemcachedReturnsInstanceOfMemcached() |
{ |
$this->assertInstanceOf('Memcached', $this->_getCacheDriver()->getMemcached()); |
} |
/** |
* {@inheritDoc} |
*/ |
protected function _getCacheDriver() |
{ |
$driver = new MemcachedCache(); |
$driver->setMemcached($this->memcached); |
return $driver; |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/MongoDBCacheTest.php |
---|
@@ -0,0 +1,68 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\Cache; |
use Doctrine\Common\Cache\MongoDBCache; |
use MongoClient; |
use MongoCollection; |
/** |
* @requires extension mongo |
*/ |
class MongoDBCacheTest extends CacheTest |
{ |
/** |
* @var MongoCollection |
*/ |
private $collection; |
protected function setUp() |
{ |
if ( ! version_compare(phpversion('mongo'), '1.3.0', '>=')) { |
$this->markTestSkipped('Mongo >= 1.3.0 is required.'); |
} |
$mongo = new MongoClient(); |
$this->collection = $mongo->selectCollection('doctrine_common_cache', 'test'); |
} |
protected function tearDown() |
{ |
if ($this->collection instanceof MongoCollection) { |
$this->collection->drop(); |
} |
} |
public function testGetStats() |
{ |
$cache = $this->_getCacheDriver(); |
$stats = $cache->getStats(); |
$this->assertNull($stats[Cache::STATS_HITS]); |
$this->assertNull($stats[Cache::STATS_MISSES]); |
$this->assertGreaterThan(0, $stats[Cache::STATS_UPTIME]); |
$this->assertEquals(0, $stats[Cache::STATS_MEMORY_USAGE]); |
$this->assertNull($stats[Cache::STATS_MEMORY_AVAILABLE]); |
} |
/** |
* @group 108 |
*/ |
public function testMongoCursorExceptionsDoNotBubbleUp() |
{ |
/* @var $collection \MongoCollection|\PHPUnit_Framework_MockObject_MockObject */ |
$collection = $this->getMock('MongoCollection', array(), array(), '', false); |
$collection->expects(self::once())->method('update')->willThrowException(new \MongoCursorException()); |
$cache = new MongoDBCache($collection); |
self::assertFalse($cache->save('foo', 'bar')); |
} |
protected function _getCacheDriver() |
{ |
return new MongoDBCache($this->collection); |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/PhpFileCacheTest.php |
---|
@@ -0,0 +1,98 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\Cache; |
use Doctrine\Common\Cache\PhpFileCache; |
/** |
* @group DCOM-101 |
*/ |
class PhpFileCacheTest extends BaseFileCacheTest |
{ |
public function provideDataToCache() |
{ |
$data = parent::provideDataToCache(); |
unset($data['object'], $data['object_recursive']); // PhpFileCache only allows objects that implement __set_state() and fully support var_export() |
if (PHP_VERSION_ID < 70002) { |
unset($data['float_zero']); // var_export exports float(0) as int(0): https://bugs.php.net/bug.php?id=66179 |
} |
return $data; |
} |
public function testImplementsSetState() |
{ |
$cache = $this->_getCacheDriver(); |
// Test save |
$cache->save('test_set_state', new SetStateClass(array(1,2,3))); |
//Test __set_state call |
$this->assertCount(0, SetStateClass::$values); |
// Test fetch |
$value = $cache->fetch('test_set_state'); |
$this->assertInstanceOf('Doctrine\Tests\Common\Cache\SetStateClass', $value); |
$this->assertEquals(array(1,2,3), $value->getValue()); |
//Test __set_state call |
$this->assertCount(1, SetStateClass::$values); |
// Test contains |
$this->assertTrue($cache->contains('test_set_state')); |
} |
public function testNotImplementsSetState() |
{ |
$cache = $this->_getCacheDriver(); |
$this->setExpectedException('InvalidArgumentException'); |
$cache->save('test_not_set_state', new NotSetStateClass(array(1,2,3))); |
} |
public function testGetStats() |
{ |
$cache = $this->_getCacheDriver(); |
$stats = $cache->getStats(); |
$this->assertNull($stats[Cache::STATS_HITS]); |
$this->assertNull($stats[Cache::STATS_MISSES]); |
$this->assertNull($stats[Cache::STATS_UPTIME]); |
$this->assertEquals(0, $stats[Cache::STATS_MEMORY_USAGE]); |
$this->assertGreaterThan(0, $stats[Cache::STATS_MEMORY_AVAILABLE]); |
} |
protected function _getCacheDriver() |
{ |
return new PhpFileCache($this->directory); |
} |
} |
class NotSetStateClass |
{ |
private $value; |
public function __construct($value) |
{ |
$this->value = $value; |
} |
public function getValue() |
{ |
return $this->value; |
} |
} |
class SetStateClass extends NotSetStateClass |
{ |
public static $values = array(); |
public static function __set_state($data) |
{ |
self::$values = $data; |
return new self($data['value']); |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/PredisCacheTest.php |
---|
@@ -0,0 +1,87 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\Cache; |
use Doctrine\Common\Cache\PredisCache; |
use Predis\Client; |
use Predis\Connection\ConnectionException; |
class PredisCacheTest extends CacheTest |
{ |
private $client; |
protected function setUp() |
{ |
if (!class_exists('Predis\Client')) { |
$this->markTestSkipped('Predis\Client is missing. Make sure to "composer install" to have all dev dependencies.'); |
} |
$this->client = new Client(); |
try { |
$this->client->connect(); |
} catch (ConnectionException $e) { |
$this->markTestSkipped('Cannot connect to Redis because of: ' . $e); |
} |
} |
public function testHitMissesStatsAreProvided() |
{ |
$cache = $this->_getCacheDriver(); |
$stats = $cache->getStats(); |
$this->assertNotNull($stats[Cache::STATS_HITS]); |
$this->assertNotNull($stats[Cache::STATS_MISSES]); |
} |
/** |
* @return PredisCache |
*/ |
protected function _getCacheDriver() |
{ |
return new PredisCache($this->client); |
} |
/** |
* {@inheritDoc} |
* |
* @dataProvider provideDataToCache |
*/ |
public function testSetContainsFetchDelete($value) |
{ |
if (array() === $value) { |
$this->markTestIncomplete( |
'Predis currently doesn\'t support saving empty array values. ' |
. 'See https://github.com/nrk/predis/issues/241' |
); |
} |
parent::testSetContainsFetchDelete($value); |
} |
/** |
* {@inheritDoc} |
* |
* @dataProvider provideDataToCache |
*/ |
public function testUpdateExistingEntry($value) |
{ |
if (array() === $value) { |
$this->markTestIncomplete( |
'Predis currently doesn\'t support saving empty array values. ' |
. 'See https://github.com/nrk/predis/issues/241' |
); |
} |
parent::testUpdateExistingEntry($value); |
} |
public function testAllowsGenericPredisClient() |
{ |
/* @var $predisClient \Predis\ClientInterface */ |
$predisClient = $this->getMock('Predis\\ClientInterface'); |
$this->assertInstanceOf('Doctrine\\Common\\Cache\\PredisCache', new PredisCache($predisClient)); |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/RedisCacheTest.php |
---|
@@ -0,0 +1,59 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\RedisCache; |
use Doctrine\Common\Cache\Cache; |
/** |
* @requires extension redis |
*/ |
class RedisCacheTest extends CacheTest |
{ |
private $_redis; |
protected function setUp() |
{ |
$this->_redis = new \Redis(); |
$ok = @$this->_redis->connect('127.0.0.1'); |
if (!$ok) { |
$this->markTestSkipped('Cannot connect to Redis.'); |
} |
} |
public function testHitMissesStatsAreProvided() |
{ |
$cache = $this->_getCacheDriver(); |
$stats = $cache->getStats(); |
$this->assertNotNull($stats[Cache::STATS_HITS]); |
$this->assertNotNull($stats[Cache::STATS_MISSES]); |
} |
public function testGetRedisReturnsInstanceOfRedis() |
{ |
$this->assertInstanceOf('Redis', $this->_getCacheDriver()->getRedis()); |
} |
public function testSerializerOptionWithOutIgbinaryExtension() |
{ |
if (defined('Redis::SERIALIZER_IGBINARY') && extension_loaded('igbinary')) { |
$this->markTestSkipped('Extension igbinary is loaded.'); |
} |
$this->assertEquals( |
\Redis::SERIALIZER_PHP, |
$this->_getCacheDriver()->getRedis()->getOption(\Redis::OPT_SERIALIZER) |
); |
} |
/** |
* {@inheritDoc} |
*/ |
protected function _getCacheDriver() |
{ |
$driver = new RedisCache(); |
$driver->setRedis($this->_redis); |
return $driver; |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/RiakCacheTest.php |
---|
@@ -0,0 +1,58 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Riak\Bucket; |
use Riak\Connection; |
use Riak\Exception; |
use Doctrine\Common\Cache\RiakCache; |
/** |
* RiakCache test |
* |
* @group Riak |
* @requires extension riak |
*/ |
class RiakCacheTest extends CacheTest |
{ |
/** |
* @var \Riak\Connection |
*/ |
private $connection; |
/** |
* @var \Riak\Bucket |
*/ |
private $bucket; |
protected function setUp() |
{ |
try { |
$this->connection = new Connection('127.0.0.1', 8087); |
$this->bucket = new Bucket($this->connection, 'test'); |
} catch (Exception\RiakException $e) { |
$this->markTestSkipped('Cannot connect to Riak.'); |
} |
} |
/** |
* {@inheritdoc} |
*/ |
public function testGetStats() |
{ |
$cache = $this->_getCacheDriver(); |
$stats = $cache->getStats(); |
$this->assertNull($stats); |
} |
/** |
* Retrieve RiakCache instance. |
* |
* @return \Doctrine\Common\Cache\RiakCache |
*/ |
protected function _getCacheDriver() |
{ |
return new RiakCache($this->bucket); |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/SQLite3CacheTest.php |
---|
@@ -0,0 +1,42 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\Cache; |
use Doctrine\Common\Cache\SQLite3Cache; |
use SQLite3; |
/** |
* @requires extension sqlite3 |
*/ |
class SQLite3Test extends CacheTest |
{ |
private $file; |
private $sqlite; |
protected function setUp() |
{ |
$this->file = tempnam(null, 'doctrine-cache-test-'); |
unlink($this->file); |
$this->sqlite = new SQLite3($this->file); |
} |
protected function tearDown() |
{ |
$this->sqlite = null; // DB must be closed before |
unlink($this->file); |
} |
public function testGetStats() |
{ |
$this->assertNull($this->_getCacheDriver()->getStats()); |
} |
/** |
* {@inheritDoc} |
*/ |
protected function _getCacheDriver() |
{ |
return new SQLite3Cache($this->sqlite, 'test_table'); |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/VoidCacheTest.php |
---|
@@ -0,0 +1,58 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\VoidCache; |
/** |
* @covers \Doctrine\Common\Cache\VoidCache |
*/ |
class VoidCacheTest extends \PHPUnit_Framework_TestCase |
{ |
public function testShouldAlwaysReturnFalseOnContains() |
{ |
$cache = new VoidCache(); |
$this->assertFalse($cache->contains('foo')); |
$this->assertFalse($cache->contains('bar')); |
} |
public function testShouldAlwaysReturnFalseOnFetch() |
{ |
$cache = new VoidCache(); |
$this->assertFalse($cache->fetch('foo')); |
$this->assertFalse($cache->fetch('bar')); |
} |
public function testShouldAlwaysReturnTrueOnSaveButNotStoreAnything() |
{ |
$cache = new VoidCache(); |
$this->assertTrue($cache->save('foo', 'fooVal')); |
$this->assertFalse($cache->contains('foo')); |
$this->assertFalse($cache->fetch('foo')); |
} |
public function testShouldAlwaysReturnTrueOnDelete() |
{ |
$cache = new VoidCache(); |
$this->assertTrue($cache->delete('foo')); |
} |
public function testShouldAlwaysReturnNullOnGetStatus() |
{ |
$cache = new VoidCache(); |
$this->assertNull($cache->getStats()); |
} |
public function testShouldAlwaysReturnTrueOnFlush() |
{ |
$cache = new VoidCache(); |
$this->assertTrue($cache->flushAll()); |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/WinCacheCacheTest.php |
---|
@@ -0,0 +1,16 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\WincacheCache; |
/** |
* @requires extension wincache |
*/ |
class WincacheCacheTest extends CacheTest |
{ |
protected function _getCacheDriver() |
{ |
return new WincacheCache(); |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/XcacheCacheTest.php |
---|
@@ -0,0 +1,16 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\XcacheCache; |
/** |
* @requires extension xcache |
*/ |
class XcacheCacheTest extends CacheTest |
{ |
protected function _getCacheDriver() |
{ |
return new XcacheCache(); |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/ZendDataCacheTest.php |
---|
@@ -0,0 +1,31 @@ |
<?php |
namespace Doctrine\Tests\Common\Cache; |
use Doctrine\Common\Cache\ZendDataCache; |
/** |
* @requires function zend_shm_cache_fetch |
*/ |
class ZendDataCacheTest extends CacheTest |
{ |
protected function setUp() |
{ |
if ('apache2handler' !== php_sapi_name()) { |
$this->markTestSkipped('Zend Data Cache only works in apache2handler SAPI.'); |
} |
} |
public function testGetStats() |
{ |
$cache = $this->_getCacheDriver(); |
$stats = $cache->getStats(); |
$this->assertNull($stats); |
} |
protected function _getCacheDriver() |
{ |
return new ZendDataCache(); |
} |
} |
/vendor/doctrine/cache/tests/Doctrine/Tests/DoctrineTestCase.php |
---|
@@ -0,0 +1,10 @@ |
<?php |
namespace Doctrine\Tests; |
/** |
* Base testcase class for all Doctrine testcases. |
*/ |
abstract class DoctrineTestCase extends \PHPUnit_Framework_TestCase |
{ |
} |
/vendor/doctrine/cache/tests/travis/php.ini |
---|
@@ -0,0 +1,7 @@ |
extension="mongo.so" |
extension="memcache.so" |
extension="memcached.so" |
extension="redis.so" |
apc.enabled=1 |
apc.enable_cli=1 |
/vendor/doctrine/cache/tests/travis/phpunit.travis.xml |
---|
@@ -0,0 +1,34 @@ |
<?xml version="1.0" encoding="UTF-8"?> |
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd" |
backupGlobals="false" |
colors="true" |
bootstrap="../../vendor/autoload.php" |
> |
<php> |
<ini name="error_reporting" value="-1" /> |
</php> |
<logging> |
<log type="coverage-clover" target="../../build/logs/clover.xml"/> |
</logging> |
<testsuites> |
<testsuite name="Doctrine Cache Test Suite"> |
<directory>../Doctrine/</directory> |
</testsuite> |
</testsuites> |
<filter> |
<whitelist> |
<directory>../../lib/Doctrine/</directory> |
</whitelist> |
</filter> |
<groups> |
<exclude> |
<group>performance</group> |
</exclude> |
</groups> |
</phpunit> |