]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/bdd/steps/cgi-with-coverage.php
Merge pull request #3006 from biswajit-k/generalize-filter
[nominatim.git] / test / bdd / steps / cgi-with-coverage.php
index 17104d47a29b99e437d9597aa2729a9bae08b1a1..dbd8993bbb0f7500d6e852a529ec7144b8939038 100644 (file)
@@ -1,13 +1,40 @@
 <?php
+/**
+ * SPDX-License-Identifier: GPL-2.0-only
+ *
+ * This file is part of Nominatim. (https://nominatim.org)
+ *
+ * Copyright (C) 2022 by the Nominatim developer community.
+ * For a full list of authors see the git log.
+ */
 require_once 'SebastianBergmann/CodeCoverage/autoload.php';
+
+
+function coverage_shutdown($oCoverage)
+{
+    $oCoverage->stop();
+    $writer = new \SebastianBergmann\CodeCoverage\Report\PHP;
+    $writer->process($oCoverage, $_SERVER['PHP_CODE_COVERAGE_FILE']);
+}
+
 $covfilter = new SebastianBergmann\CodeCoverage\Filter();
-$covfilter->addDirectoryToWhitelist($_SERVER['COV_PHP_DIR']);
-$coverage = new SebastianBergmann\CodeCoverage\CodeCoverage(null, $covfilter);
-$coverage->start($_SERVER['COV_TEST_NAME']);
+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
+    );
+}
 
-include $_SERVER['COV_SCRIPT_FILENAME'];
+$coverage->start($_SERVER['COV_TEST_NAME']);
 
+register_shutdown_function('coverage_shutdown', $coverage);
 
-$coverage->stop();
-$writer = new \SebastianBergmann\CodeCoverage\Report\PHP;
-$writer->process($coverage, $_SERVER['PHP_CODE_COVERAGE_FILE']);
+include $_SERVER['COV_SCRIPT_FILENAME'];