Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/Debugger/Debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,33 @@ public function render(): string
*/
protected function createTab(string $type): void
{
if (!$this->debugBar->hasCollector($type)) {
$this->debugBar->addCollector(new MessagesCollector($type));
}
$collector = $this->resolveMessagesCollector($type);

$messages = $this->store->get($type);

foreach ($messages as $message) {
$fn = key($message);
$this->debugBar[$type]->$fn($message[$fn]);
$collector->log($fn, $message[$fn]);
}
}

/**
* Ensures the requested debug tab collector can accept mixed message payloads.
* @throws DebugBarException
*/
protected function resolveMessagesCollector(string $type): MessagesCollector
{
if (!$this->debugBar->hasCollector($type)) {
$this->debugBar->addCollector(new MessagesCollector($type));
}

$collector = $this->debugBar->getCollector($type);

if (!$collector instanceof MessagesCollector) {
throw new DebugBarException("Collector '{$type}' must be a MessagesCollector instance");
}

return $collector;
}

/**
Expand Down
32 changes: 31 additions & 1 deletion tests/Unit/Debugger/DebuggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function testDebugbarRender(): void

$this->debugger->initStore();

$rendererMock = Mockery::mock('alias:' . JavascriptRenderer::class);
$rendererMock = Mockery::mock(JavascriptRenderer::class);
$rendererMock->shouldReceive('setBaseUrl')->andReturnSelf();
$rendererMock->shouldReceive('addAssets')->andReturnSelf();
$rendererMock->shouldReceive('renderHead')->andReturn('<head></head>');
Expand All @@ -117,13 +117,43 @@ public function testDebugbarRender(): void
$this->debugBarMock->shouldReceive('getJavascriptRenderer')->andReturn($rendererMock);

$this->debugBarMock->shouldReceive('hasCollector')->with(Mockery::any())->andReturn(true);
$this->debugBarMock->shouldReceive('getCollector')
->with(Mockery::any())
->andReturn(Mockery::mock(MessagesCollector::class));

$output = $this->debugger->render();

$this->assertStringContainsString('<head></head>', $output);
$this->assertStringContainsString('<div>Debug Bar</div>', $output);
}

public function testDebugbarRenderReplaysArrayPayloadsThroughLog(): void
{
$this->debugger->initStore();
$this->debugger->addToStoreCell(Debugger::ROUTES, LogLevel::INFO, ['Route' => '/welcome']);

$collectorMock = Mockery::mock(MessagesCollector::class);
$collectorMock->shouldReceive('log')
->once()
->with(LogLevel::INFO, ['Route' => '/welcome']);

$this->debugBarMock->shouldReceive('hasCollector')
->with(Debugger::ROUTES)
->andReturn(true);
$this->debugBarMock->shouldReceive('getCollector')
->with(Debugger::ROUTES)
->andReturn($collectorMock);

$method = new \ReflectionMethod($this->debugger, 'createTab');
$method->setAccessible(true);
$method->invoke($this->debugger, Debugger::ROUTES);

$this->assertEquals(
['info' => ['Route' => '/welcome']],
$this->debuggerStore->get(Debugger::ROUTES)[0]
);
}

public function testDebugbarRenderReturnsEmptyWhenDisabled(): void
{
config()->set('app.debug', false);
Expand Down
Loading