mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-16 15:47:58 +00:00
Nominatim::DB support input variables, custom error messages
This commit is contained in:
@@ -3,10 +3,32 @@
|
||||
namespace Nominatim;
|
||||
|
||||
require_once(CONST_BasePath.'/lib/lib.php');
|
||||
require_once(CONST_BasePath.'/lib/db.php');
|
||||
require_once(CONST_BasePath.'/lib/DB.php');
|
||||
|
||||
// subclassing so we can set the protected connection variable
|
||||
class NominatimSubClassedDB extends \Nominatim\DB
|
||||
{
|
||||
public function setConnection($oConnection)
|
||||
{
|
||||
$this->connection = $oConnection;
|
||||
}
|
||||
}
|
||||
|
||||
// phpcs:ignore PSR1.Classes.ClassDeclaration.MultipleClasses
|
||||
class DBTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testReusingConnection()
|
||||
{
|
||||
$oDB = new NominatimSubClassedDB('');
|
||||
$oDB->setConnection('anything');
|
||||
$this->assertTrue($oDB->connect());
|
||||
}
|
||||
|
||||
public function testDatabaseExists()
|
||||
{
|
||||
$oDB = new \Nominatim\DB('');
|
||||
$this->assertFalse($oDB->databaseExists());
|
||||
}
|
||||
|
||||
public function testErrorHandling()
|
||||
{
|
||||
@@ -36,9 +58,35 @@ class DBTest extends \PHPUnit\Framework\TestCase
|
||||
throw new \PDOException('ERROR: syntax error at or near "FROM"');
|
||||
}));
|
||||
|
||||
$oDB = new \Nominatim\DB('');
|
||||
$oDB->connection = $oPDOStub;
|
||||
$oDB->tableExists('abc');
|
||||
$oDB = new NominatimSubClassedDB('');
|
||||
$oDB->setConnection($oPDOStub);
|
||||
$oDB->getOne('SELECT name FROM');
|
||||
}
|
||||
|
||||
public function testGetPostgresVersion()
|
||||
{
|
||||
$oDBStub = $this->getMockBuilder(\Nominatim\DB::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('getOne'))
|
||||
->getMock();
|
||||
|
||||
$oDBStub->method('getOne')
|
||||
->willReturn('100006');
|
||||
|
||||
$this->assertEquals(10, $oDBStub->getPostgresVersion());
|
||||
}
|
||||
|
||||
public function testGetPostgisVersion()
|
||||
{
|
||||
$oDBStub = $this->getMockBuilder(\Nominatim\DB::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('getOne'))
|
||||
->getMock();
|
||||
|
||||
$oDBStub->method('getOne')
|
||||
->willReturn('2.4.4');
|
||||
|
||||
$this->assertEquals(2.4, $oDBStub->getPostgisVersion());
|
||||
}
|
||||
|
||||
public function testParseDSN()
|
||||
|
||||
Reference in New Issue
Block a user