Completed
Branch master (1afc22)
by Dan
09:51 queued 07:56
created

AbstractCacheTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 59
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testConstructNullStorage() 0 5 1
A testConstructWithStorage() 0 5 1
A testWithCacheStorage() 0 6 1
A testGetCacheStorage() 0 6 1
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
 * Abstract Cache Tests
12
 *
13
 * @package Tests\Cache
14
 */
15
class AbstractCacheTest extends \PHPUnit\Framework\TestCase
16
{
17
    /**
18
     * @var Cache
19
     */
20
    public $cache;
21
22
    /**
23
     * @var \PHPUnit_Framework_MockObject_MockObject
24
     */
25
    public $storageMock;
26
27
    /**
28
     * Using AbstractCacheMock to extend abstract class.
29
     */
30
    public function setUp()
31
    {
32
        $this->storageMock = $this->getMockBuilder(CacheStorageInterface::class)->getMock();
33
        $this->cache = new AbstractCacheMock($this->storageMock);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Tests\Cache\Mock\Ab...ock($this->storageMock) of type object<Tests\Cache\Mock\AbstractCacheMock> is incompatible with the declared type object<Ds\Cache\Cache> of property $cache.

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..

Loading history...
34
    }
35
36
    /**
37
     * Test that NullStorage Adaptor is called by default.
38
     */
39
    public function testConstructNullStorage(){
40
        $cache = new Cache();
41
        $storage = $cache->getCacheStorage();
42
        $this->assertInstanceOf(NullStorage::class,$storage);
43
    }
44
45
    /**
46
     * Test CacheStorage is updated from construct.
47
     */
48
    public function testConstructWithStorage(){
49
        $cache = new Cache($this->storageMock);
50
        $storage = $cache->getCacheStorage();
51
        $this->assertSame($this->storageMock,$storage);
52
    }
53
54
    /**
55
     * Test that Cache::withCacheStorage() updates CacheStorageInterface adaptor.
56
     */
57
    public function testWithCacheStorage()
58
    {
59
        $newStorageMock = clone $this->storageMock;
60
        $newCache = $this->cache->withCacheStorage($newStorageMock);
61
        $this->assertEquals($newStorageMock, $newCache->getCacheStorage());
62
    }
63
64
    /**
65
     * Test that CacheStorageInterface is returned from Cache::getCacheStorage
66
     */
67
    public function testGetCacheStorage()
68
    {
69
        $expected = $this->storageMock;
70
        $actual = $this->cache->getCacheStorage();
71
        $this->assertEquals($expected, $actual);
72
    }
73
}
74