-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: replace type in Pager
#6596
Conversation
tests/system/Pager/PagerTest.php
Outdated
@@ -182,6 +182,22 @@ public function testStoreWithSegments() | |||
); | |||
} | |||
|
|||
public function testStoreWithURIReturnObject() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this test testing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For covered testing if $returnObject = true
$this->pager->store('bar', 5, 25, 100, 1);
$uri = $this->pager->getPageURI(7, 'bar', true);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you assert that $uri
is instance of URI
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I call getTotalSegments
and getSegment
because part of the function URI class. Its okay if only assert instance of URI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please try to write a test that is as clear as possible what you are trying to test.
And if you want to test two aspects, you can add two test methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this?
--- a/tests/system/Pager/PagerTest.php
+++ b/tests/system/Pager/PagerTest.php
@@ -184,11 +184,28 @@ final class PagerTest extends CIUnitTestCase
public function testGetPageURIWithURIReturnObject()
{
- $this->pager->store('bar', 5, 25, 100, 1);
+ $_GET['page'] = 3;
+ $_GET['foo'] = 'bar';
+
+ $this->pager->store('default', 3, 25, 100, 1);
- $uri = $this->pager->getPageURI(7, 'bar', true);
+ $uri = $this->pager->getPageURI(5, 'default', true);
$this->assertInstanceOf(URI::class, $uri);
+ $this->assertSame(
+ 'page=3&foo=bar',
+ $uri->getQuery()
+ );
+
+ $this->pager->store('new', 3, 25, 100, 1);
+
+ $uriOnly = $this->pager->only(['foo'])->getPageURI(7, 'new', true);
+
+ $this->assertInstanceOf(URI::class, $uriOnly);
+ $this->assertSame(
+ 'foo=bar',
+ $uriOnly->getQuery()
+ );
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better than the first test.
But there are many test aspects:
- return URI object
- query parameters in URI object
- only() method
It is better to write one test for one aspect.
If the test method is testGetPageURIWithURIReturnObject
, the current test is enough.
If you want to write a test for only() or query parameters, please add another test method.
Or is there any test already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getPageURI
only 2 aspect, with only
or without only
. And this topic coverage getPageURI
return URI
object
public function testGetPageURIWithURIReturnObject()
{
$_GET['page'] = 3;
$_GET['foo'] = 'bar';
$this->pager->store('default', 5, 25, 100, 1);
$uri = $this->pager->getPageURI(5, 'default', true);
$this->assertInstanceOf(URI::class, $uri);
$this->assertSame(
'page=3&foo=bar',
$uri->getQuery()
);
}
public function testOnlyGetPageURIWithURIReturnObject()
{
$_GET['page'] = 3;
$_GET['foo'] = 'bar';
$this->pager->store('default', 5, 25, 100, 1);
$uriOnly = $this->pager->only(['foo'])->getPageURI(5, 'default', true);
$this->assertInstanceOf(URI::class, $uriOnly);
$this->assertSame(
'foo=bar',
$uriOnly->getQuery()
);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$this->pager->store('default', 5, 25, 100, 1);
The last parameter means the first URI segment is the page number.
$_GET['page'] = 3;
means it is a query string that is not the page number, but the name is page
accidentally.
I think these tests are testing too tricky situations.
If you want to test only()
or query string, I think it is better to use the cases with the page number query string ,
not using URI segment.
@ddevsr It seems you did |
Co-authored-by: kenjis <[email protected]>
Co-authored-by: kenjis <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kenjis has gone through this thoroughly so I just checked out the end result. Very nice QA, thank you!
Description
See #6310
Checklist: