From a8132c43ec84dbdc08d8b14a3af033e5903bc098 Mon Sep 17 00:00:00 2001 From: Giorgio Sironi Date: Sun, 30 Jun 2013 14:37:08 +0200 Subject: [PATCH] Environment variables are not prefixed anymore to commands, but only passed in a Windows-safe way using Process object --- bin/phpunit-wrapper | 5 ----- src/ParaTest/Runners/PHPUnit/ExecutableTest.php | 8 +++----- src/ParaTest/Runners/PHPUnit/Worker.php | 2 +- test/ParaTest/Runners/PHPUnit/ExecutableTestTest.php | 10 +++++----- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/bin/phpunit-wrapper b/bin/phpunit-wrapper index aafaafa8..3bfc0ef7 100755 --- a/bin/phpunit-wrapper +++ b/bin/phpunit-wrapper @@ -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"; } diff --git a/src/ParaTest/Runners/PHPUnit/ExecutableTest.php b/src/ParaTest/Runners/PHPUnit/ExecutableTest.php index 1e416666..54285e7b 100644 --- a/src/ParaTest/Runners/PHPUnit/ExecutableTest.php +++ b/src/ParaTest/Runners/PHPUnit/ExecutableTest.php @@ -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); @@ -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; } diff --git a/src/ParaTest/Runners/PHPUnit/Worker.php b/src/ParaTest/Runners/PHPUnit/Worker.php index 17a1e361..17c01a93 100644 --- a/src/ParaTest/Runners/PHPUnit/Worker.php +++ b/src/ParaTest/Runners/PHPUnit/Worker.php @@ -20,7 +20,7 @@ class Worker public function start($wrapperBinary, $token = 1) { - $bin = ''; + $bin = 'PARATEST=1 '; if (is_numeric($token)) { $bin .= "TEST_TOKEN=$token "; } diff --git a/test/ParaTest/Runners/PHPUnit/ExecutableTestTest.php b/test/ParaTest/Runners/PHPUnit/ExecutableTestTest.php index a2761459..32c08c02 100644 --- a/test/ParaTest/Runners/PHPUnit/ExecutableTestTest.php +++ b/test/ParaTest/Runners/PHPUnit/ExecutableTestTest.php @@ -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() @@ -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()