Completed
Push — master ( ac9830...86bd1d )
by Aimeos
01:48
created

FlowTest::testGetMultiple()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2014-2016
6
 */
7
8
9
namespace Aimeos\MW\Cache;
10
11
12
class FlowTest extends \PHPUnit_Framework_TestCase
13
{
14
	private $object;
15
	private $mock;
16
17
18
	protected function setUp()
19
	{
20
		if( interface_exists( 'TYPO3\Flow\Cache\Frontend\FrontendInterface' ) === false ) {
21
			$this->markTestSkipped( 'Class \\TYPO3\\Flow\\Cache\\Frontend\\FrontendInterface not found' );
22
		}
23
24
		$this->mock = $this->getMockBuilder( 'TYPO3\Flow\Cache\Frontend\FrontendInterface' )->getMock();
25
		$this->object = new \Aimeos\MW\Cache\Flow( array(), $this->mock );
26
	}
27
28
29
	protected function tearDown()
30
	{
31
		unset( $this->mock, $this->object );
32
	}
33
34
35
	public function testDelete()
36
	{
37
		$this->mock->expects( $this->once() )->method( 'remove' )->with( $this->equalTo( 'key' ) );
38
		$this->object->delete( 'key' );
39
	}
40
41
42 View Code Duplication
	public function testDeleteWithSiteId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
	{
44
		$object = new \Aimeos\MW\Cache\Flow( array( 'siteid' => 1 ), $this->mock );
45
46
		$this->mock->expects( $this->once() )->method( 'remove' )->with( $this->equalTo( '1-key' ) );
47
		$object->delete( 'key' );
48
	}
49
50
51
	public function testDeleteMultiple()
52
	{
53
		$this->mock->expects( $this->exactly( 2 ) )->method( 'remove' )->with( $this->equalTo( 'key' ) );
54
		$this->object->deleteMultiple( array( 'key', 'key' ) );
55
	}
56
57
58 View Code Duplication
	public function testDeleteMultipleWithSiteId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
	{
60
		$object = new \Aimeos\MW\Cache\Flow( array( 'siteid' => 1 ), $this->mock );
61
62
		$this->mock->expects( $this->once() )->method( 'remove' )->with( $this->equalTo( '1-key' ) );
63
		$object->deleteMultiple( array( 'key' ) );
64
	}
65
66
67
	public function testDeleteByTags()
68
	{
69
		$this->mock->expects( $this->exactly( 2 ) )->method( 'flushByTag' )->with( $this->equalTo( 'tag' ) );
70
		$this->object->deleteByTags( array( 'tag', 'tag' ) );
71
	}
72
73
74 View Code Duplication
	public function testDeleteByTagsWithSiteId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
	{
76
		$object = new \Aimeos\MW\Cache\Flow( array( 'siteid' => 1 ), $this->mock );
77
78
		$this->mock->expects( $this->once() )->method( 'flushByTag' )->with( $this->equalTo( '1-tag' ) );
79
		$object->deleteByTags( array( 'tag' ) );
80
	}
81
82
83
	public function testClear()
84
	{
85
		$this->mock->expects( $this->once() )->method( 'flush' );
86
		$this->object->clear();
87
	}
88
89
90 View Code Duplication
	public function testClearWithSiteId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91
	{
92
		$object = new \Aimeos\MW\Cache\Flow( array( 'siteid' => 1 ), $this->mock );
93
94
		$this->mock->expects( $this->once() )->method( 'flushByTag' )->with( $this->equalTo( '1-siteid' ) );
95
		$object->clear();
96
	}
97
98
99 View Code Duplication
	public function testGet()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
	{
101
		$this->mock->expects( $this->once() )->method( 'get' )
102
			->with( $this->equalTo( 'key' ) )->will( $this->returnValue( 'value' ) );
103
104
		$this->assertEquals( 'value', $this->object->get( 'key', 'default' ) );
105
	}
106
107
108 View Code Duplication
	public function testGetDefault()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
109
	{
110
		$this->mock->expects( $this->once() )->method( 'get' )
111
		->with( $this->equalTo( 'key' ) )->will( $this->returnValue( false ) );
112
113
		$this->assertEquals( 'default', $this->object->get( 'key', 'default' ) );
114
	}
115
116
117 View Code Duplication
	public function testGetWithSiteId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
118
	{
119
		$object = new \Aimeos\MW\Cache\Flow( array( 'siteid' => 1 ), $this->mock );
120
121
		$this->mock->expects( $this->once() )->method( 'get' )->with( $this->equalTo( '1-key' ) );
122
		$object->get( 'key', 'default' );
123
	}
124
125
126 View Code Duplication
	public function testGetMultiple()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
127
	{
128
		$this->mock->expects( $this->exactly( 2 ) )->method( 'get' )
129
			->will( $this->returnValue( 'value' ) );
130
131
		$expected = array( 'key1' => 'value', 'key2' => 'value' );
132
		$this->assertEquals( $expected, $this->object->getMultiple( array( 'key1', 'key2' ) ) );
133
	}
134
135
136 View Code Duplication
	public function testGetMultipleWithSiteId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
137
	{
138
		$object = new \Aimeos\MW\Cache\Flow( array( 'siteid' => 1 ), $this->mock );
139
140
		$this->mock->expects( $this->once() )->method( 'get' )->with( $this->equalTo( '1-key' ) );
141
		$object->getMultiple( array( 'key' ) );
142
	}
143
144
145 View Code Duplication
	public function testGetMultipleByTags()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
146
	{
147
		$this->mock->expects( $this->exactly( 2 ) )->method( 'getByTag' )
148
			->with( $this->equalTo( 'key' ) )->will( $this->returnValue( array( 'key' => 'value' ) ) );
149
150
		$this->assertEquals( array( 'key' => 'value' ), $this->object->getMultipleByTags( array( 'key', 'key' ) ) );
151
	}
152
153
154 View Code Duplication
	public function testGetMultipleByTagsWithSiteId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
155
	{
156
		$object = new \Aimeos\MW\Cache\Flow( array( 'siteid' => 1 ), $this->mock );
157
158
		$this->mock->expects( $this->once() )->method( 'getByTag' )
159
			->with( $this->equalTo( '1-key' ) )->will( $this->returnValue( array( '1-key' => 'value' ) ) );
160
161
		$this->assertEquals( array( 'key' => 'value' ), $object->getMultipleByTags( array( 'key' ) ) );
162
	}
163
164
165
	public function testSet()
166
	{
167
		$this->mock->expects( $this->once() )->method( 'set' )
168
			->with(
169
				$this->equalTo( 'key' ), $this->equalTo( 'value' ),
170
				$this->equalTo( array( 'tag' ) ), $this->greaterThan( 0 )
171
			);
172
173
		$this->object->set( 'key', 'value', '2100-01-01 00:00:00', array( 'tag' ) );
174
	}
175
176
177 View Code Duplication
	public function testSetWithSiteId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
178
	{
179
		$object = new \Aimeos\MW\Cache\Flow( array( 'siteid' => 1 ), $this->mock );
180
181
		$this->mock->expects( $this->once() )->method( 'set' )
182
			->with(
183
				$this->equalTo( '1-key' ), $this->equalTo( 'value' ),
184
				$this->equalTo( array( '1-siteid', '1-tag' ) ), $this->equalTo( null )
185
			);
186
187
		$object->set( 'key', 'value', null, array( 'tag' ) );
188
	}
189
190
191
	public function testSetMultiple()
192
	{
193
		$this->mock->expects( $this->once() )->method( 'set' )
194
			->with(
195
				$this->equalTo( 'key' ), $this->equalTo( 'value' ),
196
				$this->equalTo( array( 'tag' ) ), $this->greaterThan( 0 )
197
			);
198
199
		$expires = array( 'key' => '2100-01-01 00:00:00' );
200
		$this->object->setMultiple( array( 'key' => 'value' ), $expires, array( 'key' => array( 'tag' ) ) );
201
	}
202
203
204 View Code Duplication
	public function testSetMultipleWithSiteId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
205
	{
206
		$object = new \Aimeos\MW\Cache\Flow( array( 'siteid' => 1 ), $this->mock );
207
208
		$this->mock->expects( $this->once() )->method( 'set' )
209
			->with(
210
				$this->equalTo( '1-key' ), $this->equalTo( 'value' ),
211
				$this->equalTo( array( '1-siteid', '1-tag' ) ), $this->equalTo( null )
212
			);
213
214
		$object->setMultiple( array( 'key' => 'value' ), null, array( 'key' => array( 'tag' ) ) );
215
	}
216
217
}
218