1
|
|
|
<?php |
2
|
|
|
namespace FwlibTest\Cache; |
3
|
|
|
|
4
|
|
|
use Fwlib\Cache\HandlerTrait as CacheHandlerTrait; |
5
|
|
|
use Fwolf\Wrapper\PHPUnit\PHPUnitTestCase; |
6
|
|
|
use PHPUnit_Framework_MockObject_MockObject as MockObject; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @copyright Copyright 2015 Fwolf |
10
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html LGPL-3.0+ |
11
|
|
|
*/ |
12
|
|
|
class HandlerTraitTest extends PHPUnitTestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @return MockObject | CacheHandlerTrait |
16
|
|
|
*/ |
17
|
|
|
protected function buildMock() |
18
|
|
|
{ |
19
|
|
|
$mock = $this->getMockBuilder(CacheHandlerTrait::class) |
20
|
|
|
->setMethods(null) |
21
|
|
|
->getMockForTrait(); |
22
|
|
|
|
23
|
|
|
return $mock; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
public function testComputeExpireTime() |
28
|
|
|
{ |
29
|
|
|
$handler = $this->buildMock(); |
30
|
|
|
|
31
|
|
|
$expireTime = $this->reflectionCall($handler, 'computeExpireTime'); |
32
|
|
|
$this->assertEquals(0, $expireTime); |
33
|
|
|
|
34
|
|
|
$expireTime = |
35
|
|
|
$this->reflectionCall($handler, 'computeExpireTime', [0]); |
36
|
|
|
$this->assertEquals(0, $expireTime); |
37
|
|
|
|
38
|
|
|
$expireTime = |
39
|
|
|
$this->reflectionCall($handler, 'computeExpireTime', [10, 300]); |
40
|
|
|
$this->assertEquals(310, $expireTime); |
41
|
|
|
|
42
|
|
|
$now = time(); |
43
|
|
|
$expireTime = |
44
|
|
|
$this->reflectionCall($handler, 'computeExpireTime', [30, 0]); |
45
|
|
|
$this->assertGreaterThan($now + 20, $expireTime); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
public function testHashKey() |
50
|
|
|
{ |
51
|
|
|
$handler = $this->buildMock(); |
52
|
|
|
|
53
|
|
|
$handler->emptyKeyReplacement = '[emptyKey]'; |
|
|
|
|
54
|
|
|
|
55
|
|
|
$this->assertEquals( |
56
|
|
|
'[emptyKey]', |
57
|
|
|
$this->reflectionCall($handler, 'hashKey', ['']) |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$handler->hashAlgorithm = ''; |
|
|
|
|
61
|
|
|
$hashedKey = $this->reflectionCall($handler, 'hashKey', ['foo']); |
62
|
|
|
$this->assertEquals('foo', $hashedKey); |
63
|
|
|
|
64
|
|
|
$handler->hashAlgorithm = 'crc32b'; |
|
|
|
|
65
|
|
|
$hashedKey = $this->reflectionCall($handler, 'hashKey', ['foo']); |
66
|
|
|
$this->assertNotEquals('foo', $hashedKey); |
67
|
|
|
$this->assertNotEmpty($hashedKey); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: