Taufan Aditya | 655a89f | 2012-03-29 03:00:56 +0700 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | class DB_test extends CI_TestCase { |
| 4 | |
Taufan Aditya | a8a2e33 | 2012-03-29 03:56:46 +0700 | [diff] [blame] | 5 | // ------------------------------------------------------------------------ |
Taufan Aditya | 655a89f | 2012-03-29 03:00:56 +0700 | [diff] [blame] | 6 | |
Taufan Aditya | a8a2e33 | 2012-03-29 03:56:46 +0700 | [diff] [blame] | 7 | public function test_db_invalid() |
Taufan Aditya | 655a89f | 2012-03-29 03:00:56 +0700 | [diff] [blame] | 8 | { |
Taufan Aditya | ee2f5d0 | 2012-03-30 06:29:11 +0700 | [diff] [blame] | 9 | $connection = new Mock_Database_DB(array( |
Taufan Aditya | a8a2e33 | 2012-03-29 03:56:46 +0700 | [diff] [blame] | 10 | 'undefined' => array( |
| 11 | 'dsn' => '', |
| 12 | 'hostname' => 'undefined', |
| 13 | 'username' => 'undefined', |
| 14 | 'password' => 'undefined', |
| 15 | 'database' => 'undefined', |
| 16 | 'dbdriver' => 'undefined', |
| 17 | ), |
| 18 | )); |
| 19 | |
| 20 | $this->setExpectedException('InvalidArgumentException', 'CI Error: Invalid DB driver'); |
| 21 | |
Taufan Aditya | ee2f5d0 | 2012-03-30 06:29:11 +0700 | [diff] [blame] | 22 | Mock_Database_DB::DB($connection->set_dsn('undefined'), TRUE); |
Taufan Aditya | a8a2e33 | 2012-03-29 03:56:46 +0700 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | // ------------------------------------------------------------------------ |
| 26 | |
| 27 | public function test_db_valid() |
| 28 | { |
Taufan Aditya | ee2f5d0 | 2012-03-30 06:29:11 +0700 | [diff] [blame] | 29 | $config = Mock_Database_DB::config(DB_DRIVER); |
| 30 | $connection = new Mock_Database_DB($config); |
| 31 | $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER), TRUE); |
Taufan Aditya | 655a89f | 2012-03-29 03:00:56 +0700 | [diff] [blame] | 32 | |
| 33 | $this->assertTrue($db instanceof CI_DB); |
| 34 | $this->assertTrue($db instanceof CI_DB_Driver); |
Taufan Aditya | ee2f5d0 | 2012-03-30 06:29:11 +0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | // ------------------------------------------------------------------------ |
| 38 | |
| 39 | public function test_db_failover() |
| 40 | { |
| 41 | $config = Mock_Database_DB::config(DB_DRIVER); |
| 42 | $connection = new Mock_Database_DB($config); |
| 43 | $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER.'_failover'), TRUE); |
| 44 | |
| 45 | $this->assertTrue($db instanceof CI_DB); |
| 46 | $this->assertTrue($db instanceof CI_DB_Driver); |
Taufan Aditya | 655a89f | 2012-03-29 03:00:56 +0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | } |