<?php
{{ header }}
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
$pkgAutoloader = __DIR__ . '/{{ pkg_path }}/vendor/autoload.php';
if (file_exists($pkgAutoloader)) {
require_once $pkgAutoloader;
}{% if has_file_fixtures %}
$_test_documents = __DIR__ . '/{{ test_documents_path }}';
if (is_dir($_test_documents)) {
chdir($_test_documents);
}{% endif %}{% if has_http_fixtures %}
$mockServerBin = __DIR__ . '/../rust/target/release/mock-server';
$fixturesDir = __DIR__ . '/../../fixtures';
if (file_exists($mockServerBin)) {
$descriptors = [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => STDERR];
$proc = proc_open([$mockServerBin, $fixturesDir], $descriptors, $pipes);
if (is_resource($proc)) {
for ($i = 0; $i < 8; $i++) {
$line = fgets($pipes[1]);
if ($line === false) {
break;
}
$line = trim($line);
if (str_starts_with($line, 'MOCK_SERVER_URL=')) {
$url = substr($line, strlen('MOCK_SERVER_URL='));
putenv('MOCK_SERVER_URL=' . $url);
$_ENV['MOCK_SERVER_URL'] = $url;
} elseif (str_starts_with($line, 'MOCK_SERVERS=')) {
$jsonVal = substr($line, strlen('MOCK_SERVERS='));
putenv('MOCK_SERVERS=' . $jsonVal);
$_ENV['MOCK_SERVERS'] = $jsonVal;
$servers = json_decode($jsonVal, true);
if (is_array($servers)) {
foreach ($servers as $fid => $furl) {
$envKey = 'MOCK_SERVER_' . strtoupper($fid);
putenv($envKey . '=' . $furl);
$_ENV[$envKey] = $furl;
}
}
break;
} elseif (isset($url)) {
break;
}
}
register_shutdown_function(static function () use ($proc, $pipes): void {
fclose($pipes[0]);
proc_close($proc);
});
}
}{% endif %}