summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorIgnace Nyamagana Butera <nyamsprod@gmail.com>2014-12-01 09:14:54 +0100
committerIgnace Nyamagana Butera <nyamsprod@gmail.com>2014-12-01 09:14:54 +0100
commitbcb0fd0dd7a3c8d913f9262f76b6b6665fdc8828 (patch)
tree9c23318bf25bd59bbba7ada6584fa780860a83ff /test
parent28eabada4d2ccefc272b506dbcf1d6e9ebab9b06 (diff)
downloadcsv-bcb0fd0dd7a3c8d913f9262f76b6b6665fdc8828.zip
csv-bcb0fd0dd7a3c8d913f9262f76b6b6665fdc8828.tar.gz
csv-bcb0fd0dd7a3c8d913f9262f76b6b6665fdc8828.tar.bz2
Bug fix in implementing issue #62
Diffstat (limited to 'test')
-rw-r--r--test/ReaderTest.php44
1 files changed, 38 insertions, 6 deletions
diff --git a/test/ReaderTest.php b/test/ReaderTest.php
index 47e38fb..05e4824 100644
--- a/test/ReaderTest.php
+++ b/test/ReaderTest.php
@@ -287,12 +287,44 @@ EOF;
$this->assertInstanceOf('\League\Csv\Writer', $csv);
}
- public function testFetchAssocWithoutKeys()
+ public function testFetchAssocWithARowIndex()
{
- $csv = Reader::createFromPath(__DIR__.'/data/prenoms.csv');
- $csv->setDelimiter(';');
- $csv->setEncodingFrom("iso-8859-15");
- $data = $csv->fetchAssoc();
- $this->assertTrue($data[0]['prenoms'] == 'Aaron');
+ $arr = [
+ ['A', 'B', 'C'],
+ [1, 2, 3],
+ ['D', 'E', 'F'],
+ [6, 7, 8],
+ ];
+
+ $tmpFile = new SplTempFileObject();
+ foreach ($arr as $row) {
+ $tmpFile->fputcsv($row);
+ }
+
+ $csv = Reader::createFromFileObject($tmpFile);
+ $res = $csv->setOffSet(2)->fetchAssoc(2);
+ $this->assertSame([['D' => '6', 'E' => '7', 'F' => '8']], $res);
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage the column index must be a positive integer or 0
+ */
+ public function testFetchAssocWithInvalidKey()
+ {
+ $arr = [
+ ['A', 'B', 'C'],
+ [1, 2, 3],
+ ['D', 'E', 'F'],
+ [6, 7, 8],
+ ];
+
+ $tmpFile = new SplTempFileObject();
+ foreach ($arr as $row) {
+ $tmpFile->fputcsv($row);
+ }
+
+ $csv = Reader::createFromFileObject($tmpFile);
+ $res = $csv->fetchAssoc(-23);
}
}