]> git.openstreetmap.org Git - nominatim.git/blob - test/php/Nominatim/DatabaseErrorTest.php
work around strange query planning behaviour
[nominatim.git] / test / php / Nominatim / DatabaseErrorTest.php
1 <?php
2 /**
3  * SPDX-License-Identifier: GPL-2.0-only
4  *
5  * This file is part of Nominatim. (https://nominatim.org)
6  *
7  * Copyright (C) 2022 by the Nominatim developer community.
8  * For a full list of authors see the git log.
9  */
10
11 namespace Nominatim;
12
13 require_once(CONST_LibDir.'/init-website.php');
14 require_once(CONST_LibDir.'/DatabaseError.php');
15
16 class DatabaseErrorTest extends \PHPUnit\Framework\TestCase
17 {
18
19     public function testSqlMessage()
20     {
21         $oSqlStub = $this->getMockBuilder(PDOException::class)
22                     ->setMethods(array('getMessage'))
23                     ->getMock();
24
25         $oSqlStub->method('getMessage')
26                 ->willReturn('Unknown table.');
27
28         $oErr = new DatabaseError('Sql error', 123, null, $oSqlStub);
29         $this->assertEquals('Sql error', $oErr->getMessage());
30         $this->assertEquals(123, $oErr->getCode());
31         $this->assertEquals('Unknown table.', $oErr->getSqlError());
32     }
33
34     public function testSqlObjectDump()
35     {
36         $oErr = new DatabaseError('Sql error', 123, null, array('one' => 'two'));
37         $this->assertStringContainsString('two', $oErr->getSqlDebugDump());
38     }
39 }