Allow to configure kernel using server & env variables

This commit is contained in:
Kamil Kokot
2019-01-16 17:08:30 +01:00
parent bae9a26443
commit 39cdb2074a
4 changed files with 151 additions and 10 deletions

View File

@@ -24,6 +24,9 @@ final class TestContext implements Context
/** @var Process */
private $process;
/** @var array */
private $variables = [];
/**
* @BeforeFeature
*/
@@ -136,6 +139,14 @@ CON
$this->thereIsFile('config/services.yaml', '');
}
/**
* @Given /^an? (server|environment) variable "([^"]++)" set to "([^"]++)"$/
*/
public function variableSetTo(string $type, string $name, string $value): void
{
$this->variables[$type][$name] = $value;
}
/**
* @Given /^a YAML services file containing:$/
*/
@@ -167,9 +178,13 @@ CON
/**
* @Given /^a (?:.+ |)file "([^"]+)" containing(?: "([^"]+)"|:)$/
*/
public function thereIsFile($file, $content): void
public function thereIsFile($file, $content): string
{
self::$filesystem->dumpFile(self::$workingDir . '/' . $file, (string) $content);
$path = self::$workingDir . '/' . $file;
self::$filesystem->dumpFile($path, (string) $content);
return $path;
}
/**
@@ -185,7 +200,25 @@ CON
*/
public function iRunBehat(): void
{
$this->process = new Process(sprintf('%s %s --strict -vvv --no-interaction --lang=en', self::$phpBin, escapeshellarg(BEHAT_BIN_PATH)));
$executablePath = BEHAT_BIN_PATH;
if ($this->variables !== []) {
$content = '<?php ';
foreach ($this->variables['server'] ?? [] as $name => $value) {
$content .= sprintf('$_SERVER["%s"] = "%s"; ', $name, $value);
}
foreach ($this->variables['environment'] ?? [] as $name => $value) {
$content .= sprintf('$_ENV["%s"] = "%s"; ', $name, $value);
}
$content .= sprintf('require_once("%s"); ', $executablePath);
$executablePath = $this->thereIsFile('__executable.php', $content);
}
$this->process = new Process(sprintf('%s %s --strict -vvv --no-interaction --lang=en', self::$phpBin, escapeshellarg($executablePath)));
$this->process->setWorkingDirectory(self::$workingDir);
$this->process->start();
$this->process->wait();