|
|
@@ -42,6 +42,28 @@ class TestCollection extends \IteratorIterator implements CollectionInterface
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Special class to test that extending \ArrayIterator works as expected
|
|
|
+ */
|
|
|
+class TestIterator extends ArrayIterator
|
|
|
+{
|
|
|
+ use CollectionTrait;
|
|
|
+
|
|
|
+ public $data = [];
|
|
|
+
|
|
|
+ public function __construct($data)
|
|
|
+ {
|
|
|
+ $this->data = $data;
|
|
|
+
|
|
|
+ parent::__construct($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function checkValues()
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
* CollectionTest
|
|
|
*/
|
|
|
class CollectionTest extends TestCase
|
|
|
@@ -2512,4 +2534,30 @@ class CollectionTest extends TestCase
|
|
|
{
|
|
|
return new \DatePeriod(new \DateTime($start), new \DateInterval('P1D'), new \DateTime($end));
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Tests to ensure that collection classes extending ArrayIterator work as expected.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testArrayIteratorExtend()
|
|
|
+ {
|
|
|
+ $iterator = new TestIterator(range(0, 10));
|
|
|
+
|
|
|
+ $this->assertTrue(method_exists($iterator, 'checkValues'));
|
|
|
+ $this->assertTrue($iterator->checkValues());
|
|
|
+
|
|
|
+ //We need to perform at least two collection operation to trigger the issue.
|
|
|
+ $newIterator = $iterator
|
|
|
+ ->filter(function ($item) {
|
|
|
+ return $item < 5;
|
|
|
+ })
|
|
|
+ ->reject(function ($item) {
|
|
|
+ return $item > 2;
|
|
|
+ });
|
|
|
+
|
|
|
+ $this->assertTrue(method_exists($newIterator, 'checkValues'), 'Our method has gone missing!');
|
|
|
+ $this->assertTrue($newIterator->checkValues());
|
|
|
+ $this->assertCount(3, $newIterator->toArray());
|
|
|
+ }
|
|
|
}
|