blob: 9b93e223de93824f3333645dc951b45e2e4f40f5 [file] [log] [blame]
Taufan Aditya655a89f2012-03-29 03:00:56 +07001<?php
2
3class DB_test extends CI_TestCase {
4
Taufan Adityaa8a2e332012-03-29 03:56:46 +07005 // ------------------------------------------------------------------------
Taufan Aditya655a89f2012-03-29 03:00:56 +07006
Taufan Adityaa8a2e332012-03-29 03:56:46 +07007 public function test_db_invalid()
Taufan Aditya655a89f2012-03-29 03:00:56 +07008 {
Taufan Adityaee2f5d02012-03-30 06:29:11 +07009 $connection = new Mock_Database_DB(array(
Taufan Adityaa8a2e332012-03-29 03:56:46 +070010 '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 Adityaee2f5d02012-03-30 06:29:11 +070022 Mock_Database_DB::DB($connection->set_dsn('undefined'), TRUE);
Taufan Adityaa8a2e332012-03-29 03:56:46 +070023 }
24
25 // ------------------------------------------------------------------------
26
27 public function test_db_valid()
28 {
Taufan Adityaee2f5d02012-03-30 06:29:11 +070029 $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 Aditya655a89f2012-03-29 03:00:56 +070032
33 $this->assertTrue($db instanceof CI_DB);
34 $this->assertTrue($db instanceof CI_DB_Driver);
Taufan Adityaee2f5d02012-03-30 06:29:11 +070035 }
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 Aditya655a89f2012-03-29 03:00:56 +070047 }
48
49}