diff options
author | Ignace Nyamagana Butera <nyamsprod@gmail.com> | 2015-01-28 12:03:14 +0100 |
---|---|---|
committer | Ignace Nyamagana Butera <nyamsprod@gmail.com> | 2015-01-28 12:03:14 +0100 |
commit | 08802ef10cc607484a7efe2a02bf2a521abf3b7e (patch) | |
tree | 44693064ab4de21b54e18e53892dabdf42ad940d | |
parent | b2167534b7c23cad4567a0d59d543d2a2540eb8d (diff) | |
download | csv-08802ef10cc607484a7efe2a02bf2a521abf3b7e.zip csv-08802ef10cc607484a7efe2a02bf2a521abf3b7e.tar.gz csv-08802ef10cc607484a7efe2a02bf2a521abf3b7e.tar.bz2 |
improve new Features
-rw-r--r-- | src/Config/Factory.php | 9 | ||||
-rw-r--r-- | src/Writer.php | 2 | ||||
-rw-r--r-- | test/WriterTest.php | 11 |
3 files changed, 18 insertions, 4 deletions
diff --git a/src/Config/Factory.php b/src/Config/Factory.php index 2fe042b..3e3d0fe 100644 --- a/src/Config/Factory.php +++ b/src/Config/Factory.php @@ -21,7 +21,7 @@ use SplTempFileObject; * A trait to facilate class instantiation * * @package League.csv - * @since 6.X.X + * @since 6.4.0 * */ trait Factory @@ -112,6 +112,11 @@ trait Factory $obj = new SplTempFileObject(); $obj->fwrite(rtrim($str).$newline); - return static::createFromFileObject($obj); + $res = static::createFromFileObject($obj); + if ('League\Csv\Writer' == get_class($res)) { + $res->setNewline($newline); + } + + return $res; } } diff --git a/src/Writer.php b/src/Writer.php index 65b1215..69b1f95 100644 --- a/src/Writer.php +++ b/src/Writer.php @@ -195,7 +195,7 @@ class Writer extends AbstractCsv * * @return static */ - public function setCellContentValidation($status) + public function useFormatValidation($status) { $this->checkCellContent = (bool) $status; diff --git a/test/WriterTest.php b/test/WriterTest.php index d4dd0ef..22f1137 100644 --- a/test/WriterTest.php +++ b/test/WriterTest.php @@ -119,7 +119,7 @@ class WriterTest extends PHPUnit_Framework_TestCase ['john', null, 'john.doe@example.com'], ]; $this->csv->setNullHandlingMode(Writer::NULL_AS_EMPTY); - $this->csv->setCellContentValidation(false); + $this->csv->useFormatValidation(false); $this->csv->insertAll($expected); $iterator = new LimitIterator($this->csv->getIterator(), 2, 1); @@ -243,4 +243,13 @@ class WriterTest extends PHPUnit_Framework_TestCase $csv->insertOne(["jane", "doe"]); $this->assertSame("jane,doe\r\n", (string) $csv); } + + public function testCustomNewlineFromCreateFromString() + { + $expected = "\r\n"; + $raw = "john,doe,john.doe@example.com".PHP_EOL + ."jane,doe,jane.doe@example.com".PHP_EOL; + $csv = Writer::createFromString($raw, $expected); + $this->assertSame($expected, $csv->getNewline()); + } } |