From c8d45972bbda2cdc60013a074bf6f25beea29394 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Tue, 30 Jul 2024 15:43:41 +0200 Subject: [PATCH] remove support for PHP code coverage in BDD tests --- docs/develop/Testing.md | 17 ----------- test/bdd/environment.py | 3 +- test/bdd/steps/cgi-with-coverage.php | 40 ------------------------- test/bdd/steps/nominatim_environment.py | 9 ------ test/bdd/steps/steps_api_queries.py | 13 +------- 5 files changed, 2 insertions(+), 80 deletions(-) delete mode 100644 test/bdd/steps/cgi-with-coverage.php diff --git a/docs/develop/Testing.md b/docs/develop/Testing.md index aeaca2ee..c220f4e4 100644 --- a/docs/develop/Testing.md +++ b/docs/develop/Testing.md @@ -121,23 +121,6 @@ and compromises the following data: 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. -#### 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= - -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= - ### DB Creation Tests (`test/bdd/db`) These tests check the import and update of the Nominatim database. They do not diff --git a/test/bdd/environment.py b/test/bdd/environment.py index 6aec8f59..155b8d90 100644 --- a/test/bdd/environment.py +++ b/test/bdd/environment.py @@ -30,8 +30,7 @@ userconfig = { 'SERVER_MODULE_PATH' : None, 'TOKENIZER' : None, # Test with a custom tokenizer 'STYLE' : 'extratags', - 'API_ENGINE': 'falcon', - 'PHPCOV' : False, # set to output directory to enable code coverage + 'API_ENGINE': 'falcon' } use_step_matcher("re") diff --git a/test/bdd/steps/cgi-with-coverage.php b/test/bdd/steps/cgi-with-coverage.php deleted file mode 100644 index dbd8993b..00000000 --- a/test/bdd/steps/cgi-with-coverage.php +++ /dev/null @@ -1,40 +0,0 @@ -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']; diff --git a/test/bdd/steps/nominatim_environment.py b/test/bdd/steps/nominatim_environment.py index 88a4f11c..c4b05588 100644 --- a/test/bdd/steps/nominatim_environment.py +++ b/test/bdd/steps/nominatim_environment.py @@ -37,8 +37,6 @@ class NominatimEnvironment: self.server_module_path = config['SERVER_MODULE_PATH'] self.reuse_template = not config['REMOVE_TEMPLATE'] 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.test_env = None @@ -70,13 +68,6 @@ class NominatimEnvironment: dbargs['password'] = self.db_pass 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): """ Set up a custom test configuration that connects to the given diff --git a/test/bdd/steps/steps_api_queries.py b/test/bdd/steps/steps_api_queries.py index aa1b43b8..93501e42 100644 --- a/test/bdd/steps/steps_api_queries.py +++ b/test/bdd/steps/steps_api_queries.py @@ -114,18 +114,7 @@ def send_api_query_php(endpoint, params, context): for k, v in context.http_headers.items(): env['HTTP_' + k.upper().replace('-', '_')] = v - 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'] = 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']) + cmd = ['/usr/bin/env', 'php-cgi', '-f', env['SCRIPT_FILENAME']] for k,v in params.items(): cmd.append(f"{k}={v}") -- 2.39.5