spy(ExceptionHandler::class) ->shouldReceive('report') ->once() ->with(m::type(ServerException::class)); $httpMock = new HttpClient([ 'handler' => HandlerStack::create( new MockHandler([new Psr7Response(500)]) ), ]); $this->swap(HttpClient::class, $httpMock); $event = new Event(m::mock(EventMutex::class), 'php -i'); $thenCalled = false; $event->pingBefore('https://httpstat.us/500') ->then(function () use (&$thenCalled) { $thenCalled = true; }); $event->callBeforeCallbacks($this->app->make(Container::class)); $event->callAfterCallbacks($this->app->make(Container::class)); $this->assertTrue($thenCalled); } }