Skip to content

Commit

Permalink
fix unexpected output. flush expections
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Nov 11, 2020
1 parent 091509b commit c90fc5f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 20 additions & 5 deletions src/Illuminate/Testing/PendingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -221,6 +221,7 @@ public function run()
}

$this->verifyExpectations();
$this->flushExpectations();

return $exitCode;
}
Expand Down Expand Up @@ -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.');
}
}
Expand Down Expand Up @@ -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;
});
}

Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit c90fc5f

Please sign in to comment.