From a3d58e7b0d678bd7368d5c2937146bddf130c73f Mon Sep 17 00:00:00 2001 From: romanb Date: Wed, 15 Jul 2009 10:10:04 +0000 Subject: [PATCH] [2.0] Fixed array tests by removing tests for ArrayCache specific methods from the tests of other cache drivers. Some general API work on the cache interface. --- lib/Doctrine/Common/Cache/Cache.php | 34 +++++++++---------- lib/Doctrine/Common/Cache/MemcacheCache.php | 4 ++- .../Common/Collections/Collection.php | 8 ++--- .../Tests/Common/Cache/ApcCacheTest.php | 7 ---- .../Tests/Common/Cache/MemcacheCacheTest.php | 7 ---- .../Tests/Common/Cache/XcacheCacheTest.php | 7 ---- 6 files changed, 23 insertions(+), 44 deletions(-) diff --git a/lib/Doctrine/Common/Cache/Cache.php b/lib/Doctrine/Common/Cache/Cache.php index fc1672fa1..ebf417c3f 100644 --- a/lib/Doctrine/Common/Cache/Cache.php +++ b/lib/Doctrine/Common/Cache/Cache.php @@ -34,38 +34,36 @@ namespace Doctrine\Common\Cache; interface Cache { /** - * Test if a cache entry is available for the given id and (if yes) return it (false else). + * Fetches an entry from the cache. * - * Note : return value is always "string" (unserialization is done by the core not by the backend) - * - * @param string $id cache id - * @return string cached datas (or false) + * @param string $id cache id The id of the cache entry to fetch. + * @return string The cached data or FALSE, if no cache entry exists for the given id. */ - public function fetch($id); + function fetch($id); /** - * Test if a cache is available or not (for the given id) + * Test if an entry exists in the cache. * - * @param string $id cache id - * @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record + * @param string $id cache id The cache id of the entry to check for. + * @return boolean TRUE if a cache entry exists for the given cache id, FALSE otherwise. */ - public function contains($id); + function contains($id); /** * Puts data into the cache. * - * @param string $id cache id - * @param string $data data to cache - * @param int $lifeTime if != false, set a specific lifetime for this cache record (null => infinite lifeTime) - * @return boolean true if no problem + * @param string $id The cache id. + * @param string $data The cache entry/data. + * @param int $lifeTime The lifetime. If != false, sets a specific lifetime for this cache entry (null => infinite lifeTime). + * @return boolean TRUE if the entry was successfully stored in the cache, FALSE otherwise. */ - public function save($id, $data, $lifeTime = false); + function save($id, $data, $lifeTime = false); /** - * Remove a cache record + * Deletes a cache entry. * * @param string $id cache id - * @return boolean true if no problem + * @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise. */ - public function delete($id); + function delete($id); } \ No newline at end of file diff --git a/lib/Doctrine/Common/Cache/MemcacheCache.php b/lib/Doctrine/Common/Cache/MemcacheCache.php index 0f2625a2e..06984ff44 100644 --- a/lib/Doctrine/Common/Cache/MemcacheCache.php +++ b/lib/Doctrine/Common/Cache/MemcacheCache.php @@ -21,6 +21,8 @@ namespace Doctrine\Common\Cache; +use \Memcache; + /** * Memcache cache driver. * @@ -33,7 +35,7 @@ namespace Doctrine\Common\Cache; class MemcacheCache implements Cache { /** - * @var Memcache $_memcache memcache object + * @var Memcache */ private $_memcache; diff --git a/lib/Doctrine/Common/Collections/Collection.php b/lib/Doctrine/Common/Collections/Collection.php index 91321e1b6..567870e9f 100644 --- a/lib/Doctrine/Common/Collections/Collection.php +++ b/lib/Doctrine/Common/Collections/Collection.php @@ -28,8 +28,8 @@ use \ArrayAccess; use \ArrayIterator; /** - * A Collection is a thin wrapper around a php array. Think of it as an OO version - * of a plain array. + * A Collection is a thin wrapper around a php array. Like a php array it is essentially + * an ordered map. * * @author Roman S. Borschel * @since 2.0 @@ -42,10 +42,10 @@ class Collection implements Countable, IteratorAggregate, ArrayAccess * * @var array */ - protected $_elements = array(); + protected $_elements; /** - * Constructor accepts an array of $elements + * Initializes a new Collection. * * @param array $elements */ diff --git a/tests/Doctrine/Tests/Common/Cache/ApcCacheTest.php b/tests/Doctrine/Tests/Common/Cache/ApcCacheTest.php index efd8470bc..48df93ac8 100644 --- a/tests/Doctrine/Tests/Common/Cache/ApcCacheTest.php +++ b/tests/Doctrine/Tests/Common/Cache/ApcCacheTest.php @@ -28,16 +28,9 @@ class ApcCacheTest extends \Doctrine\Tests\DoctrineTestCase // Test fetch $this->assertEquals('testing this out', $cache->fetch('test_key')); - // Test count - $this->assertEquals(1, $cache->count()); - // Test delete $cache->save('test_key2', 'test2'); $cache->delete('test_key2'); $this->assertFalse($cache->contains('test_key2')); - - // Test delete all - $cache->deleteAll(); - $this->assertEquals(0, $cache->count()); } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/Common/Cache/MemcacheCacheTest.php b/tests/Doctrine/Tests/Common/Cache/MemcacheCacheTest.php index c1e78ea36..996b0baaa 100644 --- a/tests/Doctrine/Tests/Common/Cache/MemcacheCacheTest.php +++ b/tests/Doctrine/Tests/Common/Cache/MemcacheCacheTest.php @@ -28,16 +28,9 @@ class MemcacheCacheTest extends \Doctrine\Tests\DoctrineTestCase // Test fetch $this->assertEquals('testing this out', $cache->fetch('test_key')); - // Test count - $this->assertEquals(1, $cache->count()); - // Test delete $cache->save('test_key2', 'test2'); $cache->delete('test_key2'); $this->assertFalse($cache->contains('test_key2')); - - // Test delete all - $cache->deleteAll(); - $this->assertEquals(0, $cache->count()); } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/Common/Cache/XcacheCacheTest.php b/tests/Doctrine/Tests/Common/Cache/XcacheCacheTest.php index 1a0b983cb..bd97a6ec5 100644 --- a/tests/Doctrine/Tests/Common/Cache/XcacheCacheTest.php +++ b/tests/Doctrine/Tests/Common/Cache/XcacheCacheTest.php @@ -28,16 +28,9 @@ class XcacheCacheTest extends \Doctrine\Tests\DoctrineTestCase // Test fetch $this->assertEquals('testing this out', $cache->fetch('test_key')); - // Test count - $this->assertEquals(1, $cache->count()); - // Test delete $cache->save('test_key2', 'test2'); $cache->delete('test_key2'); $this->assertFalse($cache->contains('test_key2')); - - // Test delete all - $cache->deleteAll(); - $this->assertEquals(0, $cache->count()); } } \ No newline at end of file