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
[HttpFoundation] Constraint ResponseHeaderSame now shows the actual header value #49227
base: 7.1
Are you sure you want to change the base?
[HttpFoundation] Constraint ResponseHeaderSame now shows the actual header value #49227
Conversation
621b10e
to
2cab626
Compare
I like this! A quick question: what happens if the header doesn't exist? Should we expect a message error like this?
|
Hi @javiereguiluz, I guess most people check for header existence before they assert the header value, but I think it makes sense to add the |
2cab626
to
29ae98d
Compare
29ae98d
to
39bfb97
Compare
39bfb97
to
b421a7f
Compare
b421a7f
to
90e11a4
Compare
|
||
public function __construct(string $headerName, string $expectedValue) | ||
public function __construct(string $headerName, string $expectedValue, bool $logicalNot = false) |
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 is this needed?
Let me try to explain:
The test case for the assertResponseHeaderNotSame
public function testAssertResponseHeaderNotSame()
{
$this->getResponseTester(new Response())->assertResponseHeaderNotSame('Cache-Control', 'public');
$this->expectException(AssertionFailedError::class);
$this->expectExceptionMessage('Failed asserting that the Response does not have header "Cache-Control" with value "no-cache, private", value of header "Cache-Control" is "no-cache, private".');
$this->getResponseTester(new Response())->assertResponseHeaderNotSame('Cache-Control', 'no-cache, private');
}
failed with:
Failed asserting that exception message
'Failed asserting that the Response does not have header "Cache-Control" with value "no-cache, private", value of header "Cache-Control" is not "no-cache, private".'
contains
'Failed asserting that the Response does not have header "Cache-Control" with value "no-cache, private", value of header "Cache-Control" is "no-cache, private".'.
- Please notice the not in the actual exception message.
This is happening because the assertResponseHeaderNotSame
assertion uses a ResponseHeaderSame
constraint internally. This constraint is wrapped by a LogicalNot
which is in fact the reason all messages for this constraint are negated.
So the best idea I had so far is to "ignore" the logical not case.
90e11a4
to
8854686
Compare
I am using the
BrowserKitAssertionsTrait::assertResponseHeaderSame(...)
quite a lot in my functional tests and it would be nice to see the actual header value in case the expected one doesn't match. So instead of just seeing:it would be helpful to see: