Browse Source

Added tests and fixed a bug in BufferedIterator

Jose Lorenzo Rodriguez 11 years ago
parent
commit
e7f2d27a9d
1 changed files with 12 additions and 1 deletions
  1. 12 1
      src/Collection/Iterator/BufferedIterator.php

+ 12 - 1
src/Collection/Iterator/BufferedIterator.php

@@ -60,6 +60,13 @@ class BufferedIterator extends Collection {
 	protected $_started = false;
 
 /**
+ * Whether or not the internal iterator's has reached its end
+ *
+ * @var boolean
+ */
+	protected $_finished = false;
+
+/**
  * Maintains an in-memory cache of the results yielded by the internal
  * iterator.
  *
@@ -127,6 +134,7 @@ class BufferedIterator extends Collection {
 			]);
 		}
 
+		$this->_finished = !$valid;
 		return $valid;
 	}
 
@@ -137,7 +145,10 @@ class BufferedIterator extends Collection {
  */
 	public function next() {
 		$this->_index++;
-		parent::next();
+
+		if (!$this->_finished) {
+			parent::next();
+		}
 	}
 
 }