Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Added a 'expectedOutputNever' method for console command testing #35160

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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