1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of mundschenk-at/wp-data-storage. |
4
|
|
|
* |
5
|
|
|
* Copyright 2017-2018 Peter Putzer. |
6
|
|
|
* |
7
|
|
|
* This program is free software; you can redistribute it and/or |
8
|
|
|
* modify it under the terms of the GNU General Public License |
9
|
|
|
* as published by the Free Software Foundation; either version 2 |
10
|
|
|
* of the License, or ( at your option ) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with this program; if not, write to the Free Software |
19
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20
|
|
|
* |
21
|
|
|
* @package mundschenk-at/wp-data-storage/tests |
22
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.html |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace Mundschenk\Data_Storage\Tests; |
26
|
|
|
|
27
|
|
|
use Mundschenk\Data_Storage\Abstract_Cache; |
28
|
|
|
|
29
|
|
|
use Brain\Monkey\Actions; |
30
|
|
|
use Brain\Monkey\Filters; |
31
|
|
|
use Brain\Monkey\Functions; |
32
|
|
|
|
33
|
|
|
use Mockery as m; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Mundschenk\Data_Storage\Abstract_Cache unit test for the singleton methods. |
37
|
|
|
* |
38
|
|
|
* @coversDefaultClass \Mundschenk\Data_Storage\Abstract_Cache |
39
|
|
|
* @usesDefaultClass \Mundschenk\Data_Storage\Abstract_Cache |
40
|
|
|
* |
41
|
|
|
* @uses ::__construct |
42
|
|
|
*/ |
43
|
|
|
class Abstract_Cache_Test extends TestCase { |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Sets up the fixture, for example, opens a network connection. |
49
|
|
|
* This method is called before a test is executed. |
50
|
|
|
*/ |
51
|
|
|
protected function setUp() { // @codingStandardsIgnoreLine |
52
|
|
|
parent::setUp(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Necesssary clean-up work. |
57
|
|
|
*/ |
58
|
|
|
protected function tearDown() { // @codingStandardsIgnoreLine |
59
|
|
|
parent::tearDown(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Tests constructor. |
64
|
|
|
* |
65
|
|
|
* @covers ::__construct |
66
|
|
|
*/ |
67
|
|
|
public function test___construct() { |
68
|
|
|
$cache = m::mock( Abstract_Cache::class )->makePartial(); |
69
|
|
|
$cache->shouldReceive( 'invalidate' )->once(); |
70
|
|
|
|
71
|
|
|
$this->invokeMethod( $cache, '__construct', [ 'prefix_' ] ); |
72
|
|
|
|
73
|
|
|
$this->assertInstanceOf( Abstract_Cache::class, $cache ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Tests get_key. |
78
|
|
|
* |
79
|
|
|
* @covers ::get_key |
80
|
|
|
*/ |
81
|
|
|
public function test_get_key() { |
82
|
|
|
$prefix = 'my_prefix_'; |
83
|
|
|
$key = 'foo'; |
84
|
|
|
$incrementor = 99; |
85
|
|
|
|
86
|
|
|
// Prepare object. |
87
|
|
|
$cache = m::mock( Abstract_Cache::class )->makePartial(); |
88
|
|
|
$this->setValue( $cache, 'incrementor', $incrementor, Abstract_Cache::class ); |
89
|
|
|
$this->setValue( $cache, 'prefix', $prefix, Abstract_Cache::class ); |
90
|
|
|
|
91
|
|
|
$this->assertSame( "{$prefix}{$incrementor}_{$key}", $this->invokeMethod( $cache, 'get_key', [ $key ] ) ); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|