1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MAdmin\Cache\Proxy; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit_Framework_TestCase |
14
|
|
|
{ |
15
|
|
|
private $mock; |
16
|
|
|
private $object; |
17
|
|
|
private $context; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
$this->context = \TestHelperMShop::getContext(); |
23
|
|
|
|
24
|
|
|
$this->mock = $this->getMockBuilder( '\\Aimeos\\MW\\Cache\\DB' ) |
25
|
|
|
->disableOriginalConstructor()->getMock(); |
26
|
|
|
|
27
|
|
|
$manager = $this->getMockBuilder( '\\Aimeos\\MAdmin\\Cache\\Manager\\Standard' ) |
28
|
|
|
->setConstructorArgs( array( $this->context ) )->getMock(); |
29
|
|
|
|
30
|
|
|
$manager->expects( $this->once() )->method( 'getCache' ) |
31
|
|
|
->will( $this->returnValue( $this->mock ) ); |
32
|
|
|
|
33
|
|
|
$name = 'MAdminCacheProxyDefaultTest'; |
34
|
|
|
$this->context->getConfig()->set( 'madmin/cache/manager/name', $name ); |
35
|
|
|
|
36
|
|
|
\Aimeos\MAdmin\Cache\Manager\Factory::injectManager( '\\Aimeos\\MAdmin\\Cache\\Manager\\' . $name, $manager ); |
37
|
|
|
|
38
|
|
|
$this->object = new \Aimeos\MAdmin\Cache\Proxy\Standard( $this->context ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
protected function tearDown() |
43
|
|
|
{ |
44
|
|
|
unset( $this->object, $this->mock, $this->context ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
public function testDelete() |
49
|
|
|
{ |
50
|
|
|
$this->mock->expects( $this->once() )->method( 'delete' ) |
51
|
|
|
->with( $this->equalTo( 'test' ) ); |
52
|
|
|
|
53
|
|
|
$this->object->delete( 'test' ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
public function testDeleteMultiple() |
58
|
|
|
{ |
59
|
|
|
$this->mock->expects( $this->once() )->method( 'deleteMultiple' ) |
60
|
|
|
->with( $this->equalTo( array( 'test' ) ) ); |
61
|
|
|
|
62
|
|
|
$this->object->deleteMultiple( array( 'test' ) ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
public function testDeleteByTags() |
67
|
|
|
{ |
68
|
|
|
$this->mock->expects( $this->once() )->method( 'deleteByTags' ) |
69
|
|
|
->with( $this->equalTo( array( 'tag1', 'tag2' ) ) ); |
70
|
|
|
|
71
|
|
|
$this->object->deleteByTags( array( 'tag1', 'tag2' ) ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
public function testClear() |
76
|
|
|
{ |
77
|
|
|
$this->mock->expects( $this->once() )->method( 'clear' ); |
78
|
|
|
$this->object->clear(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
public function testGet() |
83
|
|
|
{ |
84
|
|
|
$this->mock->expects( $this->once() )->method( 'get' ) |
85
|
|
|
->with( $this->equalTo( 't:1' ) ) |
86
|
|
|
->will( $this->returnValue( 'test' ) ); |
87
|
|
|
|
88
|
|
|
$this->assertEquals( 'test', $this->object->get( 't:1' ) ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
public function testGetMultiple() |
93
|
|
|
{ |
94
|
|
|
$this->mock->expects( $this->once() )->method( 'getMultiple' ) |
95
|
|
|
->with( $this->equalTo( array( 't:1' ) ) ) |
96
|
|
|
->will( $this->returnValue( array( 't:1' => 'test' ) ) ); |
97
|
|
|
|
98
|
|
|
$this->assertEquals( array( 't:1' => 'test' ), $this->object->getMultiple( array( 't:1' ) ) ); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
public function testGetMultipleByTags() |
103
|
|
|
{ |
104
|
|
|
$this->mock->expects( $this->once() )->method( 'getMultipleByTags' ) |
105
|
|
|
->with( $this->equalTo( array( 'tag1', 'tag2' ) ) ) |
106
|
|
|
->will( $this->returnValue( array( 't:1' => 'test1', 't:2' => 'test2' ) ) ); |
107
|
|
|
|
108
|
|
|
$expected = array( 't:1' => 'test1', 't:2' => 'test2' ); |
109
|
|
|
$result = $this->object->getMultipleByTags( array( 'tag1', 'tag2' ) ); |
110
|
|
|
|
111
|
|
|
$this->assertEquals( $expected, $result ); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
public function testSet() |
116
|
|
|
{ |
117
|
|
|
$this->mock->expects( $this->once() )->method( 'set' ) |
118
|
|
|
->with( |
119
|
|
|
$this->equalTo( 't:1' ), |
120
|
|
|
$this->equalTo( 'test 1' ), |
121
|
|
|
$this->equalTo( '2000-01-01 00:00:00' ), |
122
|
|
|
$this->equalTo( array( 'tag1', 'tag2' ) ) |
123
|
|
|
); |
124
|
|
|
|
125
|
|
|
$this->object->set( 't:1', 'test 1', '2000-01-01 00:00:00', array( 'tag1', 'tag2' ) ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
public function testSetMultiple() |
130
|
|
|
{ |
131
|
|
|
$this->mock->expects( $this->once() )->method( 'setMultiple' ) |
132
|
|
|
->with( |
133
|
|
|
$this->equalTo( array( 't:1' => 'test 1' ) ), |
134
|
|
|
$this->equalTo( array( 't:1' => '2000-01-01 00:00:00' ) ), |
135
|
|
|
$this->equalTo( array( 'tag1', 'tag2' ) ) |
136
|
|
|
); |
137
|
|
|
|
138
|
|
|
$this->object->setMultiple( array( 't:1' => 'test 1' ), array( 't:1' => '2000-01-01 00:00:00' ), array( 'tag1', 'tag2' ) ); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|