From 6106f1a32e450fdadd0da8f8c977bcd6f3062018 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Tue, 7 Dec 2021 11:20:38 +0100 Subject: [PATCH 1/5] php test: class must be called like the file --- test/php/Nominatim/TokenListTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/php/Nominatim/TokenListTest.php b/test/php/Nominatim/TokenListTest.php index f0139d76..fdee3723 100644 --- a/test/php/Nominatim/TokenListTest.php +++ b/test/php/Nominatim/TokenListTest.php @@ -5,7 +5,7 @@ namespace Nominatim; require_once(CONST_LibDir.'/TokenList.php'); -class TokenTest extends \PHPUnit\Framework\TestCase +class TokenListTest extends \PHPUnit\Framework\TestCase { protected function setUp(): void { From b7554d9ed8357b716d3cf31b532edc2f85f5829d Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Tue, 7 Dec 2021 11:31:45 +0100 Subject: [PATCH 2/5] php unit: don't enforce a name on the test database Also gets rid of a PHPUnit deprecation warning. --- test/php/Nominatim/DBTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/php/Nominatim/DBTest.php b/test/php/Nominatim/DBTest.php index 1a2ecc86..b1ff957b 100644 --- a/test/php/Nominatim/DBTest.php +++ b/test/php/Nominatim/DBTest.php @@ -132,12 +132,6 @@ class DBTest extends \PHPUnit\Framework\TestCase 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($unit_test_dsn); From 109cdce92ca67665c16f21936e8874b5d525349f Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Tue, 7 Dec 2021 11:34:21 +0100 Subject: [PATCH 3/5] php unit: replace deprecated regex assert The regEx assertion has been renamed in PHPUnit 9.5 and causes deprecation warnings. --- test/php/Nominatim/DatabaseErrorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/php/Nominatim/DatabaseErrorTest.php b/test/php/Nominatim/DatabaseErrorTest.php index da156493..6e70ac25 100644 --- a/test/php/Nominatim/DatabaseErrorTest.php +++ b/test/php/Nominatim/DatabaseErrorTest.php @@ -26,6 +26,6 @@ class DatabaseErrorTest extends \PHPUnit\Framework\TestCase public function testSqlObjectDump() { $oErr = new DatabaseError('Sql error', 123, null, array('one' => 'two')); - $this->assertRegExp('/two/', $oErr->getSqlDebugDump()); + $this->assertStringContainsString('two', $oErr->getSqlDebugDump()); } } From 04857d32cd0fb39178500c537831707477701029 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Tue, 7 Dec 2021 12:07:17 +0100 Subject: [PATCH 4/5] enable PHPUnit 9 for coverage A couple of functions have been renamed. --- test/bdd/steps/cgi-with-coverage.php | 18 +++++++++++++++--- test/bdd/steps/steps_api_queries.py | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/test/bdd/steps/cgi-with-coverage.php b/test/bdd/steps/cgi-with-coverage.php index 6f0d79bb..15e05007 100644 --- a/test/bdd/steps/cgi-with-coverage.php +++ b/test/bdd/steps/cgi-with-coverage.php @@ -10,9 +10,21 @@ function coverage_shutdown($oCoverage) } $covfilter = new SebastianBergmann\CodeCoverage\Filter(); -$covfilter->addDirectoryToWhitelist($_SERVER['COV_PHP_DIR'].'/lib-php'); -$covfilter->addDirectoryToWhitelist($_SERVER['COV_PHP_DIR'].'/website'); -$coverage = new SebastianBergmann\CodeCoverage\CodeCoverage(null, $covfilter); +if (method_exists($covfilter, 'addDirectoryToWhitelist')) { + // pre PHPUnit 9 + $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']); register_shutdown_function('coverage_shutdown', $coverage); diff --git a/test/bdd/steps/steps_api_queries.py b/test/bdd/steps/steps_api_queries.py index fc0a2156..99469587 100644 --- a/test/bdd/steps/steps_api_queries.py +++ b/test/bdd/steps/steps_api_queries.py @@ -82,6 +82,7 @@ def send_api_query(endpoint, params, fmt, context): cmd = ['/usr/bin/env', 'php-cgi', '-f'] if context.nominatim.code_coverage_path: + env['XDEBUG_MODE'] = 'coverage' env['COV_SCRIPT_FILENAME'] = env['SCRIPT_FILENAME'] env['COV_PHP_DIR'] = context.nominatim.src_dir env['COV_TEST_NAME'] = '%s:%s' % (context.scenario.filename, context.scenario.line) From 79aeb31088914470371195bc998a4e0dd97d6f00 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Tue, 7 Dec 2021 14:49:31 +0100 Subject: [PATCH 5/5] restrict PHPUnit to 9.5 version There are so many breaking changes with PHPUnit that it is impossible to give any other guarantees. --- docs/develop/Development-Environment.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/develop/Development-Environment.md b/docs/develop/Development-Environment.md index 2840095b..eba87c09 100644 --- a/docs/develop/Development-Environment.md +++ b/docs/develop/Development-Environment.md @@ -30,7 +30,7 @@ unit tests (using PHPUnit for PHP code and pytest for Python code). It has the following additional requirements: * [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) * [Pylint](https://pylint.org/) (2.6.0 is used for the CI) * [pytest](https://pytest.org)