Skip to content

Commit

Permalink
Added tests for MultiCollection as well as a Base Collection test class
Browse files Browse the repository at this point in the history
  • Loading branch information
nozavroni committed Dec 5, 2016
1 parent be4772b commit c57c829
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/CSVelte/Collection/AbstractCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,12 @@ public static function isTabular($data)
return false;
}
}
// if row contains an array it isn't tabular
if (array_reduce($row, function($carry, $item){
return is_array($item) && $carry;
}, true)) {
return false;
}
}
return true;
}
Expand Down
20 changes: 20 additions & 0 deletions src/CSVelte/Collection/MultiCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,24 @@ protected function isConsistentDataStructure($data)
{
return static::isMultiDimensional($data);
}

/**
* @inheritdoc
*/
public function contains($value, $index = null)
{
if (parent::contains($value, $index)) {
return true;
} else {
foreach ($this->data as $key => $arr) {
if (is_traversable($arr)) {
$coll = static::factory($arr);
if ($coll->contains($value, $index)) {
return true;
}
}
}
}
return false;
}
}
3 changes: 1 addition & 2 deletions tests/CSVelte/Collection/CharCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
namespace CSVelteTest\Collection;

use CSVelte\Collection\CharCollection;
use CSVelteTest\UnitTestCase;

class CharCollectionTest extends UnitTestCase
class CharCollectionTest extends AbstractCollectionTest
{
public function testCharCollectionAcceptsString()
{
Expand Down
5 changes: 2 additions & 3 deletions tests/CSVelte/Collection/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
use \ArrayIterator;
use CSVelte\Collection\AbstractCollection;
use CSVelte\Collection\Collection;
use CSVelte\Contract\Collectable;
use CSVelteTest\UnitTestCase;
//use CSVelte\Contract\Collectable;
use function CSVelte\is_traversable;

class CollectionTest extends UnitTestCase
class CollectionTest extends AbstractCollectionTest
{
// public function testCollectFactoryReturnsCollectable()
// {
Expand Down
3 changes: 1 addition & 2 deletions tests/CSVelte/Collection/NumericCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

use CSVelte\Collection\Collection;
use CSVelte\Collection\NumericCollection;
use CSVelteTest\UnitTestCase;

class NumericCollectionTest extends UnitTestCase
class NumericCollectionTest extends AbstractCollectionTest
{
public function testIncrementDecrementAddsSubtractsOneFromGivenKey()
{
Expand Down

0 comments on commit c57c829

Please sign in to comment.