Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit6a93d11

Browse files
bug#46366 [Mime] Add null check for EmailHeaderSame (magikid)
This PR was squashed before being merged into the 4.4 branch.Discussion----------[Mime] Add null check for EmailHeaderSameWhen asserting that an email header matches some text and the headerdoes not exist on the message, an `Error` was being thrown because themethod `getBodyAsString()` was being called on a `null` object. Thiscommit allows a missing header and will show the user that the header'svalue is `null`.Issue#44190| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | yes| New feature? | no <!-- please update src/**/CHANGELOG.md files -->| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tickets |Fix#44190 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->| License | MIT<!--Replace this notice by a short README for your feature/bugfix.This will help reviewers and should be a good start for the documentation.Additionally (seehttps://symfony.com/releases): - Always add tests and ensure they pass. - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against the latest branch. - Changelog entry should followhttps://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (seehttps://symfony.com/bc).-->Commits-------a6ec675 [Mime] Add null check for EmailHeaderSame
2 parentsbb6d26a +a6ec675 commit6a93d11

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

‎src/Symfony/Component/Mime/Test/Constraint/EmailHeaderSame.php‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ protected function matches($message): bool
5555
*/
5656
protectedfunctionfailureDescription($message):string
5757
{
58-
returnsprintf('the Email %s (value is %s)',$this->toString(),$this->getHeaderValue($message));
58+
returnsprintf('the Email %s (value is %s)',$this->toString(),$this->getHeaderValue($message) ??'null');
5959
}
6060

61-
privatefunctiongetHeaderValue($message):string
61+
privatefunctiongetHeaderValue($message):?string
6262
{
63-
$header =$message->getHeaders()->get($this->headerName);
63+
if (null ===$header =$message->getHeaders()->get($this->headerName)) {
64+
returnnull;
65+
}
6466

6567
return$headerinstanceof UnstructuredHeader ?$header->getValue() :$header->getBodyAsString();
6668
}

‎src/Symfony/Component/Mime/Tests/EmailTest.php‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespaceSymfony\Component\Mime\Tests;
1313

14+
usePHPUnit\Framework\ExpectationFailedException;
1415
usePHPUnit\Framework\TestCase;
1516
useSymfony\Component\Mime\Address;
1617
useSymfony\Component\Mime\Email;
@@ -19,6 +20,7 @@
1920
useSymfony\Component\Mime\Part\Multipart\MixedPart;
2021
useSymfony\Component\Mime\Part\Multipart\RelatedPart;
2122
useSymfony\Component\Mime\Part\TextPart;
23+
useSymfony\Component\Mime\Test\Constraint\EmailHeaderSame;
2224

2325
class EmailTestextends TestCase
2426
{
@@ -384,4 +386,14 @@ public function testSerialize()
384386
$this->assertEquals($expected->getHeaders(),$n->getHeaders());
385387
$this->assertEquals($e->getBody(),$n->getBody());
386388
}
389+
390+
publicfunctiontestMissingHeaderDoesNotThrowError()
391+
{
392+
$this->expectException(ExpectationFailedException::class);
393+
$this->expectExceptionMessage('Failed asserting that the Email has header "foo" with value "bar" (value is null).');
394+
395+
$e =newEmail();
396+
$emailHeaderSame =newEmailHeaderSame('foo','bar');
397+
$emailHeaderSame->evaluate($e);
398+
}
387399
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp