2011-05-09 21:40:18 +01: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Tests\Component\Process;
|
|
|
|
|
|
|
|
use Symfony\Component\Process\Process;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Robert Schönthal <seroscho@googlemail.com>
|
|
|
|
*/
|
|
|
|
class ProcessTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* tests getter/setter
|
2011-06-08 18:56:59 +01:00
|
|
|
*
|
2011-05-09 21:40:18 +01:00
|
|
|
* @dataProvider methodProvider
|
|
|
|
*/
|
|
|
|
public function testDefaultGetterSetter($fn)
|
|
|
|
{
|
|
|
|
$p = new Process('php');
|
2011-06-08 18:56:59 +01:00
|
|
|
|
2011-05-09 21:40:18 +01:00
|
|
|
$setter = 'set'.$fn;
|
|
|
|
$getter = 'get'.$fn;
|
|
|
|
|
|
|
|
$this->assertNull($p->$setter(array('foo')));
|
|
|
|
|
|
|
|
$this->assertSame(array('foo'), $p->$getter(array('foo')));
|
|
|
|
}
|
2011-06-08 18:56:59 +01:00
|
|
|
|
2011-05-09 21:40:18 +01:00
|
|
|
/**
|
|
|
|
* tests results from sub processes
|
2011-06-08 18:56:59 +01:00
|
|
|
*
|
2011-05-09 21:40:18 +01:00
|
|
|
* @dataProvider codeProvider
|
|
|
|
*/
|
2011-05-09 22:21:57 +01:00
|
|
|
public function testProcessResponses($expected, $getter, $code)
|
2011-05-09 21:40:18 +01:00
|
|
|
{
|
2011-05-09 22:21:57 +01:00
|
|
|
$p = new Process(sprintf('php -r "%s"', $code));
|
2011-05-09 21:40:18 +01:00
|
|
|
$p->run();
|
2011-06-08 18:56:59 +01:00
|
|
|
|
2011-05-09 21:40:18 +01:00
|
|
|
$this->assertSame($expected, $p->$getter());
|
|
|
|
}
|
2011-06-08 18:56:59 +01:00
|
|
|
|
2011-05-09 21:40:18 +01:00
|
|
|
public function codeProvider()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
//expected output / getter / code to execute
|
|
|
|
//array(1,'getExitCode','exit(1);'),
|
|
|
|
//array(true,'isSuccessful','exit();'),
|
2011-05-09 22:21:57 +01:00
|
|
|
array('output', 'getOutput', 'echo \"output\";'),
|
2011-05-09 21:40:18 +01:00
|
|
|
);
|
|
|
|
}
|
2011-06-08 18:56:59 +01:00
|
|
|
|
2011-05-09 21:40:18 +01:00
|
|
|
/**
|
|
|
|
* provides default method names for simple getter/setter
|
|
|
|
*/
|
|
|
|
public function methodProvider()
|
|
|
|
{
|
|
|
|
$defaults = array(
|
|
|
|
array('CommandLine'),
|
|
|
|
array('Timeout'),
|
|
|
|
array('WorkingDirectory'),
|
|
|
|
array('Env'),
|
|
|
|
array('Stdin'),
|
|
|
|
array('Options')
|
|
|
|
);
|
2011-06-08 18:56:59 +01:00
|
|
|
|
2011-05-09 21:40:18 +01:00
|
|
|
return $defaults;
|
|
|
|
}
|
|
|
|
}
|