PhpProcessTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\Component\Process\Tests;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Process\PhpExecutableFinder;
  13. use Symfony\Component\Process\PhpProcess;
  14. class PhpProcessTest extends TestCase
  15. {
  16. public function testNonBlockingWorks()
  17. {
  18. $expected = 'hello world!';
  19. $process = new PhpProcess(<<<PHP
  20. <?php echo '$expected';
  21. PHP
  22. );
  23. $process->start();
  24. $process->wait();
  25. $this->assertEquals($expected, $process->getOutput());
  26. }
  27. public function testCommandLine()
  28. {
  29. $process = new PhpProcess(<<<'PHP'
  30. <?php echo phpversion().PHP_SAPI;
  31. PHP
  32. );
  33. $commandLine = $process->getCommandLine();
  34. $process->start();
  35. $this->assertContains($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after start');
  36. $process->wait();
  37. $this->assertContains($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after wait');
  38. $this->assertSame(PHP_VERSION.\PHP_SAPI, $process->getOutput());
  39. }
  40. public function testPassingPhpExplicitly()
  41. {
  42. $finder = new PhpExecutableFinder();
  43. $php = array_merge([$finder->find(false)], $finder->findArguments());
  44. $expected = 'hello world!';
  45. $script = <<<PHP
  46. <?php echo '$expected';
  47. PHP;
  48. $process = new PhpProcess($script, null, null, 60, $php);
  49. $process->run();
  50. $this->assertEquals($expected, $process->getOutput());
  51. }
  52. }