RunProcessMessageHandlerTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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\Messenger;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Process\Exception\RunProcessFailedException;
  13. use Symfony\Component\Process\Messenger\RunProcessMessage;
  14. use Symfony\Component\Process\Messenger\RunProcessMessageHandler;
  15. class RunProcessMessageHandlerTest extends TestCase
  16. {
  17. public function testRunSuccessfulProcess()
  18. {
  19. $context = (new RunProcessMessageHandler())(new RunProcessMessage(['ls'], cwd: __DIR__));
  20. $this->assertSame(['ls'], $context->message->command);
  21. $this->assertSame(0, $context->exitCode);
  22. $this->assertStringContainsString(basename(__FILE__), $context->output);
  23. }
  24. public function testRunFailedProcess()
  25. {
  26. try {
  27. (new RunProcessMessageHandler())(new RunProcessMessage(['invalid']));
  28. } catch (RunProcessFailedException $e) {
  29. $this->assertSame(['invalid'], $e->context->message->command);
  30. $this->assertContains(
  31. $e->context->exitCode,
  32. [null, '\\' === \DIRECTORY_SEPARATOR ? 1 : 127],
  33. 'Exit code should be 1 on Windows, 127 on other systems, or null',
  34. );
  35. return;
  36. }
  37. $this->fail('Exception not thrown');
  38. }
  39. }