CacheTest::testDeleteBatch()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
namespace Opine\Cache;
3
4
use PHPUnit_Framework_TestCase;
5
use Opine\Cache\Service as Cache;
6
use Exception;
7
8
class CacheTest extends PHPUnit_Framework_TestCase
9
{
10
    const ROOT = __DIR__.'/../public';
11
12
    public function testSet()
13
    {
14
        $cache = new Cache(self::ROOT);
15
        $this->assertTrue($cache->set('phpunit-test', 'A', 30, 0));
16
    }
17
18
    public function testGet()
19
    {
20
        $cache = new Cache(self::ROOT);
21
        $this->assertTrue('A' === $cache->get('phpunit-test', 0));
22
    }
23
24
    public function testDelete()
25
    {
26
        $cache = new Cache(self::ROOT);
27
        $this->assertTrue($cache->delete('phpunit-test', 0));
28
        $this->assertFalse($cache->get('phpunit-test', 0));
29
    }
30
31
    public function testGetSet()
32
    {
33
        $cache = new Cache(self::ROOT);
34
        $this->assertTrue('B' === $cache->getSetGet('phpunit-test', function () {
35
            return 'B';
36
        }, 30, 0));
37
        $this->assertTrue('B' === $cache->get('phpunit-test', 0));
38
    }
39
40
    public function testGetSetGetBatchNoCallback()
41
    {
42
        $cache = new Cache(self::ROOT);
43
        $items = [
44
            'phpunit-test'  => 'C',
45
            'phpunit-test2' => 'D',
46
        ];
47
        $caught = false;
48
        try {
49
            $cache->getSetGetBatch($items, 30, 0);
50
        } catch (Exception $e) {
51
            $caught = true;
52
        }
53
        $this->assertTrue($caught);
54
    }
55
56
    public function testGetSetGetBatch()
57
    {
58
        $cache = new Cache(self::ROOT);
59
        $items = [
60
            'phpunit-test'  => function () { return 'C'; },
61
            'phpunit-test2' => function () { return 'D'; }
62
        ];
63
        $this->assertTrue($cache->getSetGetBatch($items, 30, 0));
64
        $this->assertTrue('B' === $items['phpunit-test']);
65
    }
66
67
    public function testGetBatch()
68
    {
69
        $cache = new Cache(self::ROOT);
70
        $items = [
71
            'phpunit-test'  => function () { return 'C'; },
72
            'phpunit-test2' => function () { return 'D'; }
73
        ];
74
        $this->assertTrue($cache->getBatch($items, 0));
75
        $this->assertTrue('B' === $items['phpunit-test']);
76
        $this->assertTrue('D' === $items['phpunit-test2']);
77
    }
78
79
    public function testDeleteBatch()
80
    {
81
        $cache = new Cache(self::ROOT);
82
        $items = ['phpunit-test', 'phpunit-test2'];
83
        $this->assertTrue($cache->deleteBatch($items));
84
        $this->assertFalse($cache->get('phpunit-test'));
85
        $this->assertFalse($cache->get('phpunit-test2'));
86
    }
87
}
88