Skip to content

Commit

Permalink
Environment variables are not prefixed anymore to commands, but only …
Browse files Browse the repository at this point in the history
…passed in a Windows-safe way using Process object
  • Loading branch information
giorgiosironi committed Jun 30, 2013
1 parent 66be1ae commit a8132c4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
5 changes: 0 additions & 5 deletions bin/phpunit-wrapper
Expand Up @@ -29,11 +29,6 @@ while (true) {
echo "Executing: $command\n";
$_SERVER['argv'] = explode(' ', $command);

while (!preg_match('|/phpunit|', $_SERVER['argv'][0])) {
$environmentVariable = array_shift($_SERVER['argv']);
putenv($environmentVariable);
}

$lastExitCode = PHPUnit_TextUI_Command::main(false);
echo "FINISHED\n";
}
8 changes: 3 additions & 5 deletions src/ParaTest/Runners/PHPUnit/ExecutableTest.php
Expand Up @@ -125,6 +125,7 @@ public function getExitCode()
*/
public function run($binary, $options = array(), $environmentVariables = array())
{
$environmentVariables['PARATEST'] = 1;
$this->handleEnvironmentVariables($environmentVariables);
$command = $this->command($binary, $options);
$this->process = new Process($command, null, $environmentVariables);
Expand Down Expand Up @@ -167,15 +168,12 @@ protected function prepareOptions($options)
* @param array $options
* @return mixed
*/
protected function getCommandString($binary, $options = array(), $environmentVariables = array())
protected function getCommandString($binary, $options = array())
{
// TODO: this should use a CommandBuilder
//Identify paratest as the test runner
$environmentVariablePrefix = 'PARATEST=1 ';
$command = $binary;
foreach($options as $key => $value) $command .= " --$key %s";
foreach($environmentVariables as $key => $value) $environmentVariablePrefix .= "$key=%s ";
$args = array_merge(array("$environmentVariablePrefix$command %s %s"), array_values($environmentVariables), array_values($options), array($this->fullyQualifiedClassName, $this->getPath()));
$args = array_merge(array("$command %s %s"), array_values($options), array($this->fullyQualifiedClassName, $this->getPath()));
$command = call_user_func_array('sprintf', $args);
return $command;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ParaTest/Runners/PHPUnit/Worker.php
Expand Up @@ -20,7 +20,7 @@ class Worker

public function start($wrapperBinary, $token = 1)
{
$bin = '';
$bin = 'PARATEST=1 ';
if (is_numeric($token)) {
$bin .= "TEST_TOKEN=$token ";
}
Expand Down
10 changes: 5 additions & 5 deletions test/ParaTest/Runners/PHPUnit/ExecutableTestTest.php
Expand Up @@ -26,17 +26,17 @@ public function testGetCommandStringIncludesOptions()
$binary = '/usr/bin/phpunit';

$command = $this->call($this->executableTestChild, 'getCommandString', $binary, $options);
$this->assertEquals('PARATEST=1 /usr/bin/phpunit --bootstrap test/bootstrap.php ClassNameTest pathToFile', $command);
$this->assertEquals('/usr/bin/phpunit --bootstrap test/bootstrap.php ClassNameTest pathToFile', $command);
}

public function testGetCommandStringIncludesEnvironmentVariables()
public function testGetCommandStringDoesNotIncludeEnvironmentVariablesToKeepCompatibilityWithWindows()
{
$options = array('bootstrap' => 'test/bootstrap.php');
$binary = '/usr/bin/phpunit';
$environmentVariables = array('TEST_TOKEN' => 3, 'APPLICATION_ENVIRONMENT_VAR' => 'abc');
$environmentVariables = array('APPLICATION_ENVIRONMENT_VAR' => 'abc');
$command = $this->call($this->executableTestChild, 'getCommandString', $binary, $options, $environmentVariables);

$this->assertEquals('PARATEST=1 TEST_TOKEN=3 APPLICATION_ENVIRONMENT_VAR=abc /usr/bin/phpunit --bootstrap test/bootstrap.php ClassNameTest pathToFile', $command);
$this->assertEquals('/usr/bin/phpunit --bootstrap test/bootstrap.php ClassNameTest pathToFile', $command);
}

public function testGetCommandStringIncludesTheClassName()
Expand All @@ -45,7 +45,7 @@ public function testGetCommandStringIncludesTheClassName()
$binary = '/usr/bin/phpunit';

$command = $this->call($this->executableTestChild, 'getCommandString', $binary, $options);
$this->assertEquals('PARATEST=1 /usr/bin/phpunit ClassNameTest pathToFile', $command);
$this->assertEquals('/usr/bin/phpunit ClassNameTest pathToFile', $command);
}

public function testHandleEnvironmentVariablesAssignsToken()
Expand Down

0 comments on commit a8132c4

Please sign in to comment.