ProcessTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Process;
  11. use Symfony\Component\Process\Process;
  12. /**
  13. * @author Robert Schönthal <seroscho@googlemail.com>
  14. */
  15. class ProcessTest extends \PHPUnit_Framework_TestCase
  16. {
  17. /**
  18. * tests getter/setter
  19. *
  20. * @dataProvider methodProvider
  21. */
  22. public function testDefaultGetterSetter($fn)
  23. {
  24. $p = new Process('php');
  25. $setter = 'set'.$fn;
  26. $getter = 'get'.$fn;
  27. $this->assertNull($p->$setter(array('foo')));
  28. $this->assertSame(array('foo'), $p->$getter(array('foo')));
  29. }
  30. /**
  31. * tests results from sub processes
  32. *
  33. * @dataProvider codeProvider
  34. */
  35. public function testProcessResponses($expected, $getter, $code)
  36. {
  37. $p = new Process(sprintf('php -r "%s"', $code));
  38. $p->run();
  39. $this->assertSame($expected, $p->$getter());
  40. }
  41. public function codeProvider()
  42. {
  43. return array(
  44. //expected output / getter / code to execute
  45. //array(1,'getExitCode','exit(1);'),
  46. //array(true,'isSuccessful','exit();'),
  47. array('output', 'getOutput', 'echo \"output\";'),
  48. );
  49. }
  50. /**
  51. * provides default method names for simple getter/setter
  52. */
  53. public function methodProvider()
  54. {
  55. $defaults = array(
  56. array('CommandLine'),
  57. array('Timeout'),
  58. array('WorkingDirectory'),
  59. array('Env'),
  60. array('Stdin'),
  61. array('Options')
  62. );
  63. return $defaults;
  64. }
  65. }