Completed
Push — master ( 06e841...fb9ef9 )
by Aimeos
01:39
created

Typo3Test::testSetListWithSiteId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
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), 2014-2016
7
 */
8
9
10
namespace Aimeos\MW\Cache;
11
12
13
require_once __DIR__ . DIRECTORY_SEPARATOR . 'T3Cache';
14
15
16
class Typo3Test extends \PHPUnit_Framework_TestCase
17
{
18
	private $object;
19
	private $mock;
20
21
22
	protected function setUp()
23
	{
24
		$this->mock = $this->getMockBuilder( 'TYPO3\\CMS\\Core\\Cache\\Frontend\\T3Cache' )->getMock();
25
		$this->object = new \Aimeos\MW\Cache\Typo3( 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
	public function testDeleteWithSiteId()
43
	{
44
		$object = new \Aimeos\MW\Cache\Typo3( 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' ) );
0 ignored issues
show
Documentation introduced by
array('key', 'key') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a object<Aimeos\MW\Cache\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
55
	}
56
57
58
	public function testDeleteMultipleWithSiteId()
59
	{
60
		$object = new \Aimeos\MW\Cache\Typo3( array( 'siteid' => 1 ), $this->mock );
61
62
		$this->mock->expects( $this->once() )->method( 'remove' )->with( $this->equalTo( '1-key' ) );
63
		$object->deleteMultiple( array( 'key' ) );
0 ignored issues
show
Documentation introduced by
array('key') is of type array<integer,string,{"0":"string"}>, but the function expects a object<Aimeos\MW\Cache\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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
	public function testDeleteByTagsWithSiteId()
75
	{
76
		$object = new \Aimeos\MW\Cache\Typo3( 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
	public function testClearWithSiteId()
91
	{
92
		$object = new \Aimeos\MW\Cache\Typo3( 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
	public function testGet()
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
	public function testGetWithSiteId()
109
	{
110
		$object = new \Aimeos\MW\Cache\Typo3( array( 'siteid' => 1 ), $this->mock );
111
112
		$this->mock->expects( $this->once() )->method( 'get' )->with( $this->equalTo( '1-key' ) );
113
		$object->get( 'key', 'default' );
114
	}
115
116
117
	public function testGetMultiple()
118
	{
119
		$this->mock->expects( $this->exactly( 2 ) )->method( 'get' )
120
			->will( $this->returnValue( 'value' ) );
121
122
		$expected = array( 'key1' => 'value', 'key2' => 'value' );
123
		$this->assertEquals( $expected, $this->object->getMultiple( array( 'key1', 'key2' ) ) );
0 ignored issues
show
Documentation introduced by
array('key1', 'key2') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a object<Aimeos\MW\Cache\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
124
	}
125
126
127
	public function testGetMultipleWithSiteId()
128
	{
129
		$object = new \Aimeos\MW\Cache\Typo3( array( 'siteid' => 1 ), $this->mock );
130
131
		$this->mock->expects( $this->once() )->method( 'get' )->with( $this->equalTo( '1-key' ) );
132
		$object->getMultiple( array( 'key' ) );
0 ignored issues
show
Documentation introduced by
array('key') is of type array<integer,string,{"0":"string"}>, but the function expects a object<Aimeos\MW\Cache\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
133
	}
134
135
136
	public function testGetMultipleByTags()
137
	{
138
		$this->mock->expects( $this->exactly( 2 ) )->method( 'getByTag' )
139
			->with( $this->equalTo( 'key' ) )->will( $this->returnValue( array( 'key' => 'value' ) ) );
140
141
		$this->assertEquals( array( 'key' => 'value' ), $this->object->getMultipleByTags( array( 'key', 'key' ) ) );
142
	}
143
144
145
	public function testGetMultipleByTagsWithSiteId()
146
	{
147
		$object = new \Aimeos\MW\Cache\Typo3( array( 'siteid' => 1 ), $this->mock );
148
149
		$this->mock->expects( $this->once() )->method( 'getByTag' )
150
			->with( $this->equalTo( '1-key' ) )->will( $this->returnValue( array( '1-key' => 'value' ) ) );
151
152
		$this->assertEquals( array( 'key' => 'value' ), $object->getMultipleByTags( array( 'key' ) ) );
153
	}
154
155
156
	public function testSet()
157
	{
158
		$this->mock->expects( $this->once() )->method( 'set' )
159
			->with(
160
				$this->equalTo( 'key' ), $this->equalTo( 'value' ),
161
				$this->equalTo( array( 'tag' ) ), $this->greaterThan( 0 )
162
			);
163
164
		$this->object->set( 'key', 'value', '2000-01-01 00:00:00', array( 'tag' ) );
165
	}
166
167
168
	public function testSetWithSiteId()
169
	{
170
		$object = new \Aimeos\MW\Cache\Typo3( array( 'siteid' => 1 ), $this->mock );
171
172
		$this->mock->expects( $this->once() )->method( 'set' )
173
			->with(
174
				$this->equalTo( '1-key' ), $this->equalTo( 'value' ),
175
				$this->equalTo( array( '1-siteid', '1-tag' ) ), $this->equalTo( null )
176
			);
177
178
		$object->set( 'key', 'value', null, array( 'tag' ) );
179
	}
180
181
182
	public function testSetMultiple()
183
	{
184
		$this->mock->expects( $this->once() )->method( 'set' )
185
			->with(
186
				$this->equalTo( 'key' ), $this->equalTo( 'value' ),
187
				$this->equalTo( array( 'tag' ) ), $this->greaterThan( 0 )
188
			);
189
190
		$expires = array( 'key' => '2000-01-01 00:00:00' );
191
		$this->object->setMultiple( array( 'key' => 'value' ), $expires, array( 'key' => array( 'tag' ) ) );
0 ignored issues
show
Documentation introduced by
array('key' => 'value') is of type array<string,string,{"key":"string"}>, but the function expects a object<Aimeos\MW\Cache\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
192
	}
193
194
195
	public function testSetMultipleWithSiteId()
196
	{
197
		$object = new \Aimeos\MW\Cache\Typo3( array( 'siteid' => 1 ), $this->mock );
198
199
		$this->mock->expects( $this->once() )->method( 'set' )
200
			->with(
201
				$this->equalTo( '1-key' ), $this->equalTo( 'value' ),
202
				$this->equalTo( array( '1-siteid', '1-tag' ) ), $this->equalTo( null )
203
			);
204
205
		$object->setMultiple( array( 'key' => 'value' ), array(), array( 'key' => array( 'tag' ) ) );
0 ignored issues
show
Documentation introduced by
array('key' => 'value') is of type array<string,string,{"key":"string"}>, but the function expects a object<Aimeos\MW\Cache\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
206
	}
207
208
}
209