|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2022 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Base\Cache; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class LaravelTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $object; |
|
15
|
|
|
private $mock; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
protected function setUp() : void |
|
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\Base\Cache\Laravel( $this->mock ); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
protected function tearDown() : void |
|
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
|
|
|
->will( $this->returnValue( true ) ); |
|
39
|
|
|
|
|
40
|
|
|
$this->assertTrue( $this->object->delete( 'key' ) ); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
public function testDeleteMultiple() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->mock->expects( $this->exactly( 2 ) )->method( 'forget' )->with( $this->equalTo( 'key' ) ) |
|
47
|
|
|
->will( $this->returnValue( true ) ); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertTrue( $this->object->deleteMultiple( array( 'key', 'key' ) ) ); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
public function testDeleteByTags() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->mock->expects( $this->once() )->method( 'flush' )->will( $this->returnValue( true ) ); |
|
56
|
|
|
$this->assertTrue( $this->object->deleteByTags( array( 'tag', 'tag' ) ) ); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
public function testClear() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->mock->expects( $this->once() )->method( 'flush' )->will( $this->returnValue( true ) ); |
|
63
|
|
|
$this->assertTrue( $this->object->clear() ); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
public function testGet() |
|
68
|
|
|
{ |
|
69
|
|
|
$this->mock->expects( $this->once() )->method( 'get' ) |
|
70
|
|
|
->with( $this->equalTo( 'key' ) )->will( $this->returnValue( 'value' ) ); |
|
71
|
|
|
|
|
72
|
|
|
$this->assertEquals( 'value', $this->object->get( 'key', 'default' ) ); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
public function testGetDefault() |
|
77
|
|
|
{ |
|
78
|
|
|
$this->mock->expects( $this->once() )->method( 'get' ) |
|
79
|
|
|
->with( $this->equalTo( 'key' ) )->will( $this->returnValue( null ) ); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertEquals( 'default', $this->object->get( 'key', 'default' ) ); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
public function testGetMultiple() |
|
86
|
|
|
{ |
|
87
|
|
|
$this->mock->expects( $this->exactly( 2 ) )->method( 'get' ) |
|
88
|
|
|
->will( $this->returnValue( 'value' ) ); |
|
89
|
|
|
|
|
90
|
|
|
$expected = array( 'key1' => 'value', 'key2' => 'value' ); |
|
91
|
|
|
$this->assertEquals( $expected, $this->object->getMultiple( array( 'key1', 'key2' ) ) ); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
public function testSet() |
|
96
|
|
|
{ |
|
97
|
|
|
$this->mock->expects( $this->once() )->method( 'put' )->will( $this->returnValue( true ) ) |
|
98
|
|
|
->with( $this->equalTo( 'key' ), $this->equalTo( 'value' ), $this->greaterThan( 0 ) ); |
|
99
|
|
|
|
|
100
|
|
|
$this->assertTrue( $this->object->set( 'key', 'value', '2100-01-01 00:00:00', ['tag'] ) ); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
public function testSetForever() |
|
105
|
|
|
{ |
|
106
|
|
|
$this->mock->expects( $this->once() )->method( 'forever' )->will( $this->returnValue( true ) ) |
|
107
|
|
|
->with( $this->equalTo( 'key' ), $this->equalTo( 'value' ) ); |
|
108
|
|
|
|
|
109
|
|
|
$this->assertTrue( $this->object->set( 'key', 'value', null, ['tag'] ) ); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
public function testSetMultiple() |
|
114
|
|
|
{ |
|
115
|
|
|
$this->mock->expects( $this->once() )->method( 'put' )->will( $this->returnValue( true ) ) |
|
116
|
|
|
->with( $this->equalTo( 'key' ), $this->equalTo( 'value' ), $this->greaterThan( 0 ) ); |
|
117
|
|
|
|
|
118
|
|
|
$this->assertTrue( $this->object->setMultiple( array( 'key' => 'value' ), '2100-01-01 00:00:00', ['tag'] ) ); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|