Skip to content
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

Add session state and dummy state handler tests #266

Merged
merged 6 commits into from
Jun 19, 2018

Conversation

joshcanhelp
Copy link
Contributor

No description provided.

@joshcanhelp joshcanhelp added this to the 5.2.1 milestone Jun 14, 2018
@@ -1,44 +0,0 @@
<?php
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to SessionStateHandlerTest.php and refactored above

*/
public function testStateIssuedCorrectly()
{
$this->assertNull($this->state->issue());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is a "null" state correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a dummy class so null is desired in this case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to keep this dummy class in the main library's package rather than in the test package?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes ;)

public function testStateValidatesCorrectly()
{
$this->assertTrue($this->state->validate(uniqid()));
$this->assertTrue($this->state->validate(uniqid()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated line. If is intentional leave a comment in the code

{
$uniqid = uniqid();
$this->state->store($uniqid);
$this->assertEquals($uniqid, $this->store->get(SessionStateHandler::STATE_NAME));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this one before I guess.. why if you haven't passed a state name above, you're passing one now? Either pass always the name or never.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're misreading, these are 2 different methods. I'll name for clarity.

*/
public function testStateIssuedCorrectly()
{
$state_issued = $this->state->issue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue() stores using the default name, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

}

/**
* Test that state validated properly.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"is" validated or "validates"

{
$state_issued = $this->state->issue();
$this->assertTrue($this->state->validate($state_issued));
$this->assertNull($this->store->get(SessionStateHandler::STATE_NAME));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you test that after the validate("state"), the value gets removed. Right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

$state_issued = $this->state->issue();
$this->assertTrue($this->state->validate($state_issued));
$this->assertNull($this->store->get(SessionStateHandler::STATE_NAME));
$this->assertFalse($this->state->validate($state_issued . 'false'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if this one is checking if a different state fails the validation, this one belongs to a separate test. Since on the line above you've already proved that the stored state is missing.

*/
public function testDelete()
{
self::$sessionStore->delete(self::TEST_KEY);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to me, this should first ensure a key is stored (store + check it exists) then delete and check it no longer exists

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$_SESSION persists though so tests above will cover that.

I did add an assertion for the get method here, though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests should be independent. Running whichever test alone should work. Also, if the delete() method doesn't have any logic inside it (literally an empty body) the test will still pass. You should prepare each test case / scenario before testing the actual thing.

*/
public function testGet()
{
$_SESSION[self::$sessionKey] = self::TEST_VALUE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to me, this should first ensure a key is not stored then add and check it now exists

@joshcanhelp
Copy link
Contributor Author

@lbalmaceda - Made the delete test more isolated based on your comment. Ready for review next week!

@@ -9,8 +9,6 @@ branches:

php:
- 5.5
- 5.6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we test 5.5 but not 5.6 now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cocojoe What's the point on testing each version that comes out? Isn't php retro-compatible? IMO, just test the minimum supported version and the latest supported one. Each build runs for ~8mins. Multiply that for each version and flavor you want to test and you get how much it takes for a php PR to run CI.

*/
public function testStateIssuedCorrectly()
{
$this->assertNull($this->state->issue());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes ;)

Copy link
Contributor

@lbalmaceda lbalmaceda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💎

@joshcanhelp joshcanhelp merged commit 1ad1f67 into master Jun 19, 2018
@joshcanhelp joshcanhelp deleted the add-storage-tests branch June 19, 2018 14:31
@github-actions
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants