RunProcessMessageHandlerTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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->assertSame('\\' === \DIRECTORY_SEPARATOR ? 1 : 127, $e->context->exitCode);
  31. return;
  32. }
  33. $this->fail('Exception not thrown');
  34. }
  35. }