Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] Teardown test suite after using fail() method #29267

Merged
merged 5 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Illuminate/Foundation/Testing/PendingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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) {
Expand Down
33 changes: 30 additions & 3 deletions src/Illuminate/Foundation/Testing/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -175,6 +180,10 @@ protected function tearDown(): void
$this->beforeApplicationDestroyedCallbacks = [];

Artisan::forgetBootstrappers();

if ($this->callbackException) {
throw $this->callbackException;
}
}

/**
Expand Down Expand Up @@ -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;
}
}
}
}
}