]> git.openstreetmap.org Git - nominatim.git/blob - test/php/Nominatim/DatabaseErrorTest.php
Issue templates: more commenting of instructions
[nominatim.git] / test / php / Nominatim / DatabaseErrorTest.php
1 <?php
2
3 namespace Nominatim;
4
5 require_once(CONST_BasePath.'/lib/init-website.php');
6 require_once(CONST_BasePath.'/lib/DatabaseError.php');
7
8 class DatabaseErrorTest extends \PHPUnit\Framework\TestCase
9 {
10
11     public function testSqlMessage()
12     {
13         $oSqlStub = $this->getMockBuilder(PDOException::class)
14                     ->setMethods(array('getMessage'))
15                     ->getMock();
16
17         $oSqlStub->method('getMessage')
18                 ->willReturn('Unknown table.');
19
20         $oErr = new DatabaseError('Sql error', 123, null, $oSqlStub);
21         $this->assertEquals('Sql error', $oErr->getMessage());
22         $this->assertEquals(123, $oErr->getCode());
23         $this->assertEquals('Unknown table.', $oErr->getSqlError());
24     }
25
26     public function testSqlObjectDump()
27     {
28         $oErr = new DatabaseError('Sql error', 123, null, array('one' => 'two'));
29         $this->assertRegExp('/two/', $oErr->getSqlDebugDump());
30     }
31 }