5 require_once(CONST_BasePath.'/lib/lib.php');
6 require_once(CONST_BasePath.'/lib/db.php');
8 class DBTest extends \PHPUnit\Framework\TestCase
11 public function testErrorHandling()
13 $this->expectException(DatabaseError::class);
14 $this->expectExceptionMessage('Failed to establish database connection');
16 $oDB = new \Nominatim\DB('pgsql:dbname=abc');
20 public function testErrorHandling2()
22 $this->expectException(DatabaseError::class);
23 $this->expectExceptionMessage('Database query failed');
25 $oPDOStub = $this->getMockBuilder(PDO::class)
26 ->setMethods(array('query', 'quote'))
29 $oPDOStub->method('query')
30 ->will($this->returnCallback(function ($sVal) {
34 $oPDOStub->method('query')
35 ->will($this->returnCallback(function () {
36 throw new \PDOException('ERROR: syntax error at or near "FROM"');
39 $oDB = new \Nominatim\DB('');
40 $oDB->connection = $oPDOStub;
41 $oDB->tableExists('abc');
44 public function testParseDSN()
48 \Nominatim\DB::parseDSN('')
53 'hostspec' => 'machine1'
55 \Nominatim\DB::parseDSN('pgsql:dbname=db1;host=machine1')
60 'hostspec' => 'machine1',
63 'password' => 'secret'
65 \Nominatim\DB::parseDSN('pgsql:dbname=db1;host=machine1;port=1234;user=john;password=secret')