|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\Common\Cache; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Cache\Cache; |
|
6
|
|
|
use Doctrine\Common\Cache\MongoDBCache; |
|
7
|
|
|
use MongoClient; |
|
8
|
|
|
use MongoCollection; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @requires extension mongo |
|
12
|
|
|
*/ |
|
13
|
|
|
class MongoDBCacheTest extends CacheTest |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var MongoCollection |
|
17
|
|
|
*/ |
|
18
|
|
|
private $collection; |
|
19
|
|
|
|
|
20
|
|
|
protected function setUp() |
|
21
|
|
|
{ |
|
22
|
|
|
if ( ! version_compare(phpversion('mongo'), '1.3.0', '>=')) { |
|
23
|
|
|
$this->markTestSkipped('Mongo >= 1.3.0 is required.'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
$mongo = new MongoClient(); |
|
27
|
|
|
$this->collection = $mongo->selectCollection('doctrine_common_cache', 'test'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
protected function tearDown() |
|
31
|
|
|
{ |
|
32
|
|
|
if ($this->collection instanceof MongoCollection) { |
|
33
|
|
|
$this->collection->drop(); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testGetStats() |
|
38
|
|
|
{ |
|
39
|
|
|
$cache = $this->_getCacheDriver(); |
|
40
|
|
|
$stats = $cache->getStats(); |
|
41
|
|
|
|
|
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]); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @group 108 |
|
51
|
|
|
*/ |
|
52
|
|
|
public function testMongoCursorExceptionsDoNotBubbleUp() |
|
53
|
|
|
{ |
|
54
|
|
|
/* @var $collection \MongoCollection|\PHPUnit_Framework_MockObject_MockObject */ |
|
55
|
|
|
$collection = $this->getMock('MongoCollection', array(), array(), '', false); |
|
56
|
|
|
|
|
57
|
|
|
$collection->expects(self::once())->method('update')->willThrowException(new \MongoCursorException()); |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
$cache = new MongoDBCache($collection); |
|
60
|
|
|
|
|
61
|
|
|
self::assertFalse($cache->save('foo', 'bar')); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
protected function _getCacheDriver() |
|
65
|
|
|
{ |
|
66
|
|
|
return new MongoDBCache($this->collection); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: