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 | public function test_db_invalid() |
Taufan Aditya | 655a89f | 2012-03-29 03:00:56 +0700 | [diff] [blame] | 6 | { |
Taufan Aditya | ee2f5d0 | 2012-03-30 06:29:11 +0700 | [diff] [blame] | 7 | $connection = new Mock_Database_DB(array( |
Taufan Aditya | a8a2e33 | 2012-03-29 03:56:46 +0700 | [diff] [blame] | 8 | 'undefined' => array( |
| 9 | 'dsn' => '', |
| 10 | 'hostname' => 'undefined', |
| 11 | 'username' => 'undefined', |
| 12 | 'password' => 'undefined', |
| 13 | 'database' => 'undefined', |
| 14 | 'dbdriver' => 'undefined', |
| 15 | ), |
| 16 | )); |
| 17 | |
Andrey Andreev | 15170ff | 2015-02-19 16:00:40 +0200 | [diff] [blame] | 18 | $this->setExpectedException('RuntimeException', 'CI Error: Invalid DB driver'); |
Taufan Aditya | a8a2e33 | 2012-03-29 03:56:46 +0700 | [diff] [blame] | 19 | |
Taufan Aditya | ee2f5d0 | 2012-03-30 06:29:11 +0700 | [diff] [blame] | 20 | Mock_Database_DB::DB($connection->set_dsn('undefined'), TRUE); |
Taufan Aditya | a8a2e33 | 2012-03-29 03:56:46 +0700 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | // ------------------------------------------------------------------------ |
| 24 | |
| 25 | public function test_db_valid() |
| 26 | { |
Taufan Aditya | ee2f5d0 | 2012-03-30 06:29:11 +0700 | [diff] [blame] | 27 | $config = Mock_Database_DB::config(DB_DRIVER); |
| 28 | $connection = new Mock_Database_DB($config); |
Andrey Andreev | 03bafe9 | 2015-02-19 17:22:14 +0200 | [diff] [blame] | 29 | |
| 30 | // E_DEPRECATED notices thrown by mysql_connect(), mysql_pconnect() |
| 31 | // on PHP 5.5+ cause the tests to fail |
| 32 | if (DB_DRIVER === 'mysql' && version_compare(PHP_VERSION, '5.5', '>=')) |
| 33 | { |
| 34 | error_reporting(E_ALL & ~E_DEPRECATED); |
| 35 | } |
| 36 | |
Taufan Aditya | ee2f5d0 | 2012-03-30 06:29:11 +0700 | [diff] [blame] | 37 | $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER), TRUE); |
Taufan Aditya | 655a89f | 2012-03-29 03:00:56 +0700 | [diff] [blame] | 38 | |
Andrey Andreev | 20d9b0a | 2017-12-20 19:57:39 +0200 | [diff] [blame^] | 39 | $this->assertInstanceOf('CI_DB', $db); |
| 40 | $this->assertInstanceOf('CI_DB_Driver', $db); |
Taufan Aditya | ee2f5d0 | 2012-03-30 06:29:11 +0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | // ------------------------------------------------------------------------ |
| 44 | |
Andrey Andreev | 15170ff | 2015-02-19 16:00:40 +0200 | [diff] [blame] | 45 | /* |
| 46 | This test is unusable, because whoever wrote it apparently thought that |
| 47 | an E_WARNING should equal an Exception and based the whole test suite |
| 48 | around that bogus assumption. |
| 49 | |
Taufan Aditya | ee2f5d0 | 2012-03-30 06:29:11 +0700 | [diff] [blame] | 50 | public function test_db_failover() |
| 51 | { |
| 52 | $config = Mock_Database_DB::config(DB_DRIVER); |
| 53 | $connection = new Mock_Database_DB($config); |
Andrey Andreev | 15170ff | 2015-02-19 16:00:40 +0200 | [diff] [blame] | 54 | $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER.'_failover'), TRUE); |
Taufan Aditya | ee2f5d0 | 2012-03-30 06:29:11 +0700 | [diff] [blame] | 55 | |
Andrey Andreev | 20d9b0a | 2017-12-20 19:57:39 +0200 | [diff] [blame^] | 56 | $this->assertInstanceOf('CI_DB', $db); |
| 57 | $this->assertInstanceOf('CI_DB_Driver', $db); |
Taufan Aditya | 655a89f | 2012-03-29 03:00:56 +0700 | [diff] [blame] | 58 | } |
Andrey Andreev | 15170ff | 2015-02-19 16:00:40 +0200 | [diff] [blame] | 59 | */ |
Andrey Andreev | 59d6b4f | 2012-05-25 02:08:00 +0300 | [diff] [blame] | 60 | |
Andrey Andreev | 20d9b0a | 2017-12-20 19:57:39 +0200 | [diff] [blame^] | 61 | } |