Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpFoundation] Constraint ResponseHeaderSame now shows the actual header value #49227

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

Open
wants to merge 2 commits into
base: 7.4
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
try to work around the LogicalNot(ResponseHeaderSame) behaviour
  • Loading branch information
jschaedl committed Nov 29, 2023
commit 81ecde59aa2eb634bd781bf2248e385fa7a2f5f7
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static function assertResponseHeaderSame(string $headerName, string $expe

public static function assertResponseHeaderNotSame(string $headerName, string $expectedValue, string $message = ''): void
{
self::assertThatForResponse(new LogicalNot(new ResponseConstraint\ResponseHeaderSame($headerName, $expectedValue)), $message);
self::assertThatForResponse(new LogicalNot(new ResponseConstraint\ResponseHeaderSame($headerName, $expectedValue, true)), $message);
}

public static function assertResponseHasCookie(string $name, string $path = '/', string $domain = null, string $message = ''): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ final class ResponseHeaderSame extends Constraint
{
private string $headerName;
private string $expectedValue;
private bool $logicalNot;
private ?string $actualValue = null;

public function __construct(string $headerName, string $expectedValue)
public function __construct(string $headerName, string $expectedValue, bool $logicalNot = false)
Copy link
Contributor Author

@jschaedl jschaedl Nov 26, 2023

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.

{
$this->headerName = $headerName;
$this->expectedValue = $expectedValue;
$this->logicalNot = $logicalNot;
}

public function toString(): string
Expand All @@ -34,7 +36,7 @@ public function toString(): string
$output .= sprintf(', header "%s" is not set', $this->headerName);
}

if (null !== $this->actualValue) {
if (null !== $this->actualValue && !$this->logicalNot) {
$output .= sprintf(', value of header "%s" is "%s"', $this->headerName, $this->actualValue);
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.