Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions tests/AbstractConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ abstract public function createDriver();
*/
public function mapRemoteFilePath($file)
{
if (!isset($_SERVER['TEST_MACHINE_BASE_PATH'], $_SERVER['DRIVER_MACHINE_BASE_PATH'])) {
$testMachineBasePath = $this->getEnvVar('TEST_MACHINE_BASE_PATH');
$driverMachineBasePath = $this->getEnvVar('DRIVER_MACHINE_BASE_PATH');

if (null === $testMachineBasePath || null === $driverMachineBasePath) {
return $file;
}

$pattern = '/^' . preg_quote($_SERVER['TEST_MACHINE_BASE_PATH'], '/') . '/';
$basePath = $_SERVER['DRIVER_MACHINE_BASE_PATH'];
$pattern = '/^' . preg_quote($testMachineBasePath, '/') . '/';

return preg_replace($pattern, $basePath, $file, 1) ?? $file;
return preg_replace($pattern, $driverMachineBasePath, $file, 1) ?? $file;
}

/**
Expand All @@ -39,11 +41,28 @@ public function mapRemoteFilePath($file)
*/
public function getWebFixturesUrl()
{
if (!isset($_SERVER['WEB_FIXTURES_HOST']) || !\is_string($_SERVER['WEB_FIXTURES_HOST'])) {
return 'http://localhost:8002'; // Host used by default by mink-test-server
// Host used by default by mink-test-server
return $this->getEnvVar('WEB_FIXTURES_HOST') ?? 'http://localhost:8002';
}

/**
* Gets a variable from the environment, falling back to the $_SERVER one (e.g. a "<server>" in PHPUnit config).
*
* The environment goes first, because PHPUnit's "<server>" overwrites the $_SERVER value coming from it.
*
* @param string $name
*
* @return string|null
*/
protected function getEnvVar($name)
{
$value = getenv($name);

if (false === $value) {
$value = $_SERVER[$name] ?? null;
}

return $_SERVER['WEB_FIXTURES_HOST'];
return \is_string($value) ? $value : null;
}

/**
Expand Down
Loading