Skip to content
Permalink
Browse files

Added more tests for CollectionTrait::append

  • Loading branch information...
sukihub committed May 10, 2015
1 parent 14a2450 commit b9cad162529d3feb7b290fdcdc5698c9cb28e504
Showing with 40 additions and 0 deletions.
  1. +40 −0 tests/TestCase/Collection/CollectionTest.php
@@ -17,9 +17,31 @@
use ArrayIterator;
use ArrayObject;
use Cake\Collection\Collection;
use Cake\Collection\CollectionInterface;
use Cake\Collection\CollectionTrait;
use Cake\TestSuite\TestCase;
use NoRewindIterator;
class TestCollection extends \IteratorIterator implements CollectionInterface
{
use CollectionTrait;
public function __construct($items)
{
if (is_array($items)) {
$items = new \ArrayIterator($items);
}
if (!($items instanceof \Traversable)) {
$msg = 'Only an array or \Traversable is allowed for Collection';
throw new \InvalidArgumentException($msg);
}
parent::__construct($items);
}
}
/**
* CollectionTest
*
@@ -689,6 +711,24 @@ public function testAppend()
$this->assertEquals(['a' => 4, 'b' => 2, 'c' => 3], $combined->toArray());
}
/**
* Tests the append method with iterator
*/
public function testAppendIterator()
{
$collection = new Collection([1, 2, 3]);
$iterator = new ArrayIterator([4, 5, 6]);
$combined = $collection->append($iterator);
$this->assertEquals([1, 2, 3, 4, 5, 6], $combined->toList());
}
public function testAppendNotCollectionInstance()
{
$collection = new TestCollection([1, 2, 3]);
$combined = $collection->append([4, 5, 6]);
$this->assertEquals([1, 2, 3, 4, 5, 6], $combined->toList());
}
/**
* Tests that by calling compile internal iteration operations are not done
* more than once

0 comments on commit b9cad16

Please sign in to comment.
You can’t perform that action at this time.