public function testOutputMongoCache()
{
list($ready, $collection) = $this->_prepareMongo();
if (!$ready) {
return false;
}
$time = date('H:i:s');
$frontCache = new Phalcon\Cache\Frontend\Output(array('lifetime' => 3));
$cache = new Phalcon\Cache\Backend\Mongo($frontCache, array('server' => 'mongodb://localhost', 'db' => 'phalcon_test', 'collection' => 'caches'));
ob_start();
//First time cache
$content = $cache->start('test-output');
$this->assertTrue($content === null);
echo $time;
$cache->save(null, null, null, true);
$obContent = ob_get_contents();
ob_end_clean();
$this->assertEquals($time, $obContent);
$document = $collection->findOne(array('key' => 'test-output'));
$this->assertTrue(is_array($document));
$this->assertEquals($time, $document['data']);
//Expect same cache
$content = $cache->start('test-output');
$this->assertFalse($content === null);
$document = $collection->findOne(array('key' => 'test-output'));
$this->assertTrue(is_array($document));
$this->assertEquals($time, $document['data']);
//Query keys
$keys = $cache->queryKeys();
$this->assertEquals($keys, array(0 => 'test-output'));
//Exists
$this->assertTrue($cache->exists('test-output'));
//Delete entry from cache
$this->assertTrue($cache->delete('test-output'));
}