From 3a3531ba594f1e65a8d0baede534c8018c9e0e41 Mon Sep 17 00:00:00 2001 From: ddevsr Date: Tue, 27 Sep 2022 13:47:13 +0700 Subject: [PATCH 1/5] docs: replace type in Pager --- system/Pager/Pager.php | 4 ++-- system/Pager/PagerInterface.php | 4 ++-- tests/system/Pager/PagerTest.php | 31 +++++++++++++++++++++++++------ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/system/Pager/Pager.php b/system/Pager/Pager.php index 80861646efdc..2c0179a69dc3 100644 --- a/system/Pager/Pager.php +++ b/system/Pager/Pager.php @@ -158,7 +158,7 @@ public function store(string $group, int $page, ?int $perPage, int $total, int $ /** * Sets segment for a group. * - * @return mixed + * @return $this */ public function setSegment(int $number, string $group = 'default') { @@ -174,7 +174,7 @@ public function setSegment(int $number, string $group = 'default') /** * Sets the path that an aliased group of links will use. * - * @return mixed + * @return $this */ public function setPath(string $path, string $group = 'default') { diff --git a/system/Pager/PagerInterface.php b/system/Pager/PagerInterface.php index 73c15473e78e..84018d7ac5f9 100644 --- a/system/Pager/PagerInterface.php +++ b/system/Pager/PagerInterface.php @@ -42,14 +42,14 @@ public function makeLinks(int $page, int $perPage, int $total, string $template * Stores a set of pagination data for later display. Most commonly used * by the model to automate the process. * - * @return mixed + * @return $this */ public function store(string $group, int $page, int $perPage, int $total); /** * Sets the path that an aliased group of links will use. * - * @return mixed + * @return $this */ public function setPath(string $path, string $group = 'default'); diff --git a/tests/system/Pager/PagerTest.php b/tests/system/Pager/PagerTest.php index c940d18c73fe..6aabdff3e929 100644 --- a/tests/system/Pager/PagerTest.php +++ b/tests/system/Pager/PagerTest.php @@ -18,7 +18,7 @@ use CodeIgniter\Pager\Exceptions\PagerException; use CodeIgniter\Test\CIUnitTestCase; use Config\App; -use Config\Pager; +use Config\Pager as PagerConfig; use Config\Services; /** @@ -28,7 +28,7 @@ */ final class PagerTest extends CIUnitTestCase { - private ?\CodeIgniter\Pager\Pager $pager = null; + private ?Pager $pager = null; private $config; protected function setUp(): void @@ -58,8 +58,8 @@ private function createPager(string $requestUri): void $request = $request->withMethod('GET'); Services::injectMock('request', $request); - $this->config = new Pager(); - $this->pager = new \CodeIgniter\Pager\Pager($this->config, Services::renderer()); + $this->config = new PagerConfig(); + $this->pager = new Pager($this->config, Services::renderer()); } public function testSetPathRemembersPath() @@ -180,6 +180,25 @@ public function testStoreWithSegments() ); } + public function testStoreWithURIReturnObject() + { + $_GET['page'] = 5; + $_GET['id'] = 1; + + $this->pager->store('bar', 5, 25, 100, 1); + + $uri = $this->pager->getPageURI(7, 'bar', true); + $onlyURI = $this->pager->only(['bar'])->getPageURI(9, 'bar', true); + + // Total Segment + $this->assertSame(1, $uri->getTotalSegments()); + $this->assertSame(1, $onlyURI->getTotalSegments()); + + // Get Segment + $this->assertSame('', $uri->getSegment(2)); + $this->assertSame('9', $onlyURI->getSegment(1)); + } + public function testHasMoreDefaultsToFalse() { $this->assertFalse($this->pager->hasMore('foo')); @@ -463,8 +482,8 @@ public function testBasedURI() Services::injectMock('request', $request); - $this->config = new Pager(); - $this->pager = new \CodeIgniter\Pager\Pager($this->config, Services::renderer()); + $this->config = new PagerConfig(); + $this->pager = new Pager($this->config, Services::renderer()); $_GET['page_foo'] = 2; From fd883ec6cd2602cc4d1cd7fdbc8e17c40ec130e3 Mon Sep 17 00:00:00 2001 From: ddevsr Date: Tue, 27 Sep 2022 13:52:20 +0700 Subject: [PATCH 2/5] docs: replace type pager --- tests/system/Pager/PagerTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/system/Pager/PagerTest.php b/tests/system/Pager/PagerTest.php index 6aabdff3e929..483564fb9695 100644 --- a/tests/system/Pager/PagerTest.php +++ b/tests/system/Pager/PagerTest.php @@ -182,9 +182,6 @@ public function testStoreWithSegments() public function testStoreWithURIReturnObject() { - $_GET['page'] = 5; - $_GET['id'] = 1; - $this->pager->store('bar', 5, 25, 100, 1); $uri = $this->pager->getPageURI(7, 'bar', true); From c9b01e875715329d25324769790fe79c57182033 Mon Sep 17 00:00:00 2001 From: ddevsr Date: Tue, 27 Sep 2022 15:17:08 +0700 Subject: [PATCH 3/5] tests: added test getPageURI return object in Pager --- tests/system/Pager/PagerTest.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/tests/system/Pager/PagerTest.php b/tests/system/Pager/PagerTest.php index 483564fb9695..bc4cf4403c00 100644 --- a/tests/system/Pager/PagerTest.php +++ b/tests/system/Pager/PagerTest.php @@ -184,16 +184,9 @@ public function testStoreWithURIReturnObject() { $this->pager->store('bar', 5, 25, 100, 1); - $uri = $this->pager->getPageURI(7, 'bar', true); - $onlyURI = $this->pager->only(['bar'])->getPageURI(9, 'bar', true); + $uri = $this->pager->getPageURI(7, 'bar', true); - // Total Segment - $this->assertSame(1, $uri->getTotalSegments()); - $this->assertSame(1, $onlyURI->getTotalSegments()); - - // Get Segment - $this->assertSame('', $uri->getSegment(2)); - $this->assertSame('9', $onlyURI->getSegment(1)); + $this->assertInstanceOf(URI::class, $uri); } public function testHasMoreDefaultsToFalse() From b9056a46475c5ed1b852966ee77245fed87bcf12 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Tue, 27 Sep 2022 17:04:32 +0700 Subject: [PATCH 4/5] test: rename getPageURI test Co-authored-by: kenjis --- tests/system/Pager/PagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/Pager/PagerTest.php b/tests/system/Pager/PagerTest.php index bc4cf4403c00..3a0d14e12f84 100644 --- a/tests/system/Pager/PagerTest.php +++ b/tests/system/Pager/PagerTest.php @@ -180,7 +180,7 @@ public function testStoreWithSegments() ); } - public function testStoreWithURIReturnObject() + public function testgetPageURIWithURIReturnObject() { $this->pager->store('bar', 5, 25, 100, 1); From 23be5bfa9e5b674dd6370e3a8ec9046f559eb1fa Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Tue, 27 Sep 2022 21:15:35 +0700 Subject: [PATCH 5/5] test: rename getPageURI test Co-authored-by: kenjis --- tests/system/Pager/PagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/Pager/PagerTest.php b/tests/system/Pager/PagerTest.php index 3a0d14e12f84..573911ffa7af 100644 --- a/tests/system/Pager/PagerTest.php +++ b/tests/system/Pager/PagerTest.php @@ -180,7 +180,7 @@ public function testStoreWithSegments() ); } - public function testgetPageURIWithURIReturnObject() + public function testGetPageURIWithURIReturnObject() { $this->pager->store('bar', 5, 25, 100, 1);