3 namespace Doctrine\Tests\Common\Cache;
5 use Doctrine\Common\Cache\Cache;
6 use Doctrine\Common\Cache\MongoDBCache;
11 * @requires extension mongo
13 class MongoDBCacheTest extends CacheTest
16 * @var MongoCollection
20 protected function setUp()
22 if ( ! version_compare(phpversion('mongo'), '1.3.0', '>=')) {
23 $this->markTestSkipped('Mongo >= 1.3.0 is required.');
26 $mongo = new MongoClient();
27 $this->collection = $mongo->selectCollection('doctrine_common_cache', 'test');
30 protected function tearDown()
32 if ($this->collection instanceof MongoCollection) {
33 $this->collection->drop();
37 public function testGetStats()
39 $cache = $this->_getCacheDriver();
40 $stats = $cache->getStats();
42 $this->assertNull($stats[Cache::STATS_HITS]);
43 $this->assertNull($stats[Cache::STATS_MISSES]);
44 $this->assertGreaterThan(0, $stats[Cache::STATS_UPTIME]);
45 $this->assertEquals(0, $stats[Cache::STATS_MEMORY_USAGE]);
46 $this->assertNull($stats[Cache::STATS_MEMORY_AVAILABLE]);
52 public function testMongoCursorExceptionsDoNotBubbleUp()
54 /* @var $collection \MongoCollection|\PHPUnit_Framework_MockObject_MockObject */
55 $collection = $this->getMock('MongoCollection', array(), array(), '', false);
57 $collection->expects(self::once())->method('update')->willThrowException(new \MongoCursorException());
59 $cache = new MongoDBCache($collection);
61 self::assertFalse($cache->save('foo', 'bar'));
64 protected function _getCacheDriver()
66 return new MongoDBCache($this->collection);