Odyssey
DBConnTest.php
1 <?php
2 
3 $sharedLibrary = "/var/www/html/shared/library";
4 require_once("$sharedLibrary/hcuCommon.i");
5 require_once("$sharedLibrary/hcuEnv.i");
6 require_once("$sharedLibrary/db.postgres.i");
7 
8 use PHPUnit\Framework\TestCase;
9 
10 class DBConnTest extends TestCase
11 {
12  protected static $conn;
13 
14  protected function setUp() {
15  $dbInfo = HCU_array_key_value("db", LoadSystemEnv("banking"));
16  self::$conn = db_connect($dbInfo);
17  }
18 
19  protected function tearDown() {
20  pg_close(self::$conn);
21  }
22 
23  public function test_db_connection() {
24  $this->assertNotFalse(self::$conn);
25  $query_result = db_query("select 1", self::$conn);
26  $result = (int)pg_fetch_result($query_result, 0, 0);
27  $this->assertEquals(1, $result);
28  }
29 
30  public function test_db_connection_again() {
31  $this->assertNotFalse(self::$conn);
32  $query_result = db_query("select 2", self::$conn);
33  $result = (int)pg_fetch_result($query_result, 0, 0);
34  $this->assertEquals(2, $result);
35  }
36 }