summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorignace nyamagana butera <nyamsprod@gmail.com>2014-02-17 22:02:08 +0100
committerignace nyamagana butera <nyamsprod@gmail.com>2014-02-17 22:02:08 +0100
commit9fc42c1e994d9be598436301f44027bc20fdda80 (patch)
tree68dba17665265312901497e5b4f30645676158b6
parenta24d0ce6d0f9e3463d09a6cf25ba41a3487be6de (diff)
parent4cbd9e3f428e17ea4888ad7bf9a8cc12be0ee318 (diff)
downloadcsv-9fc42c1e994d9be598436301f44027bc20fdda80.zip
csv-9fc42c1e994d9be598436301f44027bc20fdda80.tar.gz
csv-9fc42c1e994d9be598436301f44027bc20fdda80.tar.bz2
Merge branch 'master' of github.com:nyamsprod/Bakame.csv
-rw-r--r--README.md53
-rw-r--r--examples/download.php4
-rw-r--r--examples/json.php2
-rw-r--r--examples/merge.php81
-rw-r--r--examples/xml.php17
-rw-r--r--src/AbstractCsv.php81
-rw-r--r--src/ConverterTrait.php157
-rw-r--r--src/Iterator/IteratorQuery.php2
-rw-r--r--src/Iterator/MapIterator.php2
-rw-r--r--src/Reader.php10
-rw-r--r--src/Writer.php2
-rw-r--r--test/CsvTest.php29
-rw-r--r--test/WriterTest.php9
13 files changed, 349 insertions, 100 deletions
diff --git a/README.md b/README.md
index d803628..70ac274 100644
--- a/README.md
+++ b/README.md
@@ -33,22 +33,29 @@ Install the Bakame.csv package with Composer.
Usage
-------
-* [Downloading the CSV](examples/download.php)
-* [Converting the CSV into a Json String](examples/json.php)
-* [Converting the CSV into a HTML Table](examples/table.php)
* [Selecting specific rows in the CSV](examples/extract.php)
* [Filtering a CSV](examples/filtering.php)
* [Creating a CSV](examples/writing.php)
+* [Merging 2 CSV documents](examples/merge.php)
* [Switching between modes from Writer to Reader mode](examples/switchmode.php)
+* [Downloading the CSV](examples/download.php)
+* [Converting the CSV into a Json String](examples/json.php)
+* [Converting the CSV into a XML file](examples/xml.php)
+* [Converting the CSV into a HTML Table](examples/table.php)
-> The CSV file use for the examples is taken from [Paris Opendata](http://opendata.paris.fr/opendata/jsp/site/Portal.jsp?document_id=60&portlet_id=121)
+> The CSV data use for the examples are taken from [Paris Opendata](http://opendata.paris.fr/opendata/jsp/site/Portal.jsp?document_id=60&portlet_id=121)
### Tips
-* When creating a file using the library, first insert all the data that need to be inserted before starting manipulating the CSV. If you manipulate your data before you may change the file cursor position and get unexpected results.
+* When creating a file using the library, first insert all the data that need to be inserted before starting manipulating the CSV. If you manipulate your data before insertion, you may change the file cursor position and get unexpected results.
* If you are dealing with non-unicode data, specify the encoding parameter using the `setEncoding` method otherwise your output conversions may no work.
+* When merging multiples CSV documents don't forget to set the main CSV object
+ as a `Bakame\Csv\Writer` object with the `$open_mode = 'a+'` to preserve its content.
+ This setting is of course not required when your main `Bakame\Csv\Writer` object is
+ created from String
+
* **If you are on a Mac OS X Server**, add the following lines before using the library to help [PHP detect line ending in Mac OS X](http://php.net/manual/en/function.fgetcsv.php#refsect1-function.fgetcsv-returnvalues).
```php
@@ -134,13 +141,28 @@ echo $writer;
echo $writer->__toString();
```
+#### convert to XML:
+
+Use the `toXML` method to convert the CSV data into a PHP `DomDocument` object. This method accepts 3 optionals arguments `$root_name`, `$row_name`, `$cell_name` to help you customize the XML tree.
+
+By default:
+* `$root_name = 'csv'`
+* `$row_name = 'row'`
+* `$cell_name = 'cell'`
+
+```php
+$dom = $writer->toXML('data', 'item', 'cell');
+```
+
+#### convert to HTML table:
+
Use the `toHTML` method to format the CSV data into an HTML table. This method accepts an optional argument `$classname` to help you customize the table rendering, by defaut the classname given to the table is `table-csv-data`.
```php
echo $writer->toHTML('table table-bordered table-hover');
```
-#### convert the CSV into a Json string:
+#### convert to Json
Use the `json_encode` function directly on the instantiated object.
@@ -148,7 +170,9 @@ Use the `json_encode` function directly on the instantiated object.
echo json_encode($writer);
```
-#### make the CSV downloadable
+**Of Note:** When using the `toHTML`, `toXML` methods and the `json_encode` function, the data is internally convert if needed into `UTF-8`.
+
+#### download the CSV
If you only wish to make your CSV downloadable just use the `output` method to return to the output buffer the CSV content.
@@ -158,6 +182,12 @@ header('Content-Type: text/csv; charset="'.$reader->getEncoding().'"');
header('Content-Disposition: attachment; filename="name-for-your-file.csv"');
$reader->output();
```
+The output method can take an optional argument `$filename`. When present you can even omit most of the headers.
+
+```php
+$reader->setEncoding('ISO-8859-15');
+$reader->output("name-for-your-file.csv");
+```
Extracting data from the CSV
-------
@@ -198,10 +228,13 @@ $data = $reader->fetchAssoc(['firstname', 'lastname', 'email']);
> * If the number of values in a CSV row is lesser than the number of named keys, the method will add `null` values to compensate for the missing values.
> * If the number of values in a CSV row is greater that the number of named keys the exceeding values will be drop from the result set.
-#### fetchCol($columnIndex, $callable = null)
+#### fetchCol($columnIndex = 0, $callable = null)
`fetchCol` returns a sequential array of all values in a given column from the CSV data.
+* If no argument is given to the method it will return the first colum from the CSV data.
+* If the column does not exists in the csv data the method will return an array full of null value.
+
```php
$data = $reader->fetchCol(2);
// will return something like this :
@@ -217,9 +250,9 @@ The methods listed above (`fetchAll`, `fetchAssoc`, `fetchCol`) can all take a o
* the current csv key
* the current csv Iterator Object
-#### fetchOne($offset)
+#### fetchOne($offset = 0)
-`fetchOne` return one single row from the CSV data. The required argument `$offset` represent the row index starting at 0.
+`fetchOne` return one single row from the CSV data. The required argument `$offset` represent the row index starting at 0. If no argument is given to the method it will return the first row from the CSV data.
```php
$data = $reader->fetchOne(3); ///accessing the 4th row (indexing starts at 0)
diff --git a/examples/download.php b/examples/download.php
index 3e017b6..150827c 100644
--- a/examples/download.php
+++ b/examples/download.php
@@ -6,6 +6,4 @@ require '../vendor/autoload.php';
$inputCsv = new Reader('data/prenoms.csv');
$inputCsv->setEncoding('ISO-8859-15');
-header('Content-Type: text/csv; charset="'.$inputCsv->getEncoding().'"');
-header('Content-Disposition: attachment; filename="firstname.csv"');
-$inputCsv->output();
+$inputCsv->output('firstname.csv'); //specifying a filename triggers header sending
diff --git a/examples/json.php b/examples/json.php
index b4caf2e..a679fec 100644
--- a/examples/json.php
+++ b/examples/json.php
@@ -12,5 +12,5 @@ $res = json_encode($inputCsv, JSON_PRETTY_PRINT|JSON_HEX_QUOT|JSON_HEX_TAG|JSON_
if (JSON_ERROR_NONE != json_last_error()) {
die(json_last_error_msg());
}
-header('Content-Type: application/json; charset="'.$inputCsv->getEncoding().'"');
+header('Content-Type: application/json; charset="utf-8"');
die($res);
diff --git a/examples/merge.php b/examples/merge.php
new file mode 100644
index 0000000..cdb9624
--- /dev/null
+++ b/examples/merge.php
@@ -0,0 +1,81 @@
+<?php
+
+use Bakame\Csv\Writer;
+use Bakame\Csv\Reader;
+
+require '../vendor/autoload.php';
+
+//we are creating a CSV from a raw string
+$rawCsv = <<<EOF
+Melodie;6;F;2011
+Melody;7;F;2011
+Melvil;13;M;2011
+Melvin;9;M;2011
+Menahem;6;M;2011
+Mendel;7;M;2011
+Meriem;8;F;2011
+Merlin;8;M;2011
+Meryam;7;F;2011
+EOF;
+
+$writer = Writer::createFromString($rawCsv);
+//because we raw string delimiter is ";"
+//the string delimiter MUST also be ";"
+$writer->setDelimiter(';');
+
+//we are creating a CSV from a raw string
+$rawCsv2Merge = <<<EOF
+Ben,7,M,2007
+Benjamin,78,M,2007
+BenoƮt,17,M,2007
+Berenice,19,F,2007
+Bertille,9,F,2007
+Bianca,18,F,2007
+Bilal,26,M,2007
+Bilel,7,M,2007
+EOF;
+
+$csv2merge = Reader::createFromString($rawCsv2Merge);
+//because we raw string delimiter is ";"
+//the string delimiter MUST also be ","
+$csv2merge->setDelimiter(',');
+
+/*
+ When merging multiples CSV documents don't forget to set the main CSV object
+ as a `Bakame\Csv\Writer` object with the $open_mode = 'a+' to preserve its content.
+ This setting is of course not required when your main CSV object is created from String
+*/
+
+?>
+<!doctype html>
+<html lang="fr">
+<head>
+ <meta charset="utf-8">
+ <title>Merging 2 CSV documents</title>
+ <link rel="stylesheet" href="example.css">
+</head>
+<body>
+<h1>Using the Bakame\Csv\Writer class to merge two CSV documents</h1>
+<h3>The main Raw CSV</h3>
+<p><em>The delimiter is a ";"</em></p>
+<pre>
+<?=$writer?>
+</pre>
+<h3>The Raw CSV to be merge</h3>
+<p><em>The delimiter is a ";"</em></p>
+<pre>
+<?=$csv2merge?>
+</pre>
+<?php $writer->insertAll($csv2merge); //we are merging both documents as simple as that!!?>
+<h3>The Raw CSV after merging</h3>
+<p><em>Notice that after merging the data is semi-colon ";" separated</em></p>
+<pre>
+<?=$writer?>
+</pre>
+<h3>Tips</h3>
+<p> When merging multiples CSV documents don't forget to set the main CSV object
+ as a <code>Bakame\Csv\Writer</code> object with the <code>$open_mode = 'a+'</code>
+ to preserve its content. This setting is of course not required when your main CSV object
+ is created from String</p>
+</body>
+</html>
diff --git a/examples/xml.php b/examples/xml.php
new file mode 100644
index 0000000..82052cb
--- /dev/null
+++ b/examples/xml.php
@@ -0,0 +1,17 @@
+<?php
+
+error_reporting(-1);
+ini_set('display_errors', 1);
+
+use Bakame\Csv\Reader;
+
+require '../vendor/autoload.php';
+
+$inputCsv = new Reader('data/prenoms.csv');
+$inputCsv->setEncoding('ISO-8859-15');
+$inputCsv->setDelimiter(';');
+$doc = $inputCsv->toXML('csv', 'ligne', 'cellule');
+$xml = $doc->saveXML();
+header('Content-Type: application/xml; charset="utf-8"');
+header('Content-Length: '.strlen($xml));
+die($xml);
diff --git a/src/AbstractCsv.php b/src/AbstractCsv.php
index 9b9bd71..c98fc90 100644
--- a/src/AbstractCsv.php
+++ b/src/AbstractCsv.php
@@ -6,7 +6,7 @@
* @copyright 2014 Ignace Nyamagana Butera
* @link https://github.com/nyamsprod/Bakame.csv
* @license http://opensource.org/licenses/MIT
-* @version 4.0.0
+* @version 4.2.0
* @package Bakame.csv
*
* MIT LICENSE
@@ -33,14 +33,12 @@
namespace Bakame\Csv;
use IteratorAggregate;
-use DomDocument;
use JsonSerializable;
use RuntimeException;
use SplFileInfo;
use SplFileObject;
use SplTempFileObject;
use InvalidArgumentException;
-use Bakame\Csv\Iterator\MapIterator;
/**
* A abstract class to enable basic CSV manipulation
@@ -52,6 +50,11 @@ use Bakame\Csv\Iterator\MapIterator;
class AbstractCsv implements JsonSerializable, IteratorAggregate
{
/**
+ * Trait to output the full CSV data
+ */
+ use ConverterTrait;
+
+ /**
* The CSV object holder
*
* @var \SplFileObject
@@ -153,7 +156,7 @@ class AbstractCsv implements JsonSerializable, IteratorAggregate
*
* @return boolean
*/
- protected static function isValidString($str)
+ public static function isValidString($str)
{
return (is_scalar($str) || (is_object($str) && method_exists($str, '__toString')));
}
@@ -340,77 +343,9 @@ class AbstractCsv implements JsonSerializable, IteratorAggregate
*/
public function getIterator()
{
- return $this->csv;
- }
-
- /**
- * Output all data on the CSV file
- */
- public function output()
- {
- $this->csv->rewind();
- $this->csv->fpassthru();
- }
-
- /**
- * Retrieves the CSV content
- *
- * @return string
- */
- public function __toString()
- {
- ob_start();
- $this->output();
-
- return ob_get_clean();
- }
-
- /**
- * Return a HTML table representation of the CSV Table
- *
- * @param string $classname optional classname
- *
- * @return string
- */
- public function toHTML($classname = 'table-csv-data')
- {
- $doc = new DomDocument('1.0', $this->encoding);
- $table = $doc->createElement('table');
- $table->setAttribute('class', $classname);
- $this->csv->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
- $this->csv->setFlags($this->flags);
- foreach ($this->csv as $row) {
- $tr = $doc->createElement('tr');
- foreach ($row as $value) {
- $tr->appendChild($doc->createElement('td', htmlspecialchars($value, ENT_COMPAT, $this->encoding)));
- }
- $table->appendChild($tr);
- }
-
- return $doc->saveHTML($table);
- }
-
- /**
- * JsonSerializable Interface
- *
- * @return array
- */
- public function jsonSerialize()
- {
$this->csv->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
$this->csv->setFlags($this->flags);
- $iterator = $this->csv;
- if ('UTF-8' != $this->encoding) {
- $iterator = new MapIterator($iterator, function ($row) {
- foreach ($row as &$value) {
- $value = mb_convert_encoding($value, 'UTF-8', $this->encoding);
- }
- unset($value);
-
- return $row;
- });
- }
- return iterator_to_array($iterator, false);
+ return $this->csv;
}
}
diff --git a/src/ConverterTrait.php b/src/ConverterTrait.php
new file mode 100644
index 0000000..f6cf6ed
--- /dev/null
+++ b/src/ConverterTrait.php
@@ -0,0 +1,157 @@
+<?php
+/**
+* Bakame.csv - A lightweight CSV Coder/Decoder library
+*
+* @author Ignace Nyamagana Butera <nyamsprod@gmail.com>
+* @copyright 2014 Ignace Nyamagana Butera
+* @link https://github.com/nyamsprod/Bakame.csv
+* @license http://opensource.org/licenses/MIT
+* @version 4.2.0
+* @package Bakame.csv
+*
+* MIT LICENSE
+*
+* Permission is hereby granted, free of charge, to any person obtaining
+* a copy of this software and associated documentation files (the
+* "Software"), to deal in the Software without restriction, including
+* without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to
+* permit persons to whom the Software is furnished to do so, subject to
+* the following conditions:
+*
+* The above copyright notice and this permission notice shall be
+* included in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+namespace Bakame\Csv;
+
+use DomDocument;
+use SplTempFileObject;
+use Bakame\Csv\Iterator\MapIterator;
+
+/**
+ * A abstract class to enable basic CSV manipulation
+ *
+ * @package Bakame.csv
+ * @since 4.2.0
+ *
+ */
+trait ConverterTrait
+{
+ /**
+ * Convert Csv file into UTF-8
+ *
+ * @return \Iterator
+ */
+ protected function convert2Utf8()
+ {
+ if ('UTF-8' == $this->encoding) {
+ return $this->getIterator();
+ }
+
+ return new MapIterator($this->getIterator(), function ($row) {
+ foreach ($row as &$value) {
+ $value = mb_convert_encoding($value, 'UTF-8', $this->encoding);
+ }
+ unset($value);
+
+ return $row;
+ });
+ }
+
+ /**
+ * Output all data on the CSV file
+ *
+ * @param string $filename CSV downloaded name if present adds extra headers
+ */
+ public function output($filename = null)
+ {
+ $iterator = $this->getIterator();
+ //@codeCoverageIgnoreStart
+ if (! is_null($filename) && AbstractCsv::isValidString($filename)) {
+ header('Content-Type: text/csv; charset="'.$this->encoding.'"');
+ header('Content-Disposition: attachment; filename="'.$filename.'"');
+ if (! $iterator instanceof SplTempFileObject) {
+ header('Content-Length: '.$iterator->getSize());
+ }
+ }
+ //@codeCoverageIgnoreEnd
+ $iterator->rewind();
+ $iterator->fpassthru();
+ }
+
+ /**
+ * Retrieves the CSV content
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ ob_start();
+ $this->output();
+
+ return ob_get_clean();
+ }
+
+ /**
+ * transform a CSV into a XML
+ *
+ * @param string $root_name XML root node name
+ * @param string $row_name XML row node name
+ * @param string $cell_name XML cell node name
+ *
+ * @return \DomDocument
+ */
+ public function toXML($root_name = 'csv', $row_name = 'row', $cell_name = 'cell')
+ {
+ $doc = new DomDocument('1.0', 'UTF-8');
+ $root = $doc->createElement($root_name);
+ foreach ($this->convert2Utf8() as $row) {
+ $item = $doc->createElement($row_name);
+ foreach ($row as $value) {
+ $content = $doc->createTextNode($value);
+ $cell = $doc->createElement($cell_name);
+ $cell->appendChild($content);
+ $item->appendChild($cell);
+ }
+ $root->appendChild($item);
+ }
+ $doc->appendChild($root);
+
+ return $doc;
+ }
+
+ /**
+ * Return a HTML table representation of the CSV Table
+ *
+ * @param string $classname optional classname
+ *
+ * @return string
+ */
+ public function toHTML($classname = 'table-csv-data')
+ {
+ $doc = $this->toXML('table', 'tr', 'td');
+ $doc->documentElement->setAttribute('class', $classname);
+
+ return $doc->saveHTML($doc->documentElement);
+ }
+
+ /**
+ * JsonSerializable Interface
+ *
+ * @return array
+ */
+ public function jsonSerialize()
+ {
+ $iterator = $this->convert2Utf8();
+
+ return iterator_to_array($iterator, false);
+ }
+}
diff --git a/src/Iterator/IteratorQuery.php b/src/Iterator/IteratorQuery.php
index 5541b43..f498f5a 100644
--- a/src/Iterator/IteratorQuery.php
+++ b/src/Iterator/IteratorQuery.php
@@ -6,7 +6,7 @@
* @copyright 2014 Ignace Nyamagana Butera
* @link https://github.com/nyamsprod/Bakame.csv
* @license http://opensource.org/licenses/MIT
-* @version 4.0.0
+* @version 4.2.0
* @package Bakame.csv
*
* MIT LICENSE
diff --git a/src/Iterator/MapIterator.php b/src/Iterator/MapIterator.php
index 12843c0..866adf4 100644
--- a/src/Iterator/MapIterator.php
+++ b/src/Iterator/MapIterator.php
@@ -6,7 +6,7 @@
* @copyright 2014 Ignace Nyamagana Butera
* @link https://github.com/nyamsprod/Bakame.csv
* @license http://opensource.org/licenses/MIT
-* @version 4.0.0
+* @version 4.2.0
* @package Bakame.csv
*
* MIT LICENSE
diff --git a/src/Reader.php b/src/Reader.php
index 028a7bf..45a597a 100644
--- a/src/Reader.php
+++ b/src/Reader.php
@@ -6,7 +6,7 @@
* @copyright 2014 Ignace Nyamagana Butera
* @link https://github.com/nyamsprod/Bakame.csv
* @license http://opensource.org/licenses/MIT
-* @version 4.0.0
+* @version 4.2.0
* @package Bakame.csv
*
* MIT LICENSE
@@ -86,9 +86,7 @@ class Reader extends AbstractCsv
*/
public function query(callable $callable = null)
{
- $this->csv->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
- $this->csv->setFlags($this->flags);
- $iterator = new CallbackFilterIterator($this->csv, function ($row) {
+ $iterator = new CallbackFilterIterator($this->getIterator(), function ($row) {
return is_array($row);
});
@@ -104,7 +102,7 @@ class Reader extends AbstractCsv
*
* @throws \InvalidArgumentException If the $offset is not a valid Integer
*/
- public function fetchOne($offset)
+ public function fetchOne($offset = 0)
{
$this->setOffset($offset);
$this->setLimit(1);
@@ -172,7 +170,7 @@ class Reader extends AbstractCsv
*
* @throws \InvalidArgumentException If the column index is not a positive integer or 0
*/
- public function fetchCol($columnIndex, callable $callable = null)
+ public function fetchCol($columnIndex = 0, callable $callable = null)
{
if (false === filter_var($columnIndex, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]])) {
throw new InvalidArgumentException(
diff --git a/src/Writer.php b/src/Writer.php
index c853324..f151988 100644
--- a/src/Writer.php
+++ b/src/Writer.php
@@ -6,7 +6,7 @@
* @copyright 2014 Ignace Nyamagana Butera
* @link https://github.com/nyamsprod/Bakame.csv
* @license http://opensource.org/licenses/MIT
-* @version 4.0.0
+* @version 4.2.0
* @package Bakame.csv
*
* MIT LICENSE
diff --git a/test/CsvTest.php b/test/CsvTest.php
index e912505..7a6defa 100644
--- a/test/CsvTest.php
+++ b/test/CsvTest.php
@@ -6,6 +6,9 @@ use SplFileInfo;
use SplFileObject;
use SplTempFileObject;
use PHPUnit_Framework_TestCase;
+use DateTime;
+
+date_default_timezone_set('UTC');
/**
* @group csv
@@ -108,7 +111,7 @@ class CsvTest extends PHPUnit_Framework_TestCase
*/
public function testFailCreateFromString()
{
- Reader::createFromString(new \DateTime);
+ Reader::createFromString(new DateTime);
}
/**
@@ -168,6 +171,30 @@ EOF;
$this->assertSame($expected, $this->csv->toHTML());
}
+ public function testToXML()
+ {
+ $expected = <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<csv>
+ <row>
+ <cell>john</cell>
+ <cell>doe</cell>
+ <cell>john.doe@example.com</cell>
+ </row>
+ <row>
+ <cell>jane</cell>
+ <cell>doe</cell>
+ <cell>jane.doe@example.com</cell>
+ </row>
+</csv>
+
+EOF;
+ $doc = $this->csv->toXML();
+ $this->assertInstanceof('\DomDocument', $doc);
+ $doc->formatOutput = true;
+ $this->assertSame($expected, $doc->saveXML());
+ }
+
/**
* @param $rawCsv
*
diff --git a/test/WriterTest.php b/test/WriterTest.php
index 7b228cb..ccd45cd 100644
--- a/test/WriterTest.php
+++ b/test/WriterTest.php
@@ -5,6 +5,9 @@ namespace Bakame\Csv;
use SplTempFileObject;
use ArrayIterator;
use PHPUnit_Framework_TestCase;
+use DateTime;
+
+date_default_timezone_set('UTC');
/**
* @group writer
@@ -47,7 +50,7 @@ class WriterTest extends PHPUnit_Framework_TestCase
*/
public function testFailedInsertWithWrongData()
{
- $this->csv->insertOne(new \DateTime);
+ $this->csv->insertOne(new DateTime);
}
/**
@@ -55,7 +58,7 @@ class WriterTest extends PHPUnit_Framework_TestCase
*/
public function testFailedInsertWithMultiDimensionArray()
{
- $this->csv->insertOne(['john', new \DateTime]);
+ $this->csv->insertOne(['john', new DateTime]);
}
public function testSave()
@@ -80,7 +83,7 @@ class WriterTest extends PHPUnit_Framework_TestCase
*/
public function testFailedSaveWithWrongType()
{
- $this->csv->insertAll(new \DateTime);
+ $this->csv->insertAll(new DateTime);
}
public function testGetReader()