33namespace  Tests ;
44
55use  Illuminate \Mail \Mailable ;
6+ use  Illuminate \Mail \Mailables \Address ;
7+ use  Illuminate \Mail \Mailables \Attachment ;
8+ use  Illuminate \Mail \Mailables \Content ;
9+ use  Illuminate \Mail \Mailables \Envelope ;
610use  Stackkit \LaravelDatabaseEmails \Email ;
711
812class  MailableReaderTest extends  TestCase
913{
14+     private  function  mailable (): Mailable 
15+     {
16+         if  (version_compare (app ()->version (), '10.0.0 ' , '>= ' )) {
17+             return  new  Laravel10TestMailable ();
18+         }
19+ 
20+         return  new  TestMailable ();
21+     }
22+ 
1023    /** @test */ 
1124    public  function  it_extracts_the_recipient ()
1225    {
1326        $ composercompose ()
14-             ->mailable (new   TestMailable ());
27+             ->mailable ($ this -> mailable ());
1528
1629        $ this assertEquals (['john@doe.com ' ], $ composergetData ('recipient ' ));
1730
1831        $ composercompose ()
1932            ->mailable (
20-                 ( new   TestMailable () )->to (['jane@doe.com ' ])
33+                 $ this -> mailable ( )->to (['jane@doe.com ' ])
2134            );
2235
2336        $ this assertCount (2 , $ composergetData ('recipient ' ));
@@ -28,39 +41,39 @@ public function it_extracts_the_recipient()
2841    /** @test */ 
2942    public  function  it_extracts_cc_addresses ()
3043    {
31-         $ composercompose ()->mailable (new   TestMailable ());
44+         $ composercompose ()->mailable ($ this -> mailable ());
3245
3346        $ this assertEquals (['john+cc@doe.com ' , 'john+cc2@doe.com ' ], $ composergetData ('cc ' ));
3447    }
3548
3649    /** @test */ 
3750    public  function  it_extracts_bcc_addresses ()
3851    {
39-         $ composercompose ()->mailable (new   TestMailable ());
52+         $ composercompose ()->mailable ($ this -> mailable ());
4053
4154        $ this assertEquals (['john+bcc@doe.com ' , 'john+bcc2@doe.com ' ], $ composergetData ('bcc ' ));
4255    }
4356
4457    /** @test */ 
4558    public  function  it_extracts_the_subject ()
4659    {
47-         $ composercompose ()->mailable (new   TestMailable ());
60+         $ composercompose ()->mailable ($ this -> mailable ());
4861
4962        $ this assertEquals ('Your order has shipped! ' , $ composergetData ('subject ' ));
5063    }
5164
5265    /** @test */ 
5366    public  function  it_extracts_the_body ()
5467    {
55-         $ composercompose ()->mailable (new   TestMailable ());
68+         $ composercompose ()->mailable ($ this -> mailable ());
5669
5770        $ this assertEquals ("Name: John Doe \n" , $ composergetData ('body ' ));
5871    }
5972
6073    /** @test */ 
6174    public  function  it_extracts_attachments ()
6275    {
63-         $ emailcompose ()->mailable (new   TestMailable ())->send ();
76+         $ emailcompose ()->mailable ($ this -> mailable ())->send ();
6477
6578        $ attachments$ emailgetAttachments ();
6679
@@ -78,7 +91,7 @@ public function it_extracts_attachments()
7891    public  function  it_extracts_the_from_address_and_or_name ()
7992    {
8093        $ emailcompose ()->mailable (
81-             (new   TestMailable ())
94+             ($ this -> mailable ())
8295                ->from ('marick@dolphiq.nl ' , 'Marick ' )
8396        )->send ();
8497
@@ -87,7 +100,7 @@ public function it_extracts_the_from_address_and_or_name()
87100        $ this assertEquals ('Marick ' , $ emailgetFromName ());
88101
89102        $ emailcompose ()->mailable (
90-             (new   TestMailable ())
103+             ($ this -> mailable ())
91104                ->from ('marick@dolphiq.nl ' )
92105        )->send ();
93106
@@ -96,7 +109,7 @@ public function it_extracts_the_from_address_and_or_name()
96109        $ this assertEquals (config ('mail.from.name ' ), $ emailgetFromName ());
97110
98111        $ emailcompose ()->mailable (
99-             (new   TestMailable ())
112+             ($ this -> mailable ())
100113                ->from (null , 'Marick ' )
101114        )->send ();
102115
@@ -132,3 +145,41 @@ public function build()
132145            ->view ('tests::dummy ' , ['name '  => 'John Doe ' ]);
133146    }
134147}
148+ 
149+ class  Laravel10TestMailable extends  Mailable
150+ {
151+     public  function  content (): Content 
152+     {
153+         $ contentnew  Content (
154+             'tests::dummy ' 
155+         );
156+ 
157+         $ contentwith ('name ' , 'John Doe ' );
158+ 
159+         return  $ content
160+     }
161+ 
162+     public  function  envelope (): Envelope 
163+     {
164+         return  new  Envelope (
165+             null ,
166+             [
167+                 new  Address ('john@doe.com ' , 'John Doe ' )
168+             ],
169+             ['john+cc@doe.com ' , 'john+cc2@doe.com ' ],
170+             ['john+bcc@doe.com ' , 'john+bcc2@doe.com ' ],
171+             [],
172+             'Your order has shipped! ' 
173+         );
174+     }
175+ 
176+     public  function  attachments (): array 
177+     {
178+         return  [
179+             Attachment::fromPath (__DIR__  . '/files/pdf-sample.pdf ' )->withMime ('application/pdf ' ),
180+             Attachment::fromData (function  () {
181+                 return  '<p>Thanks for your oder</p> ' ;
182+             }, 'order.html ' )
183+         ];
184+     }
185+ }
0 commit comments