diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithConsole.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithConsole.php index 7ab5334255fa..c4ec0d5c3619 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithConsole.php +++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithConsole.php @@ -4,7 +4,6 @@ use Illuminate\Console\OutputStyle; use Illuminate\Contracts\Console\Kernel; -use Illuminate\Support\Arr; use Illuminate\Testing\PendingCommand; trait InteractsWithConsole @@ -50,28 +49,6 @@ public function artisan($command, $parameters = []) return $this->app[Kernel::class]->call($command, $parameters); } - $this->beforeApplicationDestroyed(function () { - if (count($this->expectedQuestions)) { - $this->fail('Question "'.Arr::first($this->expectedQuestions)[0].'" was not asked.'); - } - - if (count($this->expectedChoices) > 0) { - foreach ($this->expectedChoices as $question => $answers) { - $assertion = $answers['strict'] ? 'assertEquals' : 'assertEqualsCanonicalizing'; - - $this->{$assertion}( - $answers['expected'], - $answers['actual'], - 'Question "'.$question.'" has different options.' - ); - } - } - - if (count($this->expectedOutput)) { - $this->fail('Output "'.Arr::first($this->expectedOutput).'" was not printed.'); - } - }); - return new PendingCommand($this, $this->app, $command, $parameters); } diff --git a/src/Illuminate/Testing/PendingCommand.php b/src/Illuminate/Testing/PendingCommand.php index dae85f317308..153a9ea6b282 100644 --- a/src/Illuminate/Testing/PendingCommand.php +++ b/src/Illuminate/Testing/PendingCommand.php @@ -5,6 +5,7 @@ use Illuminate\Console\OutputStyle; use Illuminate\Contracts\Console\Kernel; use Illuminate\Contracts\Container\Container; +use Illuminate\Support\Arr; use Mockery; use Mockery\Exception\NoMatchingExpectationException; use PHPUnit\Framework\TestCase as PHPUnitTestCase; @@ -181,9 +182,39 @@ public function run() ); } + $this->verifyExpectations(); + return $exitCode; } + /** + * Determine if expected questions / choices / outputs are fulfilled. + * + * @return void + */ + protected function verifyExpectations() + { + if (count($this->test->expectedQuestions)) { + $this->test->fail('Question "'.Arr::first($this->test->expectedQuestions)[0].'" was not asked.'); + } + + if (count($this->test->expectedChoices) > 0) { + foreach ($this->test->expectedChoices as $question => $answers) { + $assertion = $answers['strict'] ? 'assertEquals' : 'assertEqualsCanonicalizing'; + + $this->test->{$assertion}( + $answers['expected'], + $answers['actual'], + 'Question "'.$question.'" has different options.' + ); + } + } + + if (count($this->test->expectedOutput)) { + $this->test->fail('Output "'.Arr::first($this->test->expectedOutput).'" was not printed.'); + } + } + /** * Mock the application's console output. *