Skip to content

Commit

Permalink
Fix error thrown when rendering with no items (#7)
Browse files Browse the repository at this point in the history
This may happen when all the items in the pipeline are filtered out
or fail validation.

Test added to cover this case
  • Loading branch information
fusioned authored Feb 27, 2020
1 parent a6f474a commit a67f5bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions spec/TableWriterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ function it_writes_items(Table $table)

$this->finish();
}

function it_handles_zero_items(Table $table)
{
$table->setHeaders([])->shouldBeCalled();
$table->render()->shouldBeCalled();
$this->finish();
}
}
3 changes: 2 additions & 1 deletion src/TableWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public function writeItem(array $item) {
* {@inheritdoc}
*/
public function finish() {
$this->table->setHeaders(array_keys($this->firstItem));
$headers = $this->firstItem ? array_keys($this->firstItem) : [];
$this->table->setHeaders($headers);
$this->table->render();

$this->firstItem = null;
Expand Down

0 comments on commit a67f5bd

Please sign in to comment.