Skip to content

Commit 6c33eb2

Browse files
authored
Merge pull request #1041 from josbeir/5.x
Allow SqlPanel skip drivers with no setLogger method
2 parents 9a11fb6 + efe7df6 commit 6c33eb2

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

src/Panel/SqlLogPanel.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public static function addConnection(string $name): void
6868
return;
6969
}
7070
$driver = $connection->getDriver();
71+
72+
if (!method_exists($driver, 'setLogger')) {
73+
return;
74+
}
75+
7176
$logger = null;
7277
if ($driver instanceof Driver) {
7378
$logger = $driver->getLogger();

tests/TestCase/Panel/SqlLogPanelTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,21 @@ public function testSummary()
124124
$result = $this->panel->summary();
125125
$this->assertMatchesRegularExpression('/\d+ \\/ \d+(\.\d+)? ms/', $result);
126126
}
127+
128+
/**
129+
* Testing a simple connection (no set/getLogger on driver).
130+
*
131+
* @return void
132+
*/
133+
public function testWithSimpleConnection()
134+
{
135+
ConnectionManager::setConfig('simple', [
136+
'className' => 'DebugKit\TestApp\Stub\SimpleConnectionStub',
137+
]);
138+
139+
$this->panel->addConnection('simple'); // should not throw an error
140+
$this->assertTrue(true);
141+
142+
ConnectionManager::drop('simple');
143+
}
127144
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace DebugKit\TestApp\Stub;
5+
6+
use Cake\Cache\Cache;
7+
use Cake\Datasource\ConnectionInterface;
8+
use Psr\SimpleCache\CacheInterface;
9+
use stdClass;
10+
11+
class SimpleConnectionStub implements ConnectionInterface
12+
{
13+
public function getDriver(string $role = self::ROLE_WRITE): object
14+
{
15+
return new stdClass();
16+
}
17+
18+
public function setCacher(CacheInterface $cacher)
19+
{
20+
return $this;
21+
}
22+
23+
public function getCacher(): CacheInterface
24+
{
25+
return Cache::pool('_simple_connection_stub_');
26+
}
27+
28+
public function configName(): string
29+
{
30+
return 'simple_connection_stub';
31+
}
32+
33+
public function config(): array
34+
{
35+
return [];
36+
}
37+
}

0 commit comments

Comments
 (0)