1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MW\Cache; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class Laravel5Test extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $mock; |
16
|
|
|
|
17
|
|
|
|
18
|
|
View Code Duplication |
protected function setUp() |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
if( interface_exists( '\\Illuminate\\Contracts\\Cache\\Store' ) === false ) { |
21
|
|
|
$this->markTestSkipped( 'Class \\Illuminate\\Contracts\\Cache\\Store not found' ); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
$this->mock = $this->getMockBuilder( '\\Illuminate\\Contracts\\Cache\\Store' )->getMock(); |
25
|
|
|
$this->object = new \Aimeos\MW\Cache\Laravel5( $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( 'forget' )->with( $this->equalTo( 'key' ) ); |
38
|
|
|
$this->object->delete( 'key' ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
public function testDeleteMultiple() |
43
|
|
|
{ |
44
|
|
|
$this->mock->expects( $this->exactly( 2 ) )->method( 'forget' )->with( $this->equalTo( 'key' ) ); |
45
|
|
|
$this->object->deleteMultiple( array( 'key', 'key' ) ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
public function testDeleteByTags() |
50
|
|
|
{ |
51
|
|
|
$this->mock->expects( $this->once() )->method( 'flush' ); |
52
|
|
|
$this->object->deleteByTags( array( 'tag', 'tag' ) ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
public function testClear() |
57
|
|
|
{ |
58
|
|
|
$this->mock->expects( $this->once() )->method( 'flush' ); |
59
|
|
|
$this->object->clear(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
View Code Duplication |
public function testGet() |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
$this->mock->expects( $this->once() )->method( 'get' ) |
66
|
|
|
->with( $this->equalTo( 'key' ) )->will( $this->returnValue( 'value' ) ); |
67
|
|
|
|
68
|
|
|
$this->assertEquals( 'value', $this->object->get( 'key', 'default' ) ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
View Code Duplication |
public function testGetDefault() |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
$this->mock->expects( $this->once() )->method( 'get' ) |
75
|
|
|
->with( $this->equalTo( 'key' ) )->will( $this->returnValue( null ) ); |
76
|
|
|
|
77
|
|
|
$this->assertEquals( 'default', $this->object->get( 'key', 'default' ) ); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
View Code Duplication |
public function testGetMultiple() |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
$this->mock->expects( $this->exactly( 2 ) )->method( 'get' ) |
84
|
|
|
->will( $this->returnValue( 'value' ) ); |
85
|
|
|
|
86
|
|
|
$expected = array( 'key1' => 'value', 'key2' => 'value' ); |
87
|
|
|
$this->assertEquals( $expected, $this->object->getMultiple( array( 'key1', 'key2' ) ) ); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
public function testGetMultipleByTags() |
92
|
|
|
{ |
93
|
|
|
$this->assertEquals( array(), $this->object->getMultipleByTags( array( 'key', 'key' ) ) ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
View Code Duplication |
public function testSet() |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
$this->mock->expects( $this->once() )->method( 'put' ) |
100
|
|
|
->with( $this->equalTo( 'key' ), $this->equalTo( 'value' ), $this->greaterThan( 0 ) ); |
101
|
|
|
|
102
|
|
|
$this->object->set( 'key', 'value', '2100-01-01 00:00:00', array( 'tag' ) ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
View Code Duplication |
public function testSetForever() |
|
|
|
|
107
|
|
|
{ |
108
|
|
|
$this->mock->expects( $this->once() )->method( 'forever' ) |
109
|
|
|
->with( $this->equalTo( 'key' ), $this->equalTo( 'value' ) ); |
110
|
|
|
|
111
|
|
|
$this->object->set( 'key', 'value', null, array( 'tag' ) ); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
View Code Duplication |
public function testSetMultiple() |
|
|
|
|
116
|
|
|
{ |
117
|
|
|
$this->mock->expects( $this->once() )->method( 'put' ) |
118
|
|
|
->with( $this->equalTo( 'key' ), $this->equalTo( 'value' ), $this->greaterThan( 0 ) ); |
119
|
|
|
|
120
|
|
|
$expires = array( 'key' => '2100-01-01 00:00:00' ); |
121
|
|
|
$this->object->setMultiple( array( 'key' => 'value' ), $expires, array( 'key' => array( 'tag' ) ) ); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
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.