Skip to content

Commit a67f5bd

Browse files
authored
Fix error thrown when rendering with no items (#7)
This may happen when all the items in the pipeline are filtered out or fail validation. Test added to cover this case
1 parent a6f474a commit a67f5bd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

spec/TableWriterSpec.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@ function it_writes_items(Table $table)
3838

3939
$this->finish();
4040
}
41+
42+
function it_handles_zero_items(Table $table)
43+
{
44+
$table->setHeaders([])->shouldBeCalled();
45+
$table->render()->shouldBeCalled();
46+
$this->finish();
47+
}
4148
}

src/TableWriter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public function writeItem(array $item) {
4747
* {@inheritdoc}
4848
*/
4949
public function finish() {
50-
$this->table->setHeaders(array_keys($this->firstItem));
50+
$headers = $this->firstItem ? array_keys($this->firstItem) : [];
51+
$this->table->setHeaders($headers);
5152
$this->table->render();
5253

5354
$this->firstItem = null;

0 commit comments

Comments
 (0)