|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Onoi\Cache\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Onoi\Cache\DoctrineCache; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @covers \Onoi\Cache\DoctrineCache |
|
9
|
|
|
* |
|
10
|
|
|
* @group onoi-cache |
|
11
|
|
|
* |
|
12
|
|
|
* @license GNU GPL v2+ |
|
13
|
|
|
* @since 1.0 |
|
14
|
|
|
* |
|
15
|
|
|
* @author mwjames |
|
16
|
|
|
*/ |
|
17
|
|
|
class DoctrineCacheTest extends \PHPUnit_Framework_TestCase { |
|
18
|
|
|
|
|
19
|
|
|
private $cache; |
|
20
|
|
|
|
|
21
|
|
|
protected function setUp() { |
|
22
|
|
|
parent::setUp(); |
|
23
|
|
|
|
|
24
|
|
|
if ( !interface_exists( '\Doctrine\Common\Cache\Cache' ) ) { |
|
25
|
|
|
$this->markTestSkipped( 'Doctrine cache interface is not available' ); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
$this->cache = $this->getMockBuilder( '\Doctrine\Common\Cache\Cache' ) |
|
29
|
|
|
->disableOriginalConstructor() |
|
30
|
|
|
->getMockForAbstractClass(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testCanConstruct() { |
|
34
|
|
|
|
|
35
|
|
|
$this->assertInstanceOf( |
|
36
|
|
|
'\Onoi\Cache\DoctrineCache', |
|
37
|
|
|
new DoctrineCache( $this->cache ) |
|
38
|
|
|
); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testGetName() { |
|
42
|
|
|
|
|
43
|
|
|
$instance = new DoctrineCache( $this->cache ); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertInternalType( |
|
46
|
|
|
'string', |
|
47
|
|
|
$instance->getName() |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testSave() { |
|
52
|
|
|
|
|
53
|
|
|
$this->cache->expects( $this->once() ) |
|
54
|
|
|
->method( 'save' ) |
|
55
|
|
|
->with( |
|
56
|
|
|
$this->equalTo( 'Foo' ), |
|
57
|
|
|
$this->anything(), |
|
58
|
|
|
$this->equalTo( 42 ) ); |
|
59
|
|
|
|
|
60
|
|
|
$instance = new DoctrineCache( $this->cache ); |
|
61
|
|
|
$instance->save( 'Foo', 'Bar', 42 ); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testDelete() { |
|
65
|
|
|
|
|
66
|
|
|
$this->cache->expects( $this->once() ) |
|
67
|
|
|
->method( 'delete' ) |
|
68
|
|
|
->with( |
|
69
|
|
|
$this->equalTo( 'Foo' ) ); |
|
70
|
|
|
|
|
71
|
|
|
$instance = new DoctrineCache( $this->cache ); |
|
72
|
|
|
$instance->delete( 'Foo' ); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function testContains() { |
|
76
|
|
|
|
|
77
|
|
|
$this->cache->expects( $this->once() ) |
|
78
|
|
|
->method( 'contains' ) |
|
79
|
|
|
->with( |
|
80
|
|
|
$this->equalTo( 'Foo' ) ); |
|
81
|
|
|
|
|
82
|
|
|
$instance = new DoctrineCache( $this->cache ); |
|
83
|
|
|
$instance->contains( 'Foo' ); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function testFetch() { |
|
87
|
|
|
|
|
88
|
|
|
$this->cache->expects( $this->once() ) |
|
89
|
|
|
->method( 'fetch' ) |
|
90
|
|
|
->with( |
|
91
|
|
|
$this->equalTo( 'Foo' ) ) |
|
92
|
|
|
->will( $this->returnValue( 'Bar' ) ); |
|
93
|
|
|
|
|
94
|
|
|
$instance = new DoctrineCache( $this->cache ); |
|
95
|
|
|
|
|
96
|
|
|
$this->assertEquals( |
|
97
|
|
|
'Bar', |
|
98
|
|
|
$instance->fetch( 'Foo' ) |
|
99
|
|
|
); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function testGetStats() { |
|
103
|
|
|
|
|
104
|
|
|
$this->cache->expects( $this->once() ) |
|
105
|
|
|
->method( 'getStats' ); |
|
106
|
|
|
|
|
107
|
|
|
$instance = new DoctrineCache( $this->cache ); |
|
108
|
|
|
|
|
109
|
|
|
$this->assertEquals( |
|
110
|
|
|
null, |
|
111
|
|
|
$instance->getStats() |
|
112
|
|
|
); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
} |
|
116
|
|
|
|