diff --git a/src/Core/StaticConfigTrait.php b/src/Core/StaticConfigTrait.php index 37b049e4b75..1d9ee2eca94 100644 --- a/src/Core/StaticConfigTrait.php +++ b/src/Core/StaticConfigTrait.php @@ -236,7 +236,7 @@ public static function parseDsn($dsn) { */ public static function dsnClassMap($map = null) { if ($map) { - static::$_dsnClassMap = $map + $_dsnClassMap; + static::$_dsnClassMap = $map + static::$_dsnClassMap; } return static::$_dsnClassMap; } diff --git a/tests/TestCase/Core/StaticConfigTraitTest.php b/tests/TestCase/Core/StaticConfigTraitTest.php index 8c2ffc1a811..f3f2527eb09 100644 --- a/tests/TestCase/Core/StaticConfigTraitTest.php +++ b/tests/TestCase/Core/StaticConfigTraitTest.php @@ -411,4 +411,36 @@ public function testParseDsnPathSetting() { $this->assertEquals($expected, TestLogStaticConfig::parseDsn($dsn)); } +/** + * Test that the dsn map can be updated/append to + * + * @return void + */ + public function testCanUpdateClassMap() { + $expected = [ + 'console' => 'Cake\Log\Engine\ConsoleLog', + 'file' => 'Cake\Log\Engine\FileLog', + 'syslog' => 'Cake\Log\Engine\SyslogLog', + ]; + $result = TestLogStaticConfig::dsnClassMap(); + $this->assertEquals($expected, $result, "The class map should match the class property"); + + $expected = [ + 'console' => 'Special\EngineLog', + 'file' => 'Cake\Log\Engine\FileLog', + 'syslog' => 'Cake\Log\Engine\SyslogLog', + ]; + $result = TestLogStaticConfig::dsnClassMap(['console' => 'Special\EngineLog']); + $this->assertEquals($expected, $result, "Should be possible to change the map"); + + $expected = [ + 'console' => 'Special\EngineLog', + 'file' => 'Cake\Log\Engine\FileLog', + 'syslog' => 'Cake\Log\Engine\SyslogLog', + 'my' => 'Special\OtherLog' + ]; + $result = TestLogStaticConfig::dsnClassMap(['my' => 'Special\OtherLog']); + $this->assertEquals($expected, $result, "Should be possible to add to the map"); + } + }