2011-12-16 14:41:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2012-03-28 14:43:52 +01:00
|
|
|
namespace Symfony\Component\Process\Tests;
|
2011-12-16 14:41:31 +00:00
|
|
|
|
|
|
|
use Symfony\Component\Process\ProcessBuilder;
|
|
|
|
|
|
|
|
class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldInheritEnvironmentVars()
|
|
|
|
{
|
|
|
|
$snapshot = $_ENV;
|
|
|
|
$_ENV = $expected = array('foo' => 'bar');
|
|
|
|
|
|
|
|
$pb = new ProcessBuilder();
|
|
|
|
$pb->add('foo')->inheritEnvironmentVariables();
|
|
|
|
$proc = $pb->getProcess();
|
|
|
|
|
2012-04-12 09:09:52 +01:00
|
|
|
$this->assertNull($proc->getEnv(), '->inheritEnvironmentVariables() copies $_ENV');
|
2011-12-16 14:41:31 +00:00
|
|
|
|
|
|
|
$_ENV = $snapshot;
|
|
|
|
}
|
|
|
|
|
2012-02-22 13:10:14 +00:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldInheritAndOverrideEnvironmentVars()
|
|
|
|
{
|
|
|
|
$snapshot = $_ENV;
|
|
|
|
$_ENV = array('foo' => 'bar', 'bar' => 'baz');
|
|
|
|
$expected = array('foo' => 'foo', 'bar' => 'baz');
|
|
|
|
|
|
|
|
$pb = new ProcessBuilder();
|
|
|
|
$pb->add('foo')->inheritEnvironmentVariables()
|
|
|
|
->setEnv('foo', 'foo');
|
|
|
|
$proc = $pb->getProcess();
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $proc->getEnv(), '->inheritEnvironmentVariables() copies $_ENV');
|
|
|
|
|
|
|
|
$_ENV = $snapshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2012-02-22 13:19:04 +00:00
|
|
|
public function shouldInheritEnvironmentVarsByDefault()
|
2012-02-22 13:10:14 +00:00
|
|
|
{
|
|
|
|
$pb = new ProcessBuilder();
|
|
|
|
$proc = $pb->add('foo')->getProcess();
|
|
|
|
|
2012-04-12 09:09:52 +01:00
|
|
|
$this->assertNull($proc->getEnv());
|
2012-02-22 13:10:14 +00:00
|
|
|
}
|
|
|
|
|
2011-12-16 14:41:31 +00:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldNotReplaceExplicitlySetVars()
|
|
|
|
{
|
|
|
|
$snapshot = $_ENV;
|
|
|
|
$_ENV = array('foo' => 'bar');
|
|
|
|
$expected = array('foo' => 'baz');
|
|
|
|
|
|
|
|
$pb = new ProcessBuilder();
|
|
|
|
$pb
|
|
|
|
->setEnv('foo', 'baz')
|
|
|
|
->inheritEnvironmentVariables()
|
|
|
|
->add('foo')
|
|
|
|
;
|
|
|
|
$proc = $pb->getProcess();
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $proc->getEnv(), '->inheritEnvironmentVariables() copies $_ENV');
|
|
|
|
|
|
|
|
$_ENV = $snapshot;
|
|
|
|
}
|
2012-07-10 14:21:23 +01:00
|
|
|
|
|
|
|
/**
|
2012-08-30 20:25:16 +01:00
|
|
|
* @expectedException Symfony\Component\Process\Exception\InvalidArgumentException
|
2012-07-10 14:21:23 +01:00
|
|
|
*/
|
|
|
|
public function testNegativeTimeoutFromSetter()
|
|
|
|
{
|
|
|
|
$pb = new ProcessBuilder();
|
|
|
|
$pb->setTimeout(-1);
|
|
|
|
}
|
2012-07-11 13:21:05 +01:00
|
|
|
|
|
|
|
public function testNullTimeout()
|
|
|
|
{
|
|
|
|
$pb = new ProcessBuilder();
|
|
|
|
$pb->setTimeout(10);
|
|
|
|
$pb->setTimeout(null);
|
|
|
|
|
|
|
|
$r = new \ReflectionObject($pb);
|
|
|
|
$p = $r->getProperty('timeout');
|
|
|
|
$p->setAccessible(true);
|
|
|
|
|
|
|
|
$this->assertNull($p->getValue($pb));
|
|
|
|
}
|
2012-10-28 15:19:50 +00:00
|
|
|
|
|
|
|
public function testShouldSetArguments()
|
|
|
|
{
|
|
|
|
$pb = new ProcessBuilder(array('initial'));
|
|
|
|
$pb->setArguments(array('second'));
|
|
|
|
|
|
|
|
$proc = $pb->getProcess();
|
|
|
|
|
|
|
|
$this->assertContains("second", $proc->getCommandLine());
|
|
|
|
}
|
2011-12-16 14:41:31 +00:00
|
|
|
}
|