From 9e0b921f16f873c5d8c88182b1fa5698facf00d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kucha=C5=99?= <honza.kuchar@grifart.cz> Date: Sat, 21 May 2016 17:43:27 +0200 Subject: [PATCH] SemanticCursor: added scrollToEnd() and scrollToBeginning() --- src/SemanticCursor.php | 18 +++++++++++++++++- tests/Cursor/SemanticCursorTest.phpt | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/SemanticCursor.php b/src/SemanticCursor.php index 7e3244b..68da21e 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 fc3bb3c..7b05be6 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() -- GitLab