+
+ putenv('FOO');
+ unset($_ENV['FOO']);
+ }
+
+ public function testGetCommandLine()
+ {
+ $p = new Process(array('/usr/bin/php'));
+
+ $expected = '\\' === \DIRECTORY_SEPARATOR ? '"/usr/bin/php"' : "'/usr/bin/php'";
+ $this->assertSame($expected, $p->getCommandLine());
+ }
+
+ /**
+ * @dataProvider provideEscapeArgument
+ */
+ public function testEscapeArgument($arg)
+ {
+ $p = new Process(array(self::$phpBin, '-r', 'echo $argv[1];', $arg));
+ $p->run();
+
+ $this->assertSame((string) $arg, $p->getOutput());
+ }
+
+ /**
+ * @dataProvider provideEscapeArgument
+ * @group legacy
+ */
+ public function testEscapeArgumentWhenInheritEnvDisabled($arg)
+ {
+ $p = new Process(array(self::$phpBin, '-r', 'echo $argv[1];', $arg), null, array('BAR' => 'BAZ'));
+ $p->inheritEnvironmentVariables(false);
+ $p->run();
+
+ $this->assertSame((string) $arg, $p->getOutput());
+ }
+
+ public function testRawCommandLine()
+ {
+ $p = new Process(sprintf('"%s" -r %s "a" "" "b"', self::$phpBin, escapeshellarg('print_r($argv);')));
+ $p->run();
+
+ $expected = <<<EOTXT
+Array
+(
+ [0] => -
+ [1] => a
+ [2] =>
+ [3] => b
+)
+
+EOTXT;
+ $this->assertSame($expected, str_replace('Standard input code', '-', $p->getOutput()));
+ }
+
+ public function provideEscapeArgument()
+ {
+ yield array('a"b%c%');
+ yield array('a"b^c^');
+ yield array("a\nb'c");
+ yield array('a^b c!');
+ yield array("a!b\tc");
+ yield array('a\\\\"\\"');
+ yield array('éÉèÈàÀöä');
+ yield array(null);
+ yield array(1);
+ yield array(1.1);
+ }
+
+ public function testEnvArgument()
+ {
+ $env = array('FOO' => 'Foo', 'BAR' => 'Bar');
+ $cmd = '\\' === \DIRECTORY_SEPARATOR ? 'echo !FOO! !BAR! !BAZ!' : 'echo $FOO $BAR $BAZ';
+ $p = new Process($cmd, null, $env);
+ $p->run(null, array('BAR' => 'baR', 'BAZ' => 'baZ'));
+
+ $this->assertSame('Foo baR baZ', rtrim($p->getOutput()));
+ $this->assertSame($env, $p->getEnv());