1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Cache; |
4
|
|
|
|
5
|
|
|
use Ds\Cache\Cache; |
6
|
|
|
use Ds\Cache\CacheStorageInterface; |
7
|
|
|
use Ds\Cache\Storage\NullStorage; |
8
|
|
|
use Tests\Cache\Mock\AbstractCacheMock; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class CacheTest |
12
|
|
|
* @package Tests\Cache |
13
|
|
|
*/ |
14
|
|
|
class AbstractCacheTest extends \PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var Cache |
18
|
|
|
*/ |
19
|
|
|
public $cache; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var CacheStorageInterface |
23
|
|
|
*/ |
24
|
|
|
public $storageMock; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Using AbstractCacheMock to extend abstract class. |
28
|
|
|
*/ |
29
|
|
|
public function setUp() |
30
|
|
|
{ |
31
|
|
|
$this->storageMock = $this->getMockBuilder(CacheStorageInterface::class)->getMock(); |
32
|
|
|
$this->cache = new AbstractCacheMock($this->storageMock); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Test that NullStorage Adaptor is called by default. |
37
|
|
|
*/ |
38
|
|
|
public function testConstructNullStorage(){ |
39
|
|
|
$cache = new Cache(); |
40
|
|
|
$storage = $cache->getCacheStorage(); |
41
|
|
|
$this->assertInstanceOf(NullStorage::class,$storage); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Test CacheStorage is updated from construct. |
46
|
|
|
*/ |
47
|
|
|
public function testConstructWithStorage(){ |
48
|
|
|
$cache = new Cache($this->storageMock); |
49
|
|
|
$storage = $cache->getCacheStorage(); |
50
|
|
|
$this->assertSame($this->storageMock,$storage); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Test that Cache::withCacheStorage() updates CacheStorageInterface adaptor. |
55
|
|
|
*/ |
56
|
|
|
public function testWithCacheStorage() |
57
|
|
|
{ |
58
|
|
|
$newStorageMock = clone $this->storageMock; |
59
|
|
|
$newCache = $this->cache->withCacheStorage($newStorageMock); |
60
|
|
|
$this->assertEquals($newStorageMock, $newCache->getCacheStorage()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Test that CacheStorageInterface is returned from Cache::getCacheStorage |
65
|
|
|
*/ |
66
|
|
|
public function testGetCacheStorage() |
67
|
|
|
{ |
68
|
|
|
$expected = $this->storageMock; |
69
|
|
|
$actual = $this->cache->getCacheStorage(); |
70
|
|
|
$this->assertEquals($expected, $actual); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..