Completed
Push — master ( 00fae0...ee941a )
by Dan
23:33 queued 15:03
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
 * 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);
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...
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