Skip to content

Commit

Permalink
Patch moved to the AbstractCsv::chunk method
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Jun 6, 2019
1 parent 9fa6a86 commit 45b0349
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AbstractCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ public function chunk(int $length): Generator

$input_bom = $this->getInputBOM();
$this->document->rewind();
$this->document->setFlags(0);
$this->document->fseek(strlen($input_bom));
foreach (str_split($this->output_bom.$this->document->fread($length), $length) as $chunk) {
yield $chunk;
Expand Down Expand Up @@ -311,7 +312,6 @@ public function output(string $filename = null): int
}
$input_bom = $this->getInputBOM();
$this->document->rewind();
$this->document->setFlags(0);
$this->document->fseek(strlen($input_bom));
echo $this->output_bom;

Expand Down
12 changes: 12 additions & 0 deletions tests/CsvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ public function testOutputHeaders()
self::assertContains('Content-Disposition: attachment; filename="tst.csv"; filename*=utf-8\'\'t%C3%A9st.csv', $headers[3]);
}

/**
* @covers ::chunk
* @covers ::getContent
*/
public function testChunkDoesNotTimeoutAfterReading()
{
$raw_csv = "john,doe,[email protected]\njane,doe,[email protected]\n";
$csv = Reader::createFromString($raw_csv);
iterator_to_array($csv->getRecords());
self::assertSame($raw_csv, $csv->getContent());
}

/**
* @covers ::__toString
* @covers ::getContent
Expand Down

0 comments on commit 45b0349

Please sign in to comment.