Browse Source

add tests modifying the dsn class map

It should be possible to redefine the map - or add to it.
AD7six 11 years ago
parent
commit
b69cf9c3c5
2 changed files with 33 additions and 1 deletions
  1. 1 1
      src/Core/StaticConfigTrait.php
  2. 32 0
      tests/TestCase/Core/StaticConfigTraitTest.php

+ 1 - 1
src/Core/StaticConfigTrait.php

@@ -236,7 +236,7 @@ trait StaticConfigTrait {
  */
 	public static function dsnClassMap($map = null) {
 		if ($map) {
-			static::$_dsnClassMap = $map + $_dsnClassMap;
+			static::$_dsnClassMap = $map + static::$_dsnClassMap;
 		}
 		return static::$_dsnClassMap;
 	}

+ 32 - 0
tests/TestCase/Core/StaticConfigTraitTest.php

@@ -411,4 +411,36 @@ class StaticConfigTraitTest extends TestCase {
 		$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");
+	}
+
 }