Permalink
Browse files

bug fix preserve fileObject CSV controls

When using AbstractCsv::createFromFileObject
the CSV object inherit the SplFileObject csv controls

A php bug was filled because SplFileObject::getCsvControl did not
return the escape caracter (see: https://bugs.php.net/bug.php?id=72646)

The bug is resolved so the patch can be completely applied and the testsuite
is updated accordingly
  • Loading branch information...
nyamsprod committed Jul 22, 2016
1 parent 2ec6db1 commit 8a20c56144effa552a8cba5d8c626063222975b7
Showing with 25 additions and 1 deletion.
  1. +9 −1 src/AbstractCsv.php
  2. +16 −0 test/FactoryTest.php
View
@@ -115,7 +115,15 @@ public function __destruct()
*/
public static function createFromFileObject(SplFileObject $file)
{
- return new static($file);
+ $csv = new static($file);
+ $controls = $file->getCsvControl();
+ $csv->setDelimiter($controls[0]);
+ $csv->setEnclosure($controls[1]);
+ if (isset($controls[2])) {
+ $csv->setEscape($controls[2]);
+ }
+
+ return $csv;
}
/**
View
@@ -73,4 +73,20 @@ public function testCreateFromFileObjectWithSplFileObject()
$this->assertInstanceof(Reader::class, $reader);
$this->assertInstanceof(SplFileObject::class, $reader->getIterator());
}
+
+
+ public function testCreateFromFileObjectPreserveFileObjectCsvControls()
+ {
+ $delimiter = "\t";
+ $enclosure = '?';
+ $escape = '^';
+ $file = new SplTempFileObject();
+ $file->setCsvControl($delimiter, $enclosure, $escape);
+ $obj = Reader::createFromFileObject($file);
+ $this->assertSame($delimiter, $obj->getDelimiter());
+ $this->assertSame($enclosure, $obj->getEnclosure());
+ if (3 === count($file->getCsvControl())) {
+ $this->assertSame($escape, $obj->getEscape());
+ }
+ }
}

0 comments on commit 8a20c56

Please sign in to comment.