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.

LuApplicationTest.php 2.9KB

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