@@ -103,21 +103,29 @@ public function testEncoding()
103103 public function testCustomEncoderNeedsToRegisterFirst ()
104104 {
105105 $ this ->expectException (InvalidArgumentException::class);
106- $ this ->expectExceptionMessage ('The encoding must be one of "quoted-printable", "base64", "8bit", "exception_test" ("upper_encoder" given). ' );
107- TextPart::addEncoder ('exception_test ' , $ this ->createMock (ContentEncoderInterface::class));
108- new TextPart ('content ' , 'utf-8 ' , 'plain ' , 'upper_encoder ' );
106+ $ this ->expectExceptionMessage ('The encoding must be one of "quoted-printable", "base64", "8bit", "upper_encoder" ("this_encoding_does_not_exist" given). ' );
107+
108+ $ upperEncoder = $ this ->createMock (ContentEncoderInterface::class);
109+ $ upperEncoder ->method ('getName ' )->willReturn ('upper_encoder ' );
110+
111+ TextPart::addEncoder ($ upperEncoder );
112+ new TextPart ('content ' , 'utf-8 ' , 'plain ' , 'this_encoding_does_not_exist ' );
109113 }
110114
111115 public function testOverwriteDefaultEncoder ()
112116 {
113117 $ this ->expectException (InvalidArgumentException::class);
114118 $ this ->expectExceptionMessage ('You are not allowed to change the default encoders ("quoted-printable", "base64", and "8bit"). ' );
115- TextPart::addEncoder ('8bit ' , $ this ->createMock (ContentEncoderInterface::class));
119+
120+ $ base64Encoder = $ this ->createMock (ContentEncoderInterface::class);
121+ $ base64Encoder ->method ('getName ' )->willReturn ('base64 ' );
122+
123+ TextPart::addEncoder ($ base64Encoder );
116124 }
117125
118126 public function testCustomEncoding ()
119127 {
120- TextPart::addEncoder (' upper_encoder ' , new class implements ContentEncoderInterface {
128+ TextPart::addEncoder (new class implements ContentEncoderInterface {
121129 public function encodeByteStream ($ stream , int $ maxLineLength = 0 ): iterable
122130 {
123131 $ filter = stream_filter_append ($ stream , 'string.toupper ' , \STREAM_FILTER_READ );
0 commit comments