File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
src/Symfony/Component/Mime Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -55,12 +55,14 @@ protected function matches($message): bool
55
55
*/
56
56
protected function failureDescription ($ message ): string
57
57
{
58
- return sprintf ('the Email %s (value is %s) ' , $ this ->toString (), $ this ->getHeaderValue ($ message ));
58
+ return sprintf ('the Email %s (value is %s) ' , $ this ->toString (), $ this ->getHeaderValue ($ message ) ?? ' null ' );
59
59
}
60
60
61
- private function getHeaderValue ($ message ): string
61
+ private function getHeaderValue ($ message ): ? string
62
62
{
63
- $ header = $ message ->getHeaders ()->get ($ this ->headerName );
63
+ if (null === $ header = $ message ->getHeaders ()->get ($ this ->headerName )) {
64
+ return null ;
65
+ }
64
66
65
67
return $ header instanceof UnstructuredHeader ? $ header ->getValue () : $ header ->getBodyAsString ();
66
68
}
Original file line number Diff line number Diff line change 11
11
12
12
namespace Symfony \Component \Mime \Tests ;
13
13
14
+ use PHPUnit \Framework \ExpectationFailedException ;
14
15
use PHPUnit \Framework \TestCase ;
15
16
use Symfony \Component \Mime \Address ;
16
17
use Symfony \Component \Mime \Email ;
19
20
use Symfony \Component \Mime \Part \Multipart \MixedPart ;
20
21
use Symfony \Component \Mime \Part \Multipart \RelatedPart ;
21
22
use Symfony \Component \Mime \Part \TextPart ;
23
+ use Symfony \Component \Mime \Test \Constraint \EmailHeaderSame ;
22
24
23
25
class EmailTest extends TestCase
24
26
{
@@ -384,4 +386,14 @@ public function testSerialize()
384
386
$ this ->assertEquals ($ expected ->getHeaders (), $ n ->getHeaders ());
385
387
$ this ->assertEquals ($ e ->getBody (), $ n ->getBody ());
386
388
}
389
+
390
+ public function testMissingHeaderDoesNotThrowError ()
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 = new Email ();
396
+ $ emailHeaderSame = new EmailHeaderSame ('foo ' , 'bar ' );
397
+ $ emailHeaderSame ->evaluate ($ e );
398
+ }
387
399
}
You can’t perform that action at this time.
0 commit comments