Skip to content

Commit

Permalink
Fix expectsTable call (#35820)
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Jan 7, 2021
1 parent 4415b94 commit b3ebb1b
Showing 1 changed file with 18 additions and 40 deletions.
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

0 comments on commit b3ebb1b

Please sign in to comment.