- env = dict(BASE_SERVER_ENV)
- env['QUERY_STRING'] = urlencode(params)
-
- env['SCRIPT_NAME'] = '/%s.php' % endpoint
- env['REQUEST_URI'] = '%s?%s' % (env['SCRIPT_NAME'], env['QUERY_STRING'])
- env['CONTEXT_DOCUMENT_ROOT'] = os.path.join(context.nominatim.website_dir.name, 'website')
- env['SCRIPT_FILENAME'] = os.path.join(env['CONTEXT_DOCUMENT_ROOT'],
- '%s.php' % endpoint)
-
- LOG.debug("Environment:" + json.dumps(env, sort_keys=True, indent=2))
-
- if hasattr(context, 'http_headers'):
- env.update(context.http_headers)
-
- cmd = ['/usr/bin/env', 'php-cgi', '-f']
- if context.nominatim.code_coverage_path:
- env['COV_SCRIPT_FILENAME'] = env['SCRIPT_FILENAME']
- env['COV_PHP_DIR'] = os.path.join(context.nominatim.src_dir, "lib")
- env['COV_TEST_NAME'] = '%s:%s' % (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():
- cmd.append("%s=%s" % (k, v))
-
- outp, err = run_script(cmd, cwd=context.nominatim.website_dir.name, env=env)
-
- assert len(err) == 0, "Unexpected PHP error: %s" % (err)
-
- if outp.startswith('Status: '):
- status = int(outp[8:11])
- else:
- status = 200
+ return asyncio.run(context.nominatim.api_engine(endpoint, params,
+ Path(context.nominatim.website_dir.name),
+ context.nominatim.test_env,
+ getattr(context, 'http_headers', {})))