Issues (49)

tests/Collector/ConfigCollectorTest.php (1 issue)

Labels
Severity
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(): void
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 tearDown(): void
30
    {
31
        DebugBar::clearDebugBar();
32
        $this->collector = null;
33
34
        parent::tearDown();
35
    }
36
37
    public function testGetName()
38
    {
39
        $this->assertNotEmpty($this->collector->getName());
40
    }
41
42
    public function testManifestIsProxied()
43
    {
44
        $manifest = $this->collector->getConfigManifest();
45
        $this->assertInstanceOf(ProxyConfigCollectionInterface::class, $manifest);
46
    }
47
48
    public function testGetCallsAreCaptured()
49
    {
50
        $manifest = $this->collector->getConfigManifest();
51
52
        Config::inst()->get(SSViewer::class, 'themes');
53
        $result = $manifest->getConfigCalls();
0 ignored issues
show
The method getConfigCalls() does not exist on SilverStripe\Config\Coll...nfigCollectionInterface. It seems like you code against a sub-type of SilverStripe\Config\Coll...nfigCollectionInterface such as LeKoala\DebugBar\Proxy\DeltaConfigManifestProxy or LeKoala\DebugBar\Proxy\ConfigManifestProxy. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        /** @scrutinizer ignore-call */ 
54
        $result = $manifest->getConfigCalls();
Loading history...
54
55
        // Note : depending on class hierarchy, another class can be stored instead of the one being called
56
        $this->assertArrayHasKey(SSViewer::class, $result, "Available keys are : " . implode(",", array_keys($result)));
57
        $this->assertEquals(1, $result[SSViewer::class]['themes']['calls']);
58
59
        // Make 3 more calls, it should make 4
60
        Config::inst()->get(SSViewer::class, 'themes');
61
        Config::inst()->get(SSViewer::class, 'themes');
62
        Config::inst()->get(SSViewer::class, 'themes');
63
        $result = $manifest->getConfigCalls();
64
        $this->assertEquals(4, $result[SSViewer::class]['themes']['calls']);
65
    }
66
}
67