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
5 changes: 5 additions & 0 deletions src/Panel/SqlLogPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public static function addConnection(string $name): void
return;
}
$driver = $connection->getDriver();

if (!method_exists($driver, 'setLogger')) {
return;
}

$logger = null;
if ($driver instanceof Driver) {
$logger = $driver->getLogger();
Expand Down
17 changes: 17 additions & 0 deletions tests/TestCase/Panel/SqlLogPanelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,21 @@ public function testSummary()
$result = $this->panel->summary();
$this->assertMatchesRegularExpression('/\d+ \\/ \d+(\.\d+)? ms/', $result);
}

/**
* Testing a simple connection (no set/getLogger on driver).
*
* @return void
*/
public function testWithSimpleConnection()
{
ConnectionManager::setConfig('simple', [
'className' => 'DebugKit\TestApp\Stub\SimpleConnectionStub',
]);

$this->panel->addConnection('simple'); // should not throw an error
$this->assertTrue(true);

ConnectionManager::drop('simple');
}
}
37 changes: 37 additions & 0 deletions tests/test_app/Stub/SimpleConnectionStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);

namespace DebugKit\TestApp\Stub;

use Cake\Cache\Cache;
use Cake\Datasource\ConnectionInterface;
use Psr\SimpleCache\CacheInterface;
use stdClass;

class SimpleConnectionStub implements ConnectionInterface
{
public function getDriver(string $role = self::ROLE_WRITE): object
{
return new stdClass();
}

public function setCacher(CacheInterface $cacher)
{
return $this;
}

public function getCacher(): CacheInterface
{
return Cache::pool('_simple_connection_stub_');
}

public function configName(): string
{
return 'simple_connection_stub';
}

public function config(): array
{
return [];
}
}