| 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 | // Set value in themes config |
||
| 53 | SSViewer::config()->merge('themes', ['one', 'two']); |
||
| 54 | |||
| 55 | Config::inst()->get(SSViewer::class, 'themes'); |
||
| 56 | $result = $manifest->getConfigCalls(); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 57 | |||
| 58 | // Note : depending on class hierarchy, another class can be stored instead of the one being called |
||
| 59 | $this->assertArrayHasKey(SSViewer::class, $result, "Available keys are : " . implode(",", array_keys($result))); |
||
| 60 | $this->assertEquals(1, $result[SSViewer::class]['themes']['calls']); |
||
| 61 | |||
| 62 | // Make 3 more calls, it should make 4 |
||
| 63 | Config::inst()->get(SSViewer::class, 'themes'); |
||
| 64 | Config::inst()->get(SSViewer::class, 'themes'); |
||
| 65 | Config::inst()->get(SSViewer::class, 'themes'); |
||
| 66 | $result = $manifest->getConfigCalls(); |
||
| 67 | $this->assertEquals(4, $result[SSViewer::class]['themes']['calls']); |
||
| 68 | } |
||
| 69 | } |
||
| 70 |