LTSProcessBuilderFactoryTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Alchemy\Tests\BinaryDriver;
  3. use Symfony\Component\Process\ProcessBuilder;
  4. use Alchemy\BinaryDriver\ProcessBuilderFactory;
  5. use Symfony\Component\Process\Process;
  6. class LTSProcessBuilderFactoryTest extends AbstractProcessBuilderFactoryTest
  7. {
  8. protected function getProcessBuilderFactory($binary)
  9. {
  10. $factory = new ProcessBuilderFactory($binary);
  11. $factory->setBuilder(new LTSProcessBuilder());
  12. ProcessBuilderFactory::$emulateSfLTS = false;
  13. $factory->useBinary($binary);
  14. return $factory;
  15. }
  16. }
  17. class LTSProcessBuilder extends ProcessBuilder
  18. {
  19. private $arguments;
  20. private $prefix;
  21. private $timeout;
  22. public function __construct(array $arguments = array())
  23. {
  24. $this->arguments = $arguments;
  25. parent::__construct($arguments);
  26. }
  27. public function setArguments(array $arguments)
  28. {
  29. $this->arguments = $arguments;
  30. return $this;
  31. }
  32. public function setPrefix($prefix)
  33. {
  34. $this->prefix = $prefix;
  35. return $this;
  36. }
  37. public function setTimeout($timeout)
  38. {
  39. $this->timeout = $timeout;
  40. return $this;
  41. }
  42. public function getProcess()
  43. {
  44. if (!$this->prefix && !count($this->arguments)) {
  45. throw new LogicException('You must add() command arguments before calling getProcess().');
  46. }
  47. $args = $this->prefix ? array_merge(array($this->prefix), $this->arguments) : $this->arguments;
  48. $script = implode(' ', array_map('escapeshellarg', $args));
  49. return new Process($script, null, null, null, $this->timeout);
  50. }
  51. }