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

[Mime] EmailHeaderSame doesn't check for header nullability #44190

Copy link
Copy link
Closed
@garak

Description

@garak
Issue body actions

Symfony version(s) affected

4.4

Description

in class Symfony\Component\Mime\Test\Constraint\EmailHeaderSame there is this method:

private function getHeaderValue($message): string
    {
        $header = $message->getHeaders()->get($this->headerName);

        return $header instanceof UnstructuredHeader ? $header->getValue() : $header->getBodyAsString();
    }

in the last line, the value of $header is only checked on UnstructuredHeader class. It should be checked at least for not being null (but I guess indeed it should be checked for any class containing the getBodyAsString method)

How to reproduce

Make a test where you check an e-mail header, for example:

public function testEmailIsSentWithHeader(): void
{
    // do something where your email is sent...
    // [...]
    self::assertEmailCount(1);
    $email = self::getMailerMessage();
    self::assertNotNull($email);
    self::assertEmailHeaderSame($email, 'Content-Type', 'X-foo');
}

in the last line you get

Error: Call to a member function getBodyAsString() on null
/prj/vendor/symfony/mime/Test/Constraint/EmailHeaderSame.php:67
/prj/vendor/symfony/mime/Test/Constraint/EmailHeaderSame.php:48
/prj/vendor/symfony/framework-bundle/Test/MailerAssertionsTrait.php:80
/prj/tests/MyTest.php:42

Possible Solution

Check for type of $header variable (see above)

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

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