|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LeKoala\DebugBar\Test\Collector; |
|
4
|
|
|
|
|
5
|
|
|
use LeKoala\DebugBar\DebugBar; |
|
6
|
|
|
use SilverStripe\View\SSViewer; |
|
7
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
8
|
|
|
use SilverStripe\Core\Config\Config; |
|
9
|
|
|
use LeKoala\DebugBar\Collector\ConfigCollector; |
|
10
|
|
|
use LeKoala\DebugBar\Proxy\ProxyConfigCollectionInterface; |
|
11
|
|
|
|
|
12
|
|
|
class ConfigCollectorTest extends SapphireTest |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var ConfigCollector |
|
16
|
|
|
*/ |
|
17
|
|
|
private $collector; |
|
18
|
|
|
|
|
19
|
|
|
protected function setUp() |
|
20
|
|
|
{ |
|
21
|
|
|
parent::setUp(); |
|
22
|
|
|
|
|
23
|
|
|
// We need to init DebugBar in order to get our proxied manifests |
|
24
|
|
|
DebugBar::clearDebugBar(); |
|
25
|
|
|
DebugBar::initDebugBar(); |
|
26
|
|
|
$this->collector = new ConfigCollector(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testGetName() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->assertNotEmpty($this->collector->getName()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testManifestIsProxied() |
|
35
|
|
|
{ |
|
36
|
|
|
$manifest = $this->collector->getConfigManifest(); |
|
37
|
|
|
$this->assertInstanceOf(ProxyConfigCollectionInterface::class, $manifest); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testGetCallsAreCaptured() |
|
41
|
|
|
{ |
|
42
|
|
|
$manifest = $this->collector->getConfigManifest(); |
|
43
|
|
|
|
|
44
|
|
|
Config::inst()->get(SSViewer::class, 'themes'); |
|
45
|
|
|
$result = $manifest->getConfigCalls(); |
|
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
// Note : depending on class hierarchy, another class can be stored instead of the one being called |
|
48
|
|
|
$this->assertArrayHasKey(SSViewer::class, $result, "Available keys are : " . implode(",", array_keys($result))); |
|
49
|
|
|
$this->assertEquals(1, $result[SSViewer::class]['themes']['calls']); |
|
50
|
|
|
|
|
51
|
|
|
// Make 3 more calls, it should make 4 |
|
52
|
|
|
Config::inst()->get(SSViewer::class, 'themes'); |
|
53
|
|
|
Config::inst()->get(SSViewer::class, 'themes'); |
|
54
|
|
|
Config::inst()->get(SSViewer::class, 'themes'); |
|
55
|
|
|
$result = $manifest->getConfigCalls(); |
|
56
|
|
|
$this->assertEquals(4, $result[SSViewer::class]['themes']['calls']); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|