PartialCacheCollectorTest::testCollect()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace LeKoala\DebugBar\Test\Collector;
4
5
use LeKoala\DebugBar\DebugBar;
6
use SilverStripe\Dev\SapphireTest;
7
use LeKoala\DebugBar\Collector\PartialCacheCollector;
8
9
class PartialCacheCollectorTest extends SapphireTest
10
{
11
    /**
12
     * @var PartialCacheCollector
13
     */
14
    private $collector;
15
16
    protected function setUp(): void
17
    {
18
        parent::setUp();
19
        $this->collector = new PartialCacheCollector();
20
    }
21
22
    public function tearDown(): void
23
    {
24
        DebugBar::clearDebugBar();
25
        $this->collector = null;
26
27
        parent::tearDown();
28
    }
29
30
    public function testGetName()
31
    {
32
        $this->assertNotEmpty($this->collector->getName());
33
    }
34
35
    /**
36
     * Tests that the tab is returned and that the badge is optional
37
     */
38
    public function testGetWidgets()
39
    {
40
        PartialCacheCollector::setTemplateCache(array());
41
        $widgets = $this->collector->getWidgets();
42
        $this->assertArrayHasKey('Partial Cache', $widgets);
43
        $this->assertArrayNotHasKey('Partial Cache:badge', $widgets);
44
45
        PartialCacheCollector::addTemplateCache('test', array('test'));
46
        $this->assertArrayHasKey('Partial Cache:badge', $this->collector->getWidgets());
47
    }
48
49
    /**
50
     * Tests that an array is returned with specific indexes set
51
     */
52
    public function testCollect()
53
    {
54
        $result = $this->collector->collect();
55
        $this->assertArrayHasKey('count', $result);
56
        $this->assertArrayHasKey('calls', $result);
57
    }
58
59
    /**
60
     * Tests that adding an item to the cache increases its count
61
     */
62
    public function testAddTemplateCache()
63
    {
64
        $count = count(PartialCacheCollector::getTemplateCache());
65
        PartialCacheCollector::addTemplateCache('test1234', array('test'));
66
        $this->assertCount($count + 1, PartialCacheCollector::getTemplateCache());
67
    }
68
69
    /**
70
     * Tests that the setter works
71
     */
72
    public function testSetTemplateCache()
73
    {
74
        PartialCacheCollector::setTemplateCache(array());
75
        $this->assertCount(0, PartialCacheCollector::getTemplateCache());
76
    }
77
}
78