Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Console\OutputStyle;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Support\Arr;
use Illuminate\Testing\PendingCommand;

trait InteractsWithConsole
Expand Down Expand Up @@ -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);
}

Expand Down
31 changes: 31 additions & 0 deletions src/Illuminate/Testing/PendingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down