blob: 9d53fd6f258809d0f3f2d71884b136714b6e1c13 [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 public function test_db_invalid()
Taufan Aditya655a89f2012-03-29 03:00:56 +07006 {
Taufan Adityaee2f5d02012-03-30 06:29:11 +07007 $connection = new Mock_Database_DB(array(
Taufan Adityaa8a2e332012-03-29 03:56:46 +07008 'undefined' => array(
9 'dsn' => '',
10 'hostname' => 'undefined',
11 'username' => 'undefined',
12 'password' => 'undefined',
13 'database' => 'undefined',
14 'dbdriver' => 'undefined',
15 ),
16 ));
17
Andrey Andreev15170ff2015-02-19 16:00:40 +020018 $this->setExpectedException('RuntimeException', 'CI Error: Invalid DB driver');
Taufan Adityaa8a2e332012-03-29 03:56:46 +070019
Taufan Adityaee2f5d02012-03-30 06:29:11 +070020 Mock_Database_DB::DB($connection->set_dsn('undefined'), TRUE);
Taufan Adityaa8a2e332012-03-29 03:56:46 +070021 }
22
23 // ------------------------------------------------------------------------
24
25 public function test_db_valid()
26 {
Taufan Adityaee2f5d02012-03-30 06:29:11 +070027 $config = Mock_Database_DB::config(DB_DRIVER);
28 $connection = new Mock_Database_DB($config);
Andrey Andreev03bafe92015-02-19 17:22:14 +020029
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 Adityaee2f5d02012-03-30 06:29:11 +070037 $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER), TRUE);
Taufan Aditya655a89f2012-03-29 03:00:56 +070038
Andrey Andreev20d9b0a2017-12-20 19:57:39 +020039 $this->assertInstanceOf('CI_DB', $db);
40 $this->assertInstanceOf('CI_DB_Driver', $db);
Taufan Adityaee2f5d02012-03-30 06:29:11 +070041 }
42
43 // ------------------------------------------------------------------------
44
Andrey Andreev15170ff2015-02-19 16:00:40 +020045/*
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 Adityaee2f5d02012-03-30 06:29:11 +070050 public function test_db_failover()
51 {
52 $config = Mock_Database_DB::config(DB_DRIVER);
53 $connection = new Mock_Database_DB($config);
Andrey Andreev15170ff2015-02-19 16:00:40 +020054 $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER.'_failover'), TRUE);
Taufan Adityaee2f5d02012-03-30 06:29:11 +070055
Andrey Andreev20d9b0a2017-12-20 19:57:39 +020056 $this->assertInstanceOf('CI_DB', $db);
57 $this->assertInstanceOf('CI_DB_Driver', $db);
Taufan Aditya655a89f2012-03-29 03:00:56 +070058 }
Andrey Andreev15170ff2015-02-19 16:00:40 +020059*/
Andrey Andreev59d6b4f2012-05-25 02:08:00 +030060
Andrey Andreev20d9b0a2017-12-20 19:57:39 +020061}