From c90fc5f6b8e91e3f6b0f2f3a74cad7d8a49bc71b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 11 Nov 2020 08:36:13 -0600 Subject: [PATCH] fix unexpected output. flush expections --- .../Testing/Concerns/InteractsWithConsole.php | 4 +-- src/Illuminate/Testing/PendingCommand.php | 25 +++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithConsole.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithConsole.php index 60095a6c2fa6..dad0f65f6464 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithConsole.php +++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithConsole.php @@ -23,11 +23,11 @@ trait InteractsWithConsole public $expectedOutput = []; /** - * All of the output lines that are expected to never be output. + * All of the output lines that aren't expected to be displayed. * * @var array */ - public $expectedOutputNever = []; + public $unexpectedOutput = []; /** * All of the expected ouput tables. diff --git a/src/Illuminate/Testing/PendingCommand.php b/src/Illuminate/Testing/PendingCommand.php index 64738811044e..ac7ec5e45972 100644 --- a/src/Illuminate/Testing/PendingCommand.php +++ b/src/Illuminate/Testing/PendingCommand.php @@ -139,9 +139,9 @@ public function expectsOutput($output) * @param string $output * @return $this */ - public function expectsOutputNever($output) + public function doesntExpectOutput($output) { - $this->test->expectedOutputNever[$output] = false; + $this->test->unexpectedOutput[$output] = false; return $this; } @@ -221,6 +221,7 @@ public function run() } $this->verifyExpectations(); + $this->flushExpectations(); return $exitCode; } @@ -252,7 +253,7 @@ protected function verifyExpectations() $this->test->fail('Output "'.Arr::first($this->test->expectedOutput).'" was not printed.'); } - if ($output = array_search(true, $this->test->expectedOutputNever)) { + if ($output = array_search(true, $this->test->unexpectedOutput)) { $this->test->fail('Output "'.$output.'" was printed.'); } } @@ -316,13 +317,13 @@ private function createABufferedOutputMock() }); } - foreach ($this->test->expectedOutputNever as $output => $displayed) { + foreach ($this->test->unexpectedOutput as $output => $displayed) { $mock->shouldReceive('doWrite') ->once() ->ordered() ->with($output, Mockery::any()) ->andReturnUsing(function () use ($output) { - $this->test->expectedOutputNever[$output] = true; + $this->test->unexpectedOutput[$output] = true; }); } @@ -359,6 +360,20 @@ private function applyTableOutputExpectations($mock) } } + /** + * Flush the expectations from the test case. + * + * @return void + */ + protected function flushExpectations() + { + $this->test->expectedOutput = []; + $this->test->unexpectedOutput = []; + $this->test->expectedTables = []; + $this->test->expectedQuestions = []; + $this->test->expectedChoices = []; + } + /** * Handle the object's destruction. *