AbstractProcessBuilderFactoryTest.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace Alchemy\Tests\BinaryDriver;
  3. use Symfony\Component\Process\ExecutableFinder;
  4. use Alchemy\BinaryDriver\ProcessBuilderFactory;
  5. abstract class AbstractProcessBuilderFactoryTest extends \PHPUnit_Framework_TestCase
  6. {
  7. public static $phpBinary;
  8. private $original;
  9. /**
  10. * @return ProcessBuilderFactory
  11. */
  12. abstract protected function getProcessBuilderFactory($binary);
  13. public function setUp()
  14. {
  15. ProcessBuilderFactory::$emulateSfLTS = null;
  16. if (null === static::$phpBinary) {
  17. $this->markTestSkipped('Unable to detect php binary, skipping');
  18. }
  19. }
  20. public static function setUpBeforeClass()
  21. {
  22. $finder = new ExecutableFinder();
  23. static::$phpBinary = $finder->find('php');
  24. }
  25. public function testThatBinaryIsSetOnConstruction()
  26. {
  27. $factory = $this->getProcessBuilderFactory(static::$phpBinary);
  28. $this->assertEquals(static::$phpBinary, $factory->getBinary());
  29. }
  30. public function testGetSetBinary()
  31. {
  32. $finder = new ExecutableFinder();
  33. $phpUnit = $finder->find('phpunit');
  34. if (null === $phpUnit) {
  35. $this->markTestSkipped('Unable to detect phpunit binary, skipping');
  36. }
  37. $factory = $this->getProcessBuilderFactory(static::$phpBinary);
  38. $factory->useBinary($phpUnit);
  39. $this->assertEquals($phpUnit, $factory->getBinary());
  40. }
  41. /**
  42. * @expectedException Alchemy\BinaryDriver\Exception\InvalidArgumentException
  43. */
  44. public function testUseNonExistantBinary()
  45. {
  46. $factory = $this->getProcessBuilderFactory(static::$phpBinary);
  47. $factory->useBinary('itissureitdoesnotexist');
  48. }
  49. public function testCreateShouldReturnAProcess()
  50. {
  51. $factory = $this->getProcessBuilderFactory(static::$phpBinary);
  52. $process = $factory->create();
  53. $this->assertInstanceOf('Symfony\Component\Process\Process', $process);
  54. $this->assertEquals("'".static::$phpBinary."'", $process->getCommandLine());
  55. }
  56. public function testCreateWithStringArgument()
  57. {
  58. $factory = $this->getProcessBuilderFactory(static::$phpBinary);
  59. $process = $factory->create('-v');
  60. $this->assertInstanceOf('Symfony\Component\Process\Process', $process);
  61. $this->assertEquals("'".static::$phpBinary."' '-v'", $process->getCommandLine());
  62. }
  63. public function testCreateWithArrayArgument()
  64. {
  65. $factory = $this->getProcessBuilderFactory(static::$phpBinary);
  66. $process = $factory->create(array('-r', 'echo "Hello !";'));
  67. $this->assertInstanceOf('Symfony\Component\Process\Process', $process);
  68. $this->assertEquals("'".static::$phpBinary."' '-r' 'echo \"Hello !\";'", $process->getCommandLine());
  69. }
  70. public function testCreateWithTimeout()
  71. {
  72. $factory = $this->getProcessBuilderFactory(static::$phpBinary);
  73. $factory->setTimeout(200);
  74. $process = $factory->create(array('-i'));
  75. $this->assertInstanceOf('Symfony\Component\Process\Process', $process);
  76. $this->assertEquals(200, $process->getTimeout());
  77. }
  78. }