123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- use Luticate\Utils\Controller\LuticateApplication;
- use Luticate\Utils\Dbo\LuDboDeserializeException;
- use Luticate\Utils\Dbo\LuBoolDboArray;
-
- /**
- * Created by PhpStorm.
- * User: robin
- * Date: 5/29/16
- * Time: 2:57 PM
- */
-
- class LuApplicationTest extends \PHPUnit_Framework_TestCase
- {
- public function testGetDatabases1()
- {
- $db1 = ["name" => "mydb", "other_info" => 42];
- $dbs = [$db1];
- $this->assertSame($db1, LuticateApplication::getDatabase($db1["name"], $dbs));
- }
-
- public function testGetDatabases2()
- {
- $db1 = ["name" => "mydb", "other_info" => 42];
- $dbs = [$db1];
- $this->assertNull(LuticateApplication::getDatabase("db", $dbs));
- }
-
- public function testGetDatabases3()
- {
- $db1 = ["name" => "mydb", "other_info" => 42];
- $db2 = ["name" => "myotherdb", "other_info" => 42];
- $dbs = [$db1, $db2];
- $this->assertSame($db2, LuticateApplication::getDatabase($db2["name"], $dbs));
- }
-
- public function testGetDatabases4()
- {
- $db1 = ["name" => "mydb", "other_info" => 42];
- $db2 = ["name" => "myotherdb", "other_info" => 42];
- $dbs = [$db1, $db2];
- $this->assertNull(LuticateApplication::getDatabase("anotherdb", $dbs));
- }
-
- public function testResolveDatabases1()
- {
- $db1 = ["name" => "mydb", "other_info" => 42];
- $dbs = [$db1, ["name" => "mydb2", "alias" => "mydb"]];
- $dbRes = $db1;
- $dbRes["name"] = "mydb2";
- $this->assertSame([$db1, $dbRes], LuticateApplication::resolveDatabases($dbs));
- }
-
- public function testResolveDatabases2()
- {
- $db1 = ["name" => "mydb", "other_info" => 42];
- $dbs = [$db1, "mydb2"];
- $this->assertSame([$db1], LuticateApplication::resolveDatabases($dbs));
- }
-
- public function testResolveDatabases3()
- {
- $db1 = ["name" => "mydb", "other_info" => 42];
- $dbs = [["name" => "mydb2", "alias" => "mydb2"], $db1];
- $this->assertSame([$db1], LuticateApplication::resolveDatabases($dbs));
- }
-
- public function testResolveDatabases4()
- {
- $db1 = ["name" => "mydb", "other_info" => 42];
- $dbs = [["name" => "mydb2", "alias" => "mydb"], $db1];
- $dbRes = $db1;
- $dbRes["name"] = "mydb2";
- $this->assertSame([$dbRes, $db1], LuticateApplication::resolveDatabases($dbs));
- }
-
- public function testResolveDatabases5()
- {
- $db1 = ["name" => "mydb", "other_info" => 42, "other_info2" => 24];
- $dbs = [["name" => "mydb2", "alias" => "mydb", "other_info2" => 42], $db1];
- $dbRes = $db1;
- $dbRes["name"] = "mydb2";
- $dbRes["other_info2"] = 42;
- $this->assertSame([$dbRes, $db1], LuticateApplication::resolveDatabases($dbs));
- }
-
- public function testSettings1()
- {
- $this->assertSame(42, LuticateApplication::getInstance()->getSetting("test"));
- }
-
- public function testSettings2()
- {
- $this->assertNull(LuticateApplication::getInstance()->getSetting("not-a-setting"));
- }
-
- public function testSettings3()
- {
- putenv("lu_setting_test=24");
- $this->assertSame("24", LuticateApplication::getInstance()->getSetting("test"));
- putenv("lu_setting_test");
- }
-
- public function testSettings4()
- {
- $this->assertSame("defaultValue", LuticateApplication::getInstance()->getSetting("not-a-setting", "defaultValue"));
- }
-
- public function testSettings5()
- {
- $this->assertSame(42, LuticateApplication::getInstance()->getSetting("test", "defaultValue"));
- }
- }
|