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

[5.5] Create assertion to determine if a cookie is expired #21793

Merged
merged 1 commit into from
Oct 23, 2017
Merged

[5.5] Create assertion to determine if a cookie is expired #21793

merged 1 commit into from
Oct 23, 2017

Conversation

roberto-aguilar
Copy link
Contributor

@roberto-aguilar roberto-aguilar commented Oct 23, 2017

Given that the \Illuminate\Cookie\CookieJar::forget method expires the given cookie to trigger its deletion, this will allow to test those scenarios.

This new assertion will

  • Fail if the cookie is not present at all.
  • Fail if the cookie is present, but it is not expired.
  • Pass if the cookie is present and is expired.

@roberto-aguilar roberto-aguilar changed the title Create assertion to determine if a cookie is expired [5.5] Create assertion to determine if a cookie is expired Oct 23, 2017
@taylorotwell
Copy link
Member

Maybe assertCookieExpired?

Given that the `\Illuminate\Cookie\CookieJar::forget` method expires the
given cookie to trigger its deletion, this will allow to test those
scenarios.

This new assertion will

- Fail if the cookie is not present at all.
- Fail if the cookie is present, but it is not expired.
- Pass if the cookie is present and is expired.
@roberto-aguilar
Copy link
Contributor Author

It is now renamed to assertCookieExpired

@taylorotwell thanks for the feedback!

@taylorotwell taylorotwell merged commit ac7eee2 into laravel:5.5 Oct 23, 2017
@roberto-aguilar roberto-aguilar deleted the feature/expired-cookie branch October 23, 2017 22:43
@JamesAnelay
Copy link

JamesAnelay commented May 5, 2018

Might it also make sense to have an assertCookieNotExpired assertion here? I've been using assertCookieExpired to test that a certain cookie expires at a point in the future, however, if I can't assert that it's not expired beforehand it's not that useful (for me atleast).

Example use case below.

public function testCookieIsSetWhenVisitingUrlWithRefferalHashAndExpiresIn30Days()
        //Create a user with a refferalcode
        $refferedBy = factory(User::class)->create([
            'refferal_code' => 'TESTREFFERALCODE'
        ]);

        //Have a guest user visit the website with that hash in the url.
        $response = $this->get('auth/login/#TESTREFFERALCODE');
        $response->assertCookie('reffered_by', $refferedBy->user_id);

        Carbon::setTestNow(Carbon::parse('+29 days'));
        $response->assertCookieNotExpired('reffered_by'); //Doesn't exist in core laravel.

        Carbon::setTestNow(Carbon::parse('+2 days'));
	$response->assertCookieExpired('reffered_by');

@roberto-aguilar
Copy link
Contributor Author

roberto-aguilar commented May 5, 2018

@JamesAnelay

It is now created and merged, please wait for the next release for it to be available :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants