PageRenderTime 35ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Symfony/Component/Process/Tests/PhpProcessTest.php

http://github.com/symfony/symfony
PHP | 74 lines | 54 code | 12 blank | 8 comment | 0 complexity | 4fe707d840c7c062c539a2826ce1fa76 MD5 | raw file
  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\Exception\LogicException;
  13. use Symfony\Component\Process\PhpExecutableFinder;
  14. use Symfony\Component\Process\PhpProcess;
  15. class PhpProcessTest extends TestCase
  16. {
  17. public function testNonBlockingWorks()
  18. {
  19. $expected = 'hello world!';
  20. $process = new PhpProcess(<<<PHP
  21. <?php echo '$expected';
  22. PHP
  23. );
  24. $process->start();
  25. $process->wait();
  26. $this->assertEquals($expected, $process->getOutput());
  27. }
  28. public function testCommandLine()
  29. {
  30. $process = new PhpProcess(<<<'PHP'
  31. <?php echo phpversion().PHP_SAPI;
  32. PHP
  33. );
  34. $commandLine = $process->getCommandLine();
  35. $process->start();
  36. $this->assertStringContainsString($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after start');
  37. $process->wait();
  38. $this->assertStringContainsString($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after wait');
  39. $this->assertSame(PHP_VERSION.\PHP_SAPI, $process->getOutput());
  40. }
  41. public function testPassingPhpExplicitly()
  42. {
  43. $finder = new PhpExecutableFinder();
  44. $php = array_merge([$finder->find(false)], $finder->findArguments());
  45. $expected = 'hello world!';
  46. $script = <<<PHP
  47. <?php echo '$expected';
  48. PHP;
  49. $process = new PhpProcess($script, null, null, 60, $php);
  50. $process->run();
  51. $this->assertEquals($expected, $process->getOutput());
  52. }
  53. public function testProcessCannotBeCreatedUsingFromShellCommandLine()
  54. {
  55. static::expectException(LogicException::class);
  56. static::expectExceptionMessage('The "Symfony\Component\Process\PhpProcess::fromShellCommandline()" method cannot be called when using "Symfony\Component\Process\PhpProcess".');
  57. PhpProcess::fromShellCommandline(<<<PHP
  58. <?php echo 'Hello World!';
  59. PHP
  60. );
  61. }
  62. }