CacheTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 70
rs 10
c 0
b 0
f 0
wmc 6
lcom 2
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A tearDown() 0 4 1
A testInstantiate() 0 5 1
A testContains() 0 8 1
A testClear() 0 6 1
A testFetchObject() 0 13 1
1
<?php
2
3
namespace KochTest\Cache;
4
5
use Koch\Cache\Cache;
6
7
class CacheTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @var Cache
11
     */
12
    protected $object;
13
14
    public function setUp()
15
    {
16
        $this->object = new Cache();
17
    }
18
19
    public function tearDown()
20
    {
21
        unset($this->object);
22
    }
23
24
    /**
25
     * @covers Koch\Cache\Cache::instantiate
26
     * @covers Koch\Autoload\Loader::autoload
27
     */
28
    public function testInstantiate()
29
    {
30
        $cache = Cache::instantiate('file');
31
        $this->assertTrue(is_object($cache));
32
    }
33
34
    /**
35
     * @covers Koch\Cache\Cache::store
36
     * @covers Koch\Cache\Cache::fetch
37
     * @covers Koch\Cache\Cache::contains
38
     * @covers Koch\Cache\Cache::delete
39
     */
40
    public function testContains()
41
    {
42
        $this->assertTrue(Cache::store('key1', 'value1'));
0 ignored issues
show
Documentation introduced by
'value1' is of type string, but the function expects a object<Koch\Cache\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
43
        $this->assertEquals('value1', Cache::fetch('key1'));
0 ignored issues
show
Documentation introduced by
'key1' is of type string, but the function expects a object<Koch\Cache\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
44
        $this->assertTrue(Cache::contains('key1'));
45
        $this->assertTrue(Cache::delete('key1'));
46
        $this->assertFalse(Cache::contains('key1'));
47
    }
48
49
    /**
50
     * @covers Koch\Cache\Cache::clear
51
     */
52
    public function testClear()
53
    {
54
        Cache::store('key1', 'value1');
0 ignored issues
show
Documentation introduced by
'value1' is of type string, but the function expects a object<Koch\Cache\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
55
        $this->assertTrue(Cache::clear());
56
        $this->assertFalse(Cache::contains('key1'));
57
    }
58
59
    /**
60
     * @covers Koch\Cache\Cache::storeObject
61
     * @covers Koch\Cache\Cache::fetchObject
62
     */
63
    public function testFetchObject()
64
    {
65
        // create obj
66
       $object        = new \stdClass();
67
        $object->key  = 'value';
68
        $object->key2 = 'value2';
69
70
       // store in cache
71
       $this->assertTrue(Cache::storeObject('stdClass', $object));
72
73
       // fetch and compare
74
       $this->assertEquals($object, Cache::fetchObject('stdClass'));
75
    }
76
}
77