Merge pull request #125 from itexia/42-Heading-and-offset

Fixed issue 42: heading and offset; added tests
This commit is contained in:
Fonata
2018-03-02 17:06:22 +01:00
committed by GitHub
2 changed files with 27 additions and 1 deletions

View File

@@ -987,7 +987,8 @@ class Csv {
return
$this->sort_by !== null ||
$this->offset === null ||
$current_row >= $this->offset;
$current_row >= $this->offset ||
($this->heading && $current_row == 0);
}
/**

View File

@@ -157,6 +157,31 @@ class ParseTest extends TestCase
$this->assertEquals($expected, $this->csv->data_types);
}
public function testDataArrayKeysWhenSettingOffsetWithHeading() {
$this->csv->offset = 2;
$this->csv->auto(__DIR__ . '/fixtures/datatype.csv');
$expected = [
'title',
'isbn',
'publishedAt',
'published',
'count',
'price'
];
$this->assertEquals($expected, array_keys($this->csv->data[0]));
}
public function testDataArrayKeysWhenSettingOffsetWithoutHeading() {
$this->csv->heading = false;
$this->csv->offset = 2;
$this->csv->auto(__DIR__ . '/fixtures/datatype.csv');
$expected = range(0,5, 1);
$this->assertEquals($expected, array_keys($this->csv->data[0]));
}
protected function _get_magazines_data() {
return [
[