mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-16 15:47:58 +00:00
remove support for PHP code coverage in BDD tests
This commit is contained in:
@@ -121,23 +121,6 @@ and compromises the following data:
|
|||||||
API tests should only be testing the functionality of the website PHP code.
|
API tests should only be testing the functionality of the website PHP code.
|
||||||
Most tests should be formulated as BDD DB creation tests (see below) instead.
|
Most tests should be formulated as BDD DB creation tests (see below) instead.
|
||||||
|
|
||||||
#### Code Coverage (PHP engine only)
|
|
||||||
|
|
||||||
The API tests also support code coverage tests. You need to install
|
|
||||||
[PHP_CodeCoverage](https://github.com/sebastianbergmann/php-code-coverage).
|
|
||||||
On Debian/Ubuntu run:
|
|
||||||
|
|
||||||
apt-get install php-codecoverage php-xdebug
|
|
||||||
|
|
||||||
Then run the API tests as follows:
|
|
||||||
|
|
||||||
behave api -DPHPCOV=<coverage output dir>
|
|
||||||
|
|
||||||
The output directory must be an absolute path. To generate reports, you can use
|
|
||||||
the [phpcov](https://github.com/sebastianbergmann/phpcov) tool:
|
|
||||||
|
|
||||||
phpcov merge --html=<report output dir> <coverage output dir>
|
|
||||||
|
|
||||||
### DB Creation Tests (`test/bdd/db`)
|
### DB Creation Tests (`test/bdd/db`)
|
||||||
|
|
||||||
These tests check the import and update of the Nominatim database. They do not
|
These tests check the import and update of the Nominatim database. They do not
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ userconfig = {
|
|||||||
'SERVER_MODULE_PATH' : None,
|
'SERVER_MODULE_PATH' : None,
|
||||||
'TOKENIZER' : None, # Test with a custom tokenizer
|
'TOKENIZER' : None, # Test with a custom tokenizer
|
||||||
'STYLE' : 'extratags',
|
'STYLE' : 'extratags',
|
||||||
'API_ENGINE': 'falcon',
|
'API_ENGINE': 'falcon'
|
||||||
'PHPCOV' : False, # set to output directory to enable code coverage
|
|
||||||
}
|
}
|
||||||
|
|
||||||
use_step_matcher("re")
|
use_step_matcher("re")
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
<?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();
|
|
||||||
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);
|
|
||||||
|
|
||||||
include $_SERVER['COV_SCRIPT_FILENAME'];
|
|
||||||
@@ -37,8 +37,6 @@ class NominatimEnvironment:
|
|||||||
self.server_module_path = config['SERVER_MODULE_PATH']
|
self.server_module_path = config['SERVER_MODULE_PATH']
|
||||||
self.reuse_template = not config['REMOVE_TEMPLATE']
|
self.reuse_template = not config['REMOVE_TEMPLATE']
|
||||||
self.keep_scenario_db = config['KEEP_TEST_DB']
|
self.keep_scenario_db = config['KEEP_TEST_DB']
|
||||||
self.code_coverage_path = config['PHPCOV']
|
|
||||||
self.code_coverage_id = 1
|
|
||||||
|
|
||||||
self.default_config = Configuration(None).get_os_env()
|
self.default_config = Configuration(None).get_os_env()
|
||||||
self.test_env = None
|
self.test_env = None
|
||||||
@@ -70,13 +68,6 @@ class NominatimEnvironment:
|
|||||||
dbargs['password'] = self.db_pass
|
dbargs['password'] = self.db_pass
|
||||||
return psycopg.connect(**dbargs)
|
return psycopg.connect(**dbargs)
|
||||||
|
|
||||||
def next_code_coverage_file(self):
|
|
||||||
""" Generate the next name for a coverage file.
|
|
||||||
"""
|
|
||||||
fn = Path(self.code_coverage_path) / "{:06d}.cov".format(self.code_coverage_id)
|
|
||||||
self.code_coverage_id += 1
|
|
||||||
|
|
||||||
return fn.resolve()
|
|
||||||
|
|
||||||
def write_nominatim_config(self, dbname):
|
def write_nominatim_config(self, dbname):
|
||||||
""" Set up a custom test configuration that connects to the given
|
""" Set up a custom test configuration that connects to the given
|
||||||
|
|||||||
@@ -114,18 +114,7 @@ def send_api_query_php(endpoint, params, context):
|
|||||||
for k, v in context.http_headers.items():
|
for k, v in context.http_headers.items():
|
||||||
env['HTTP_' + k.upper().replace('-', '_')] = v
|
env['HTTP_' + k.upper().replace('-', '_')] = v
|
||||||
|
|
||||||
cmd = ['/usr/bin/env', 'php-cgi', '-f']
|
cmd = ['/usr/bin/env', 'php-cgi', '-f', env['SCRIPT_FILENAME']]
|
||||||
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'] = f"{context.scenario.filename}:{context.scenario.line}"
|
|
||||||
env['SCRIPT_FILENAME'] = \
|
|
||||||
os.path.join(os.path.split(__file__)[0], 'cgi-with-coverage.php')
|
|
||||||
cmd.append(env['SCRIPT_FILENAME'])
|
|
||||||
env['PHP_CODE_COVERAGE_FILE'] = context.nominatim.next_code_coverage_file()
|
|
||||||
else:
|
|
||||||
cmd.append(env['SCRIPT_FILENAME'])
|
|
||||||
|
|
||||||
for k,v in params.items():
|
for k,v in params.items():
|
||||||
cmd.append(f"{k}={v}")
|
cmd.append(f"{k}={v}")
|
||||||
|
|||||||
Reference in New Issue
Block a user