-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[6.x] Add methods for sending cookies with test requests #30101
Conversation
61fa912
to
aceda01
Compare
aceda01
to
4542387
Compare
These tests are pretty weak and could likely be removed. They only verify internal properties. My attempts to test sending the actual cookies required mocking out parts of this internal trait which was not pretty. If there is some kind of echo or loopback test request I can make let me know and I will gladly add more tests. |
would I need to call |
protected function prepareCookiesForRequest() | ||
{ | ||
if (! $this->encryptCookies) { | ||
return $this->defaultCookies; |
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 would happen here if I needed my own cookies?
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 method only effects the code if you use these new cookie methods and one of the HTTP method helpers. As noted in the PR, if you have your own encryption/cookies, you can continue testing as you have before using call
directly.
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 makes sense, thanks for your reply.
I am still a bit lost with the implementation tho. For instance, if I can withCookies
, should I expect to send the default
ones too?.
Is it expected to remove the default?
This is my main doubt by looking at the changes.
/** | ||
* Define additional cookies to be sent with the request. | ||
* | ||
* @param array $cookies |
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.
* @param array $cookies | |
* @param array $cookies |
/** | ||
* Add a cookie to be sent with the request. | ||
* | ||
* @param string $name |
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.
* @param string $name | |
* @param string $name |
* Add a cookie to be sent with the request. | ||
* | ||
* @param string $name | ||
* @param string $value |
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.
* @param string $value | |
* @param string $value |
@jasonmccreary I fixed the build on the 6.x branch. Can you rebase? The build will pass then. |
@driesvints looks like this was merged. Yay! Let me know if you want me to make any additional changes. I'll open a patch PR. |
@jasonmccreary no worries. Build on 6.x passes |
This introduces methods for making it easier to send cookies in HTTP Tests. Previously, sending cookies restricted developers to using the low-level
call
method and required manually encrypting the cookie values (#12032).Before
After
Similar to the header methods, the following methods were added:
withCookie()
for setting a single cookie with a value.withCookies()
for setting multiple cookies with name/value pairs.disableCookieEncryption()
for disabling the automatic encryption of cookie values.Cookies are prepared before sending the HTTP request and encrypted using the
encrypter
.This implementation implies a few design decisions:
call
method does not honor cookies set by these new methods. In a future version, all logic could be moved to thecall
method and merge its$cookie
argument with cookies set by these methods.EncryptCookies
middleware is only enabled forweb
requests by default, thejson*
HTTP methods do not honor cookies set by these new methods. This could be amended by passing the unencrypted cookie values in these methods.enableCookieSerialize
method or leveraging the static property ofEncryptCookies
.In the end, these methods improve the out-of-the-box developer experience by making it easier to test requests using cookies. For more complex scenarios, developers can continue using
call
as they have been all along.