Skip to content

Commit

Permalink
Merge daaf201 into 0b843fb
Browse files Browse the repository at this point in the history
  • Loading branch information
on2 committed Oct 8, 2019
2 parents 0b843fb + daaf201 commit 4910318
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Polyfill/EmptyEscapeParser.php
Expand Up @@ -150,7 +150,9 @@ private static function filterDocument($document)
private static function extractRecord(): array
{
$record = [];
self::$line = self::$document->fgets();
if (false === (self::$line = self::$document->fgets())) {
return [null];
}
do {
$method = 'extractFieldContent';
$buffer = ltrim(self::$line, self::$trim_mask);
Expand Down
29 changes: 29 additions & 0 deletions tests/Polyfill/EmptyEscapeParserTest.php
Expand Up @@ -124,6 +124,35 @@ public function testPreserveEmptyLines()
}
}

/**
* @covers ::parse
* @covers ::extractRecord
* @covers ::extractFieldContent
* @covers ::extractEnclosedFieldContent
*/
public function testReadingOnlyStream()
{
$source = <<<EOF
"1","2"
EOF;

$expected = [
['1', '2'],
[null],
];

$path = sys_get_temp_dir().'/test.csv';
file_put_contents($path, $source);

$stream = Stream::createFromPath($path);
foreach (EmptyEscapeParser::parse($stream) as $offset => $record) {
self::assertSame($expected[$offset], $record);
}

unlink($path);
}

/**
* @covers ::parse
* @covers ::extractRecord
Expand Down

0 comments on commit 4910318

Please sign in to comment.