Explorar el Código

fixed database aliases

develop
Robin Thoni hace 8 años
padre
commit
bc3d1a8de5
Se han modificado 2 ficheros con 36 adiciones y 8 borrados
  1. 17
    3
      src/Utils/Controller/LuticateApplication.php
  2. 19
    5
      tests/LuApplicationTest.php

+ 17
- 3
src/Utils/Controller/LuticateApplication.php Ver fichero

@@ -34,7 +34,7 @@ class LuticateApplication implements MessageComponentInterface
34 34
     public static function getDatabase($name, $databases)
35 35
     {
36 36
         foreach ($databases as $database) {
37
-            if (is_array($database) && $database["name"] == $name) {
37
+            if (is_array($database) && $database["name"] == $name && !isset($database["alias"])) {
38 38
                 return $database;
39 39
             }
40 40
         }
@@ -44,9 +44,23 @@ class LuticateApplication implements MessageComponentInterface
44 44
     public static function resolveDatabases($databases) {
45 45
         $dbs = [];
46 46
         foreach ($databases as $database) {
47
-            if (is_string($database)) {
48
-                $database = static::getDatabase($database, $databases);
47
+            if (isset($database["alias"])) {
48
+                $db = static::getDatabase($database["alias"], $databases);
49
+                unset($database["alias"]);
50
+                if (!is_null($db)) {
51
+                    $database = array_merge($db, $database);
52
+                }
53
+                else {
54
+                    $database = null;
55
+                }
49 56
             }
57
+//            if (is_string($database)) {
58
+//                $name = $database;
59
+//                $database = static::getDatabase($name, $databases);
60
+//                if (!is_null($database)) {
61
+//                    $database["name"] = $name;
62
+//                }
63
+//            }
50 64
             if (is_array($database)) {
51 65
                 $dbs[] = $database;
52 66
             }

+ 19
- 5
tests/LuApplicationTest.php Ver fichero

@@ -45,8 +45,10 @@ class LuApplicationTest extends \PHPUnit_Framework_TestCase
45 45
     public function testResolveDatabases1()
46 46
     {
47 47
         $db1 = ["name" => "mydb", "other_info" => 42];
48
-        $dbs = [$db1, "mydb"];
49
-        $this->assertSame([$db1, $db1], LuticateApplication::resolveDatabases($dbs));
48
+        $dbs = [$db1, ["name" => "mydb2", "alias" => "mydb"]];
49
+        $dbRes = $db1;
50
+        $dbRes["name"] = "mydb2";
51
+        $this->assertSame([$db1, $dbRes], LuticateApplication::resolveDatabases($dbs));
50 52
     }
51 53
 
52 54
     public function testResolveDatabases2()
@@ -59,15 +61,27 @@ class LuApplicationTest extends \PHPUnit_Framework_TestCase
59 61
     public function testResolveDatabases3()
60 62
     {
61 63
         $db1 = ["name" => "mydb", "other_info" => 42];
62
-        $dbs = ["mydb2", $db1];
64
+        $dbs = [["name" => "mydb2", "alias" => "mydb2"], $db1];
63 65
         $this->assertSame([$db1], LuticateApplication::resolveDatabases($dbs));
64 66
     }
65 67
 
66 68
     public function testResolveDatabases4()
67 69
     {
68 70
         $db1 = ["name" => "mydb", "other_info" => 42];
69
-        $dbs = ["mydb", $db1];
70
-        $this->assertSame([$db1, $db1], LuticateApplication::resolveDatabases($dbs));
71
+        $dbs = [["name" => "mydb2", "alias" => "mydb"], $db1];
72
+        $dbRes = $db1;
73
+        $dbRes["name"] = "mydb2";
74
+        $this->assertSame([$dbRes, $db1], LuticateApplication::resolveDatabases($dbs));
75
+    }
76
+
77
+    public function testResolveDatabases5()
78
+    {
79
+        $db1 = ["name" => "mydb", "other_info" => 42, "other_info2" => 24];
80
+        $dbs = [["name" => "mydb2", "alias" => "mydb", "other_info2" => 42], $db1];
81
+        $dbRes = $db1;
82
+        $dbRes["name"] = "mydb2";
83
+        $dbRes["other_info2"] = 42;
84
+        $this->assertSame([$dbRes, $db1], LuticateApplication::resolveDatabases($dbs));
71 85
     }
72 86
 
73 87
     public function testSettings1()

Loading…
Cancelar
Guardar