Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

LuApplicationTest.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 testResolveDatabases1()
  40. {
  41. $db1 = ["name" => "mydb", "other_info" => 42];
  42. $dbs = [$db1, ["name" => "mydb2", "alias" => "mydb"]];
  43. $dbRes = $db1;
  44. $dbRes["name"] = "mydb2";
  45. $this->assertSame([$db1, $dbRes], LuticateApplication::resolveDatabases($dbs));
  46. }
  47. public function testResolveDatabases2()
  48. {
  49. $db1 = ["name" => "mydb", "other_info" => 42];
  50. $dbs = [$db1, "mydb2"];
  51. $this->assertSame([$db1], LuticateApplication::resolveDatabases($dbs));
  52. }
  53. public function testResolveDatabases3()
  54. {
  55. $db1 = ["name" => "mydb", "other_info" => 42];
  56. $dbs = [["name" => "mydb2", "alias" => "mydb2"], $db1];
  57. $this->assertSame([$db1], LuticateApplication::resolveDatabases($dbs));
  58. }
  59. public function testResolveDatabases4()
  60. {
  61. $db1 = ["name" => "mydb", "other_info" => 42];
  62. $dbs = [["name" => "mydb2", "alias" => "mydb"], $db1];
  63. $dbRes = $db1;
  64. $dbRes["name"] = "mydb2";
  65. $this->assertSame([$dbRes, $db1], LuticateApplication::resolveDatabases($dbs));
  66. }
  67. public function testResolveDatabases5()
  68. {
  69. $db1 = ["name" => "mydb", "other_info" => 42, "other_info2" => 24];
  70. $dbs = [["name" => "mydb2", "alias" => "mydb", "other_info2" => 42], $db1];
  71. $dbRes = $db1;
  72. $dbRes["name"] = "mydb2";
  73. $dbRes["other_info2"] = 42;
  74. $this->assertSame([$dbRes, $db1], LuticateApplication::resolveDatabases($dbs));
  75. }
  76. public function testSettings1()
  77. {
  78. $this->assertSame(42, LuticateApplication::getInstance()->getSetting("test"));
  79. }
  80. public function testSettings2()
  81. {
  82. $this->assertNull(LuticateApplication::getInstance()->getSetting("not-a-setting"));
  83. }
  84. public function testSettings3()
  85. {
  86. putenv("lu_setting_test=24");
  87. $this->assertSame("24", LuticateApplication::getInstance()->getSetting("test"));
  88. putenv("lu_setting_test");
  89. }
  90. public function testSettings4()
  91. {
  92. $this->assertSame("defaultValue", LuticateApplication::getInstance()->getSetting("not-a-setting", "defaultValue"));
  93. }
  94. public function testSettings5()
  95. {
  96. $this->assertSame(42, LuticateApplication::getInstance()->getSetting("test", "defaultValue"));
  97. }
  98. }