예제 #1
0
 public function testGetWithConnect()
 {
     $status = false;
     // not connected at start
     $open = function () use(&$status) {
         if ($status) {
             throw new \Exception("Already connected");
         }
         $status = true;
         return "FAKE DB CONNECTION";
     };
     $close = function ($db) use(&$status) {
         if (!$status) {
             throw new \Exception("Already closed");
         }
         $status = false;
     };
     Connections::add('tested', $open, $close);
     $this->assertEquals(false, static::$ref_connections->getValue()['tested']);
     $this->assertSame($open, static::$ref_open->getValue()['tested']);
     $this->assertSame($close, static::$ref_close->getValue()['tested']);
     $expected = "FAKE DB CONNECTION";
     $result = Connections::get('tested');
     $this->assertTrue($status);
     $this->assertEquals($expected, $result);
     $this->assertEquals($expected, static::$ref_connections->getValue()['tested']);
     // This should NOT throw MissingConfig
     $result = Connections::get('tested');
     $this->assertEquals($expected, $result);
     Connections::close('tested');
     $this->assertFalse($status);
     $this->assertEquals(false, static::$ref_connections->getValue()['tested']);
 }
예제 #2
0
 public function testTableName()
 {
     $users = array('engine' => 'mysql', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'port' => '3306', 'database' => 'users');
     $user_db = new \Database($users);
     \Connections::add('user', $user_db);
     $userModel = new \UserModel();
     $user_table = $userModel->table_name();
     $this->assertEquals($user_table, 'user');
 }
예제 #3
0
 public function testMultipleDatabase()
 {
     $database = array('engine' => 'mysql', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'port' => '3306', 'database' => 'test');
     $database1 = array('engine' => 'mysql', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'port' => '3307', 'database' => 'test1');
     $db = new \Database($database);
     \Connections::add('test', $db);
     $db1 = new \Database($database1);
     \Connections::add('test1', $db1);
     $this->assertEquals($db, \Connections::get('test'));
     $this->assertEquals($db1, \Connections::get('test1'));
     $this->assertFalse($db === $db1);
 }
예제 #4
0
<?php

/* Database configuration */
$users = array('engine' => 'mysql', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'port' => '3306', 'database' => 'users');
$posts = array('engine' => 'mysql', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'port' => '3307', 'database' => 'posts');
$core = array('engine' => 'mysql', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'port' => '3306', 'database' => 'core');
$test = array('engine' => 'mysql', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'port' => '3306', 'database' => 'test');
$user_db = new Database($users);
Connections::add('user', $user_db);
$post_db = new Database($posts);
Connections::add('post', $post_db);
$core_db = new Database($core);
Connections::add('core', $core_db);
$test_db = new Database($test);
Connections::add('test', $test_db);
//Connections::add('test', "string");
/* Migration */
$user = new UserModel();
//$user->migrate();
$post = new PostModel($post_db);
//$post->migrate();