lonvia PR feedback

This commit is contained in:
marc tobias
2020-04-26 03:33:15 +02:00
parent 38c21de0ee
commit a5d0657d9b
4 changed files with 25 additions and 30 deletions

View File

@@ -25,7 +25,7 @@ script:
- cd $TRAVIS_BUILD_DIR/
- if [[ $TEST_SUITE == "tests" ]]; then phpcs --report-width=120 . ; fi
- cd $TRAVIS_BUILD_DIR/test/php
- if [[ $TEST_SUITE == "tests" ]]; then UNIT_TEST_DSN='pgsql:dbname=nominatim_unit_tests' /usr/bin/phpunit ./ ; fi
- if [[ $TEST_SUITE == "tests" ]]; then /usr/bin/phpunit ./ ; fi
- cd $TRAVIS_BUILD_DIR/test/bdd
- # behave --format=progress3 api
- if [[ $TEST_SUITE == "tests" ]]; then behave -DREMOVE_TEMPLATE=1 --format=progress3 db ; fi

View File

@@ -251,7 +251,7 @@ class DB
}
/**
* Deletes a table. Returns true on success. Returns true if the table didn't exist.
* Deletes a table. Returns true if deleted or didn't exist.
*
* @param string $sTableName
*
@@ -405,29 +405,16 @@ END;
*/
public static function generateDSN($aInfo)
{
$sDSN = 'pgsql:';
if (isset($aInfo['host'])) {
$sDSN .= 'host=' . $aInfo['host'] . ';';
} elseif (isset($aInfo['hostspec'])) {
$sDSN .= 'host=' . $aInfo['hostspec'] . ';';
}
if (isset($aInfo['port'])) {
$sDSN .= 'port=' . $aInfo['port'] . ';';
}
if (isset($aInfo['dbname'])) {
$sDSN .= 'dbname=' . $aInfo['dbname'] . ';';
} elseif (isset($aInfo['database'])) {
$sDSN .= 'dbname=' . $aInfo['database'] . ';';
}
if (isset($aInfo['user'])) {
$sDSN .= 'user=' . $aInfo['user'] . ';';
} elseif (isset($aInfo['username'])) {
$sDSN .= 'user=' . $aInfo['username'] . ';';
}
if (isset($aInfo['password'])) {
$sDSN .= 'password=' . $aInfo['password'] . ';';
}
$sDSN = preg_replace('/;$/', '', $sDSN);
$sDSN = sprintf(
'pgsql:host=%s;port=%s;dbname=%s;user=%s;password=%s;',
$aInfo['host'] ?? $aInfo['hostspec'] ?? '',
$aInfo['port'] ?? '',
$aInfo['dbname'] ?? $aInfo['database'] ?? '',
$aInfo['user'] ?? '',
$aInfo['password'] ?? ''
);
$sDSN = preg_replace('/\b\w+=;/', '', $sDSN);
$sDSN = preg_replace('/;\Z/', '', $sDSN);
return $sDSN;
}

View File

@@ -51,8 +51,8 @@ To execute the test suite run
It will read phpunit.xml which points to the library, test path, bootstrap
strip and set other parameters.
The database set by `UNIT_TEST_DSN` will be deleted and recreated. Not setting
it will skip some tests as pending, but not fail the tests.
It will use (and destroy) a local database 'nominatim_unit_tests'. You can set
a different connection string with e.g. UNIT_TEST_DSN='pgsql:dbname=foo_unit_tests'.
BDD Functional Tests
====================

View File

@@ -128,11 +128,19 @@ class DBTest extends \PHPUnit\Framework\TestCase
public function testAgainstDatabase()
{
if (getenv('UNIT_TEST_DSN') == false) $this->markTestSkipped('UNIT_TEST_DSN not set');
$unit_test_dsn = getenv('UNIT_TEST_DSN') != false ?
getenv('UNIT_TEST_DSN') :
'pgsql:dbname=nominatim_unit_tests';
$this->assertRegExp(
'/unit_test/',
$unit_test_dsn,
'Test database will get destroyed, thus should have a name like unit_test to be safe'
);
## Create the database.
{
$aDSNParsed = \Nominatim\DB::parseDSN(getenv('UNIT_TEST_DSN'));
$aDSNParsed = \Nominatim\DB::parseDSN($unit_test_dsn);
$sDbname = $aDSNParsed['database'];
$aDSNParsed['database'] = 'postgres';
@@ -142,7 +150,7 @@ class DBTest extends \PHPUnit\Framework\TestCase
$oDB->exec('CREATE DATABASE ' . $sDbname);
}
$oDB = new \Nominatim\DB(getenv('UNIT_TEST_DSN'));
$oDB = new \Nominatim\DB($unit_test_dsn);
$oDB->connect();
$this->assertTrue(