You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. use Luticate\Utils\Controller\LuticateApplication;
  3. use Luticate\Utils\Dbo\LuDboDeserializeException;
  4. use Luticate\Utils\Dbo\LuBoolDboArray;
  5. /**
  6. * Created by PhpStorm.
  7. * User: robin
  8. * Date: 5/29/16
  9. * Time: 2:57 PM
  10. */
  11. class LuApplicationTest extends \PHPUnit_Framework_TestCase
  12. {
  13. public function testGetDatabases1()
  14. {
  15. $db1 = ["name" => "mydb", "other_info" => 42];
  16. $dbs = [$db1];
  17. $this->assertSame($db1, LuticateApplication::getDatabase($db1["name"], $dbs));
  18. }
  19. public function testGetDatabases2()
  20. {
  21. $db1 = ["name" => "mydb", "other_info" => 42];
  22. $dbs = [$db1];
  23. $this->assertNull(LuticateApplication::getDatabase("db", $dbs));
  24. }
  25. public function testGetDatabases3()
  26. {
  27. $db1 = ["name" => "mydb", "other_info" => 42];
  28. $db2 = ["name" => "myotherdb", "other_info" => 42];
  29. $dbs = [$db1, $db2];
  30. $this->assertSame($db2, LuticateApplication::getDatabase($db2["name"], $dbs));
  31. }
  32. public function testGetDatabases4()
  33. {
  34. $db1 = ["name" => "mydb", "other_info" => 42];
  35. $db2 = ["name" => "myotherdb", "other_info" => 42];
  36. $dbs = [$db1, $db2];
  37. $this->assertNull(LuticateApplication::getDatabase("anotherdb", $dbs));
  38. }
  39. public function testGetDatabases5()
  40. {
  41. $db1 = ["name" => "mydb", "other_info" => 42];
  42. $db2 = ["name" => "myotherdb", "alias" => "mydb"];
  43. $dbs = [$db1, $db2];
  44. $this->assertNull(LuticateApplication::getDatabase("myotherdb", $dbs));
  45. }
  46. public function testResolveDatabases1()
  47. {
  48. $db1 = ["name" => "mydb", "other_info" => 42];
  49. $dbs = [$db1, ["name" => "mydb2", "alias" => "mydb"]];
  50. $dbRes = $db1;
  51. $dbRes["name"] = "mydb2";
  52. $this->assertSame([$db1, $dbRes], LuticateApplication::resolveDatabases($dbs));
  53. }
  54. public function testResolveDatabases2()
  55. {
  56. $db1 = ["name" => "mydb", "other_info" => 42];
  57. $dbs = [$db1, "mydb2"];
  58. $this->assertSame([$db1], LuticateApplication::resolveDatabases($dbs));
  59. }
  60. public function testResolveDatabases3()
  61. {
  62. $db1 = ["name" => "mydb", "other_info" => 42];
  63. $dbs = [["name" => "mydb2", "alias" => "mydb2"], $db1];
  64. $this->assertSame([$db1], LuticateApplication::resolveDatabases($dbs));
  65. }
  66. public function testResolveDatabases4()
  67. {
  68. $db1 = ["name" => "mydb", "other_info" => 42];
  69. $dbs = [["name" => "mydb2", "alias" => "mydb"], $db1];
  70. $dbRes = $db1;
  71. $dbRes["name"] = "mydb2";
  72. $this->assertSame([$dbRes, $db1], LuticateApplication::resolveDatabases($dbs));
  73. }
  74. public function testResolveDatabases5()
  75. {
  76. $db1 = ["name" => "mydb", "other_info" => 42, "other_info2" => 24];
  77. $dbs = [["name" => "mydb2", "alias" => "mydb", "other_info2" => 42], $db1];
  78. $dbRes = $db1;
  79. $dbRes["name"] = "mydb2";
  80. $dbRes["other_info2"] = 42;
  81. $this->assertSame([$dbRes, $db1], LuticateApplication::resolveDatabases($dbs));
  82. }
  83. public function testSettings1()
  84. {
  85. $this->assertSame(42, LuticateApplication::getInstance()->getSetting("test"));
  86. }
  87. public function testSettings2()
  88. {
  89. $this->assertNull(LuticateApplication::getInstance()->getSetting("not-a-setting"));
  90. }
  91. public function testSettings3()
  92. {
  93. putenv("lu_setting_test=24");
  94. $this->assertSame("24", LuticateApplication::getInstance()->getSetting("test"));
  95. putenv("lu_setting_test");
  96. }
  97. public function testSettings4()
  98. {
  99. $this->assertSame("defaultValue", LuticateApplication::getInstance()->getSetting("not-a-setting", "defaultValue"));
  100. }
  101. public function testSettings5()
  102. {
  103. $this->assertSame(42, LuticateApplication::getInstance()->getSetting("test", "defaultValue"));
  104. }
  105. }