3  * SPDX-License-Identifier: GPL-2.0-only
 
   5  * This file is part of Nominatim. (https://nominatim.org)
 
   7  * Copyright (C) 2022 by the Nominatim developer community.
 
   8  * For a full list of authors see the git log.
 
  13 require_once(CONST_LibDir.'/init-website.php');
 
  14 require_once(CONST_LibDir.'/DatabaseError.php');
 
  16 class DatabaseErrorTest extends \PHPUnit\Framework\TestCase
 
  19     public function testSqlMessage()
 
  21         $oSqlStub = $this->getMockBuilder(PDOException::class)
 
  22                     ->setMethods(array('getMessage'))
 
  25         $oSqlStub->method('getMessage')
 
  26                 ->willReturn('Unknown table.');
 
  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());
 
  34     public function testSqlObjectDump()
 
  36         $oErr = new DatabaseError('Sql error', 123, null, array('one' => 'two'));
 
  37         $this->assertStringContainsString('two', $oErr->getSqlDebugDump());