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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Fix expectsTable call #35820

Merged
merged 1 commit into from Jan 7, 2021
Merged
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
58 changes: 18 additions & 40 deletions src/Illuminate/Testing/PendingCommand.php
Expand Up @@ -157,12 +157,24 @@ public function doesntExpectOutput($output)
*/
public function expectsTable($headers, $rows, $tableStyle = 'default', array $columnStyles = [])
{
$this->test->expectedTables[] = [
'headers' => (array) $headers,
'rows' => $rows instanceof Arrayable ? $rows->toArray() : $rows,
'tableStyle' => $tableStyle,
'columnStyles' => $columnStyles,
];
$table = (new Table($output = new BufferedOutput))
->setHeaders((array) $headers)
->setRows($rows instanceof Arrayable ? $rows->toArray() : $rows)
->setStyle($tableStyle);

foreach ($columnStyles as $columnIndex => $columnStyle) {
$table->setColumnStyle($columnIndex, $columnStyle);
}

$table->render();

$lines = array_filter(
explode(PHP_EOL, $output->fetch())
);

foreach ($lines as $line) {
$this->expectsOutput($line);
}

return $this;
}
Expand Down Expand Up @@ -305,8 +317,6 @@ private function createABufferedOutputMock()
->shouldAllowMockingProtectedMethods()
->shouldIgnoreMissing();

$this->applyTableOutputExpectations($mock);

foreach ($this->test->expectedOutput as $i => $output) {
$mock->shouldReceive('doWrite')
->once()
Expand All @@ -330,38 +340,6 @@ private function createABufferedOutputMock()
return $mock;
}

/**
* Apply the output table expectations to the mock.
*
* @param \Mockery\MockInterface $mock
* @return void
*/
private function applyTableOutputExpectations($mock)
{
foreach ($this->test->expectedTables as $i => $consoleTable) {
$table = (new Table($output = new BufferedOutput))
->setHeaders($consoleTable['headers'])
->setRows($consoleTable['rows'])
->setStyle($consoleTable['tableStyle']);

foreach ($consoleTable['columnStyles'] as $columnIndex => $columnStyle) {
$table->setColumnStyle($columnIndex, $columnStyle);
}

$table->render();

$lines = array_filter(
explode(PHP_EOL, $output->fetch())
);

foreach ($lines as $line) {
$this->expectsOutput($line);
}

unset($this->test->expectedTables[$i]);
}
}

/**
* Flush the expectations from the test case.
*
Expand Down