diff --git a/src/Illuminate/Foundation/Testing/PendingCommand.php b/src/Illuminate/Foundation/Testing/PendingCommand.php index 379eba14c8d7..d217c0261c92 100644 --- a/src/Illuminate/Foundation/Testing/PendingCommand.php +++ b/src/Illuminate/Foundation/Testing/PendingCommand.php @@ -165,7 +165,6 @@ protected function mockConsoleOutput() foreach ($this->test->expectedQuestions as $i => $question) { $mock->shouldReceive('askQuestion') - ->once() ->ordered() ->with(Mockery::on(function ($argument) use ($question) { return $argument->getQuestion() == $question[0]; @@ -195,7 +194,6 @@ private function createABufferedOutputMock() foreach ($this->test->expectedOutput as $i => $output) { $mock->shouldReceive('doWrite') - ->once() ->ordered() ->with($output, Mockery::any()) ->andReturnUsing(function () use ($i) { diff --git a/src/Illuminate/Foundation/Testing/TestCase.php b/src/Illuminate/Foundation/Testing/TestCase.php index f712d80b0f4b..5c20d0c44f32 100644 --- a/src/Illuminate/Foundation/Testing/TestCase.php +++ b/src/Illuminate/Foundation/Testing/TestCase.php @@ -42,6 +42,13 @@ abstract class TestCase extends BaseTestCase */ protected $beforeApplicationDestroyedCallbacks = []; + /** + * The exception thrown while running an application destruction callback. + * + * @var \Throwable + */ + protected $callbackException; + /** * Indicates if we have made it through the base setUp function. * @@ -136,9 +143,7 @@ protected function setUpTraits() protected function tearDown(): void { if ($this->app) { - foreach ($this->beforeApplicationDestroyedCallbacks as $callback) { - call_user_func($callback); - } + $this->callBeforeApplicationDestroyedCallbacks(); $this->app->flush(); @@ -175,6 +180,10 @@ protected function tearDown(): void $this->beforeApplicationDestroyedCallbacks = []; Artisan::forgetBootstrappers(); + + if ($this->callbackException) { + throw $this->callbackException; + } } /** @@ -202,4 +211,22 @@ protected function beforeApplicationDestroyed(callable $callback) { $this->beforeApplicationDestroyedCallbacks[] = $callback; } + + /** + * Execute the application's pre-destruction callbacks. + * + * @return void + */ + protected function callBeforeApplicationDestroyedCallbacks() + { + foreach ($this->beforeApplicationDestroyedCallbacks as $callback) { + try { + call_user_func($callback); + } catch (\Throwable $e) { + if (! $this->callbackException) { + $this->callbackException = $e; + } + } + } + } }