diff --git a/src/SemanticCursor.php b/src/SemanticCursor.php index 7e3244b0ff7210ad878caa774eca370f0f07cec7..68da21e005677794d25cd3fef2d96c3aa77fe908 100644 --- a/src/SemanticCursor.php +++ b/src/SemanticCursor.php @@ -19,7 +19,7 @@ namespace Grifart\Mappi\Cursor; class SemanticCursor implements ICursor { /** @var ICursor */ - private $cursor; + protected $cursor; /** * @param ICursor $cursor @@ -71,6 +71,22 @@ class SemanticCursor implements ICursor $this->moveFromEndTo(0); } + /** + * Scrolls to the END + */ + public function scrollToEnd() : int + { + return $this->scroll(ICursor::FETCH_REMAINING); + } + + /** + * Scroll to the BEGINNING + */ + public function scrollToBeginning() : int + { + return $this->scroll(ICursor::FETCH_FOREGOING); + } + // ---- FETCH ---- /** diff --git a/tests/Cursor/SemanticCursorTest.phpt b/tests/Cursor/SemanticCursorTest.phpt index fc3bb3c70c087be5553d65200d6806230936c448..7b05be6741bf8d817d2fa81481c8783c85bfe191 100644 --- a/tests/Cursor/SemanticCursorTest.phpt +++ b/tests/Cursor/SemanticCursorTest.phpt @@ -137,6 +137,22 @@ class SemanticCursorTest extends BaseTest $this->uut->moveToEnd(); } + // ---- the extension - scroll* ---- + + public function test_scrollBeginning() { + $this->mockedCursor->shouldReceive("scroll") + ->with(ICursor::FETCH_FOREGOING)->once()->andReturn(5); + + Assert::same(5, $this->uut->scrollToBeginning()); + } + + public function test_scrollEnd() { + $this->mockedCursor->shouldReceive("scroll") + ->with(ICursor::FETCH_REMAINING)->once()->andReturn(5); + + Assert::same(5, $this->uut->scrollToEnd()); + } + // ---- the extension - fetch* ---- public function test_fetchNext()