summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgnace Nyamagana Butera <nyamsprod@gmail.com>2014-12-01 17:17:14 +0100
committerIgnace Nyamagana Butera <nyamsprod@gmail.com>2014-12-01 17:17:14 +0100
commita20b9eb98458d3a52d6709c759babd855cb2732a (patch)
tree4fac27941cf93bf125077a6f288947e2ba26966e
parentbcb0fd0dd7a3c8d913f9262f76b6b6665fdc8828 (diff)
downloadcsv-a20b9eb98458d3a52d6709c759babd855cb2732a.zip
csv-a20b9eb98458d3a52d6709c759babd855cb2732a.tar.gz
csv-a20b9eb98458d3a52d6709c759babd855cb2732a.tar.bz2
prepare for 6.1 release
-rw-r--r--CHANGELOG.md11
-rw-r--r--src/AbstractCsv.php4
-rw-r--r--src/Config/Controls.php2
-rw-r--r--src/Config/StreamFilter.php2
-rw-r--r--src/Iterator/MapIterator.php2
-rw-r--r--src/Iterator/Query.php2
-rw-r--r--src/Reader.php16
-rw-r--r--src/Writer.php2
-rw-r--r--test/ReaderTest.php111
9 files changed, 90 insertions, 62 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 16346d4..fc3304c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,17 @@
#Changelog
All Notable changes to `League\Csv` will be documented in this file
+## 6.1.0 - XXXX-XX-XX
+
+### Added
+- `Reader::fetchAssoc` now also accepts an integer as first argument representing a row index.
+
+### Deprecated
+- Nothing
+
+### Fixed
+- Nothing
+
## 6.0.1 - 2014-11-12
### Added
diff --git a/src/AbstractCsv.php b/src/AbstractCsv.php
index 566a28c..5c30036 100644
--- a/src/AbstractCsv.php
+++ b/src/AbstractCsv.php
@@ -4,7 +4,7 @@
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/thephpleague/csv/
-* @version 6.0.1
+* @version 6.1.0
* @package League.csv
*
* For the full copyright and license information, please view the LICENSE
@@ -332,7 +332,7 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate
/**
* Validate a variable to be stringable
*
- * @param string $str
+ * @param object|string $str
*
* @return bool
*/
diff --git a/src/Config/Controls.php b/src/Config/Controls.php
index fb2dd7e..8eba624 100644
--- a/src/Config/Controls.php
+++ b/src/Config/Controls.php
@@ -4,7 +4,7 @@
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/thephpleague/csv/
-* @version 6.0.1
+* @version 6.1.0
* @package League.csv
*
* For the full copyright and license information, please view the LICENSE
diff --git a/src/Config/StreamFilter.php b/src/Config/StreamFilter.php
index 72e88f8..bf9bb84 100644
--- a/src/Config/StreamFilter.php
+++ b/src/Config/StreamFilter.php
@@ -4,7 +4,7 @@
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/thephpleague/csv/
-* @version 6.0.1
+* @version 6.1.0
* @package League.csv
*
* For the full copyright and license information, please view the LICENSE
diff --git a/src/Iterator/MapIterator.php b/src/Iterator/MapIterator.php
index 65b3578..1a6a82c 100644
--- a/src/Iterator/MapIterator.php
+++ b/src/Iterator/MapIterator.php
@@ -4,7 +4,7 @@
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/thephpleague/csv/
-* @version 6.0.1
+* @version 6.1.0
* @package League.csv
*
* For the full copyright and license information, please view the LICENSE
diff --git a/src/Iterator/Query.php b/src/Iterator/Query.php
index 462e6c6..6db93e9 100644
--- a/src/Iterator/Query.php
+++ b/src/Iterator/Query.php
@@ -4,7 +4,7 @@
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/thephpleague/csv/
-* @version 6.0.1
+* @version 6.1.0
* @package League.csv
*
* For the full copyright and license information, please view the LICENSE
diff --git a/src/Reader.php b/src/Reader.php
index dddd33b..d7c2478 100644
--- a/src/Reader.php
+++ b/src/Reader.php
@@ -4,7 +4,7 @@
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/thephpleague/csv/
-* @version 6.0.1
+* @version 6.1.0
* @package League.csv
*
* For the full copyright and license information, please view the LICENSE
@@ -99,12 +99,8 @@ class Reader extends AbstractCsv
$this->setLimit(1);
$iterator = $this->query();
$iterator->rewind();
- $res = $iterator->current();
- if (! is_array($res)) {
- return [];
- }
- return $res;
+ return (array) $iterator->current();
}
/**
@@ -131,7 +127,7 @@ class Reader extends AbstractCsv
* used as the associated named keys
* @param callable $callable a callable function
*
- * @throws \InvalidArgumentException If the submitted keys are not integer or strng
+ * @throws \InvalidArgumentException If the submitted keys are not integer or string
*
* @return array
*/
@@ -140,12 +136,12 @@ class Reader extends AbstractCsv
$keys = $this->formatAssocKeys($keys);
if (! $this->isValidAssocKeys($keys)) {
throw new InvalidArgumentException(
- 'The named keys should be unique strings Or integer'
+ 'Use a flat non empty array with unique string values'
);
}
$iterator = $this->query($callable);
$iterator = new MapIterator($iterator, function ($row) use ($keys) {
- return self::combineArray($keys, $row);
+ return static::combineArray($keys, $row);
});
return iterator_to_array($iterator, false);
@@ -175,7 +171,7 @@ class Reader extends AbstractCsv
$iterator = new LimitIterator($this->getIterator(), $keys, 1);
$iterator->rewind();
- return $iterator->current();
+ return (array) $iterator->current();
}
/**
diff --git a/src/Writer.php b/src/Writer.php
index 762c6ac..4370bc7 100644
--- a/src/Writer.php
+++ b/src/Writer.php
@@ -4,7 +4,7 @@
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/thephpleague/csv/
-* @version 6.0.1
+* @version 6.1.0
* @package League.csv
*
* For the full copyright and license information, please view the LICENSE
diff --git a/test/ReaderTest.php b/test/ReaderTest.php
index 05e4824..9cea8ca 100644
--- a/test/ReaderTest.php
+++ b/test/ReaderTest.php
@@ -144,10 +144,9 @@ class ReaderTest extends PHPUnit_Framework_TestCase
public function testFetchAssocCallback()
{
$keys = ['firstname', 'lastname', 'email'];
- $func = function ($value) {
+ $res = $this->csv->fetchAssoc($keys, function ($value) {
return array_map('strtoupper', $value);
- };
- $res = $this->csv->fetchAssoc($keys, $func);
+ });
foreach ($res as $row) {
$this->assertSame($keys, array_keys($row));
}
@@ -171,15 +170,78 @@ class ReaderTest extends PHPUnit_Framework_TestCase
}
}
+ public function testFetchAssocWithRowIndex()
+ {
+ $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 named keys should be unique strings Or integer
+ * @expectedExceptionMessage Use a flat non empty array with unique string values
*/
public function testFetchAssocKeyFailure()
{
$this->csv->fetchAssoc([['firstname', 'lastname', 'email', 'age']]);
}
+ /**
+ * @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);
+ $csv->fetchAssoc(-23);
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage Use a flat non empty array with unique string values
+ */
+ public function testFetchAssocWithEmptyArr()
+ {
+ $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);
+ $csv->fetchAssoc(23);
+ }
+
public function testFetchCol()
{
$this->assertSame(['john', 'jane'], $this->csv->fetchColumn(0));
@@ -286,45 +348,4 @@ EOF;
$csv = Reader::createFromPath(__DIR__.'/foo.csv')->newWriter('a+');
$this->assertInstanceOf('\League\Csv\Writer', $csv);
}
-
- public function testFetchAssocWithARowIndex()
- {
- $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);
- }
}