Merge pull request #2542 from lonvia/update-phpunit

Update PHPUnit use to 9.5
This commit is contained in:
Sarah Hoffmann 2021-12-07 15:44:45 +01:00 committed by GitHub
commit fedc8ed474
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 12 deletions

View File

@ -30,7 +30,7 @@ unit tests (using PHPUnit for PHP code and pytest for Python code).
It has the following additional requirements: It has the following additional requirements:
* [behave test framework](https://behave.readthedocs.io) >= 1.2.6 * [behave test framework](https://behave.readthedocs.io) >= 1.2.6
* [phpunit](https://phpunit.de) >= 7.3 * [phpunit](https://phpunit.de) (9.5 is known to work)
* [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) * [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
* [Pylint](https://pylint.org/) (2.6.0 is used for the CI) * [Pylint](https://pylint.org/) (2.6.0 is used for the CI)
* [pytest](https://pytest.org) * [pytest](https://pytest.org)

View File

@ -10,9 +10,21 @@ function coverage_shutdown($oCoverage)
} }
$covfilter = new SebastianBergmann\CodeCoverage\Filter(); $covfilter = new SebastianBergmann\CodeCoverage\Filter();
$covfilter->addDirectoryToWhitelist($_SERVER['COV_PHP_DIR'].'/lib-php'); if (method_exists($covfilter, 'addDirectoryToWhitelist')) {
$covfilter->addDirectoryToWhitelist($_SERVER['COV_PHP_DIR'].'/website'); // pre PHPUnit 9
$coverage = new SebastianBergmann\CodeCoverage\CodeCoverage(null, $covfilter); $covfilter->addDirectoryToWhitelist($_SERVER['COV_PHP_DIR'].'/lib-php');
$covfilter->addDirectoryToWhitelist($_SERVER['COV_PHP_DIR'].'/website');
$coverage = new SebastianBergmann\CodeCoverage\CodeCoverage(null, $covfilter);
} else {
// since PHP Uit 9
$covfilter->includeDirectory($_SERVER['COV_PHP_DIR'].'/lib-php');
$covfilter->includeDirectory($_SERVER['COV_PHP_DIR'].'/website');
$coverage = new SebastianBergmann\CodeCoverage\CodeCoverage(
(new SebastianBergmann\CodeCoverage\Driver\Selector)->forLineCoverage($covfilter),
$covfilter
);
}
$coverage->start($_SERVER['COV_TEST_NAME']); $coverage->start($_SERVER['COV_TEST_NAME']);
register_shutdown_function('coverage_shutdown', $coverage); register_shutdown_function('coverage_shutdown', $coverage);

View File

@ -82,6 +82,7 @@ def send_api_query(endpoint, params, fmt, context):
cmd = ['/usr/bin/env', 'php-cgi', '-f'] cmd = ['/usr/bin/env', 'php-cgi', '-f']
if context.nominatim.code_coverage_path: if context.nominatim.code_coverage_path:
env['XDEBUG_MODE'] = 'coverage'
env['COV_SCRIPT_FILENAME'] = env['SCRIPT_FILENAME'] env['COV_SCRIPT_FILENAME'] = env['SCRIPT_FILENAME']
env['COV_PHP_DIR'] = context.nominatim.src_dir env['COV_PHP_DIR'] = context.nominatim.src_dir
env['COV_TEST_NAME'] = '%s:%s' % (context.scenario.filename, context.scenario.line) env['COV_TEST_NAME'] = '%s:%s' % (context.scenario.filename, context.scenario.line)

View File

@ -132,12 +132,6 @@ class DBTest extends \PHPUnit\Framework\TestCase
getenv('UNIT_TEST_DSN') : getenv('UNIT_TEST_DSN') :
'pgsql:dbname=nominatim_unit_tests'; '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. ## Create the database.
{ {
$aDSNParsed = \Nominatim\DB::parseDSN($unit_test_dsn); $aDSNParsed = \Nominatim\DB::parseDSN($unit_test_dsn);

View File

@ -26,6 +26,6 @@ class DatabaseErrorTest extends \PHPUnit\Framework\TestCase
public function testSqlObjectDump() public function testSqlObjectDump()
{ {
$oErr = new DatabaseError('Sql error', 123, null, array('one' => 'two')); $oErr = new DatabaseError('Sql error', 123, null, array('one' => 'two'));
$this->assertRegExp('/two/', $oErr->getSqlDebugDump()); $this->assertStringContainsString('two', $oErr->getSqlDebugDump());
} }
} }

View File

@ -5,7 +5,7 @@ namespace Nominatim;
require_once(CONST_LibDir.'/TokenList.php'); require_once(CONST_LibDir.'/TokenList.php');
class TokenTest extends \PHPUnit\Framework\TestCase class TokenListTest extends \PHPUnit\Framework\TestCase
{ {
protected function setUp(): void protected function setUp(): void
{ {