mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 00:36:38 +00:00
fixes unparse bug if array ids doesn't begin on zero (comments#149)
This commit is contained in:
@@ -846,7 +846,7 @@ class Csv {
|
||||
}
|
||||
|
||||
// this is needed because sometime titles property is overwritten instead of using fields parameter!
|
||||
$titlesOnParse = !empty($this->data) ? array_keys($this->data[0]) : array();
|
||||
$titlesOnParse = !empty($this->data) ? array_keys(reset($this->data)) : array();
|
||||
|
||||
// both are identical, also in ordering
|
||||
if (array_values($fields) === array_values($titlesOnParse)) {
|
||||
|
||||
@@ -75,6 +75,12 @@ class UnparseTest extends Testcase {
|
||||
$this->unparseAndCompare($expected, $fields);
|
||||
}
|
||||
|
||||
public function testUnparseDefaultFirstRowMissing(){
|
||||
unset($this->csv->data[0]);
|
||||
$expected = "column1,column2\rvalue3,value4\r";
|
||||
$this->unparseAndCompare($expected);
|
||||
}
|
||||
|
||||
private function unparseAndCompare($expected, $fields = array()) {
|
||||
$str = $this->csv->unparse($this->csv->data, $fields);
|
||||
$this->assertEquals($expected, $str);
|
||||
|
||||
Reference in New Issue
Block a user