]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge pull request #2542 from lonvia/update-phpunit
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 7 Dec 2021 14:44:45 +0000 (15:44 +0100)
committerGitHub <noreply@github.com>
Tue, 7 Dec 2021 14:44:45 +0000 (15:44 +0100)
Update PHPUnit use to 9.5

docs/develop/Development-Environment.md
test/bdd/steps/cgi-with-coverage.php
test/bdd/steps/steps_api_queries.py
test/php/Nominatim/DBTest.php
test/php/Nominatim/DatabaseErrorTest.php
test/php/Nominatim/TokenListTest.php

index 2840095b8615e6cfc8bd94ed0bb51c346d262dd5..eba87c09e68138e20b08fdacb3f9139a8efd1345 100644 (file)
@@ -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)
index 6f0d79bb2202bde84de2a1b9e9db79c98a5006c2..15e050072935f79222030f23f13c03af7d58d46f 100644 (file)
@@ -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);
index fc0a2156b5cd5e8dbc96de1e574879265c7d23ef..994695870a644c85cbc4a3d30bf4eddff2efd58e 100644 (file)
@@ -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)
index 1a2ecc861fe0ea68d15cb33a176692b5e1a37838..b1ff957bd40a4fae5a0eecfb58f11dcdd7b0708c 100644 (file)
@@ -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);
index da15649347cc73ae293f83b6acbb1037614b4c42..6e70ac25d7cb5eeef1eaed359de671a147220ce3 100644 (file)
@@ -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());
     }
 }
index f0139d7670b4dd246bf3797aa2b49de6704918a6..fdee37234481f629a560118b972defefc9a76459 100644 (file)
@@ -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
     {