Skip to content

Commit

Permalink
Added a 'expectedOutputNever' method for console command testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
ash-jc-allen committed Nov 9, 2020
1 parent 4df6994 commit 091509b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Expand Up @@ -22,6 +22,13 @@ trait InteractsWithConsole
*/
public $expectedOutput = [];

/**
* All of the output lines that are expected to never be output.
*
* @var array
*/
public $expectedOutputNever = [];

/**
* All of the expected ouput tables.
*
Expand Down
27 changes: 27 additions & 0 deletions src/Illuminate/Testing/PendingCommand.php
Expand Up @@ -133,6 +133,19 @@ public function expectsOutput($output)
return $this;
}

/**
* Specify output that should never be printed when the command runs.
*
* @param string $output
* @return $this
*/
public function expectsOutputNever($output)
{
$this->test->expectedOutputNever[$output] = false;

return $this;
}

/**
* Specify a table that should be printed when the command runs.
*
Expand Down Expand Up @@ -238,6 +251,10 @@ protected function verifyExpectations()
if (count($this->test->expectedOutput)) {
$this->test->fail('Output "'.Arr::first($this->test->expectedOutput).'" was not printed.');
}

if ($output = array_search(true, $this->test->expectedOutputNever)) {
$this->test->fail('Output "'.$output.'" was printed.');
}
}

/**
Expand Down Expand Up @@ -299,6 +316,16 @@ private function createABufferedOutputMock()
});
}

foreach ($this->test->expectedOutputNever as $output => $displayed) {
$mock->shouldReceive('doWrite')
->once()
->ordered()
->with($output, Mockery::any())
->andReturnUsing(function () use ($output) {
$this->test->expectedOutputNever[$output] = true;
});
}

return $mock;
}

Expand Down

0 comments on commit 091509b

Please sign in to comment.