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

[9.x] Allow for accessing cookies via TestResponse #35611

Merged
merged 8 commits into from
Dec 15, 2020

Conversation

inxilpro
Copy link
Contributor

@inxilpro inxilpro commented Dec 14, 2020

TestResponse::getCookie() is currently protected, and is only used internally for cookie assertions. This PR exposes this method and handles the decryption of cookies.

This is particularly useful if a cookie has an unpredictable value which is needed later in your test.

Before:

$cookie = collect($response->headers->getCookies());
  ->first(function(Cookie $cookie) {
    return 'my_cookie' === $cookie->getName();
  });

$value  = CookieValuePrefix::remove(Crypt::decrypt($cookie->getValue(), false));

After:

$value = $response->getCookie('my_cookie')->getValue();

It's worth noting that TestResponse::getCookie() already exists and is used almost exactly like the "Before" use-case. This simply makes that functionality available to application tests, and adds framework tests for it.

This also adds a bunch of test cases for cookie assertions, which were missing before.

In one test I discovered a bug which I can also submit as a separate PR to 8.x. Right now assertCookieNotExpired() doesn't properly handle "session" cookies (i.e. cookies where the expiration is 0). This PR fixes that bug and adds a test for it.

@inxilpro
Copy link
Contributor Author

StyleCI is giving me a 500 error when I try to load the check. I'll check back in a bit and apply any necessary patches.

@inxilpro
Copy link
Contributor Author

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.

2 participants