EventPingTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Illuminate\Tests\Integration\Console\Scheduling;
  3. use GuzzleHttp\Client as HttpClient;
  4. use GuzzleHttp\Exception\ServerException;
  5. use GuzzleHttp\Handler\MockHandler;
  6. use GuzzleHttp\HandlerStack;
  7. use GuzzleHttp\Psr7\Response as Psr7Response;
  8. use Illuminate\Console\Scheduling\Event;
  9. use Illuminate\Console\Scheduling\EventMutex;
  10. use Illuminate\Contracts\Container\Container;
  11. use Illuminate\Contracts\Debug\ExceptionHandler;
  12. use Mockery as m;
  13. use Orchestra\Testbench\TestCase;
  14. class EventPingTest extends TestCase
  15. {
  16. protected function tearDown(): void
  17. {
  18. parent::tearDown();
  19. m::close();
  20. }
  21. public function testPingRescuesTransferExceptions()
  22. {
  23. $this->spy(ExceptionHandler::class)
  24. ->shouldReceive('report')
  25. ->once()
  26. ->with(m::type(ServerException::class));
  27. $httpMock = new HttpClient([
  28. 'handler' => HandlerStack::create(
  29. new MockHandler([new Psr7Response(500)])
  30. ),
  31. ]);
  32. $this->swap(HttpClient::class, $httpMock);
  33. $event = new Event(m::mock(EventMutex::class), 'php -i');
  34. $thenCalled = false;
  35. $event->pingBefore('https://httpstat.us/500')
  36. ->then(function () use (&$thenCalled) {
  37. $thenCalled = true;
  38. });
  39. $event->callBeforeCallbacks($this->app->make(Container::class));
  40. $event->callAfterCallbacks($this->app->make(Container::class));
  41. $this->assertTrue($thenCalled);
  42. }
  43. }