]> git.openstreetmap.org Git - nominatim.git/blob - test/bdd/steps/cgi-with-coverage.php
bdd: clear lof buffer after a successful import run
[nominatim.git] / test / bdd / steps / cgi-with-coverage.php
1 <?php
2 /**
3  * SPDX-License-Identifier: GPL-2.0-only
4  *
5  * This file is part of Nominatim. (https://nominatim.org)
6  *
7  * Copyright (C) 2022 by the Nominatim developer community.
8  * For a full list of authors see the git log.
9  */
10 require_once 'SebastianBergmann/CodeCoverage/autoload.php';
11
12
13 function coverage_shutdown($oCoverage)
14 {
15     $oCoverage->stop();
16     $writer = new \SebastianBergmann\CodeCoverage\Report\PHP;
17     $writer->process($oCoverage, $_SERVER['PHP_CODE_COVERAGE_FILE']);
18 }
19
20 $covfilter = new SebastianBergmann\CodeCoverage\Filter();
21 if (method_exists($covfilter, 'addDirectoryToWhitelist')) {
22     // pre PHPUnit 9
23     $covfilter->addDirectoryToWhitelist($_SERVER['COV_PHP_DIR'].'/lib-php');
24     $covfilter->addDirectoryToWhitelist($_SERVER['COV_PHP_DIR'].'/website');
25     $coverage = new SebastianBergmann\CodeCoverage\CodeCoverage(null, $covfilter);
26 } else {
27     // since PHP Uit 9
28     $covfilter->includeDirectory($_SERVER['COV_PHP_DIR'].'/lib-php');
29     $covfilter->includeDirectory($_SERVER['COV_PHP_DIR'].'/website');
30     $coverage = new SebastianBergmann\CodeCoverage\CodeCoverage(
31         (new SebastianBergmann\CodeCoverage\Driver\Selector)->forLineCoverage($covfilter),
32         $covfilter
33     );
34 }
35
36 $coverage->start($_SERVER['COV_TEST_NAME']);
37
38 register_shutdown_function('coverage_shutdown', $coverage);
39
40 include $_SERVER['COV_SCRIPT_FILENAME'];