3
3
namespace Tests ;
4
4
5
5
use 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 ;
6
10
use Stackkit \LaravelDatabaseEmails \Email ;
7
11
8
12
class MailableReaderTest extends TestCase
9
13
{
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
+
10
23
/** @test */
11
24
public function it_extracts_the_recipient ()
12
25
{
13
26
$ composer = Email::compose ()
14
- ->mailable (new TestMailable ());
27
+ ->mailable ($ this -> mailable ());
15
28
16
29
$ this ->
assertEquals ([
'[email protected] ' ],
$ composer->
getData (
'recipient ' ));
17
30
18
31
$ composer = Email::compose ()
19
32
->mailable (
20
- ( new TestMailable () )->
to ([
'[email protected] ' ])
33
+ $ this -> mailable ( )->
to ([
'[email protected] ' ])
21
34
);
22
35
23
36
$ this ->assertCount (2 , $ composer ->getData ('recipient ' ));
@@ -28,39 +41,39 @@ public function it_extracts_the_recipient()
28
41
/** @test */
29
42
public function it_extracts_cc_addresses ()
30
43
{
31
- $ composer = Email::compose ()->mailable (new TestMailable ());
44
+ $ composer = Email::compose ()->mailable ($ this -> mailable ());
32
45
33
46
$ this ->
assertEquals ([
'[email protected] ' ,
'[email protected] ' ],
$ composer->
getData (
'cc ' ));
34
47
}
35
48
36
49
/** @test */
37
50
public function it_extracts_bcc_addresses ()
38
51
{
39
- $ composer = Email::compose ()->mailable (new TestMailable ());
52
+ $ composer = Email::compose ()->mailable ($ this -> mailable ());
40
53
41
54
$ this ->
assertEquals ([
'[email protected] ' ,
'[email protected] ' ],
$ composer->
getData (
'bcc ' ));
42
55
}
43
56
44
57
/** @test */
45
58
public function it_extracts_the_subject ()
46
59
{
47
- $ composer = Email::compose ()->mailable (new TestMailable ());
60
+ $ composer = Email::compose ()->mailable ($ this -> mailable ());
48
61
49
62
$ this ->assertEquals ('Your order has shipped! ' , $ composer ->getData ('subject ' ));
50
63
}
51
64
52
65
/** @test */
53
66
public function it_extracts_the_body ()
54
67
{
55
- $ composer = Email::compose ()->mailable (new TestMailable ());
68
+ $ composer = Email::compose ()->mailable ($ this -> mailable ());
56
69
57
70
$ this ->assertEquals ("Name: John Doe \n" , $ composer ->getData ('body ' ));
58
71
}
59
72
60
73
/** @test */
61
74
public function it_extracts_attachments ()
62
75
{
63
- $ email = Email::compose ()->mailable (new TestMailable ())->send ();
76
+ $ email = Email::compose ()->mailable ($ this -> mailable ())->send ();
64
77
65
78
$ attachments = $ email ->getAttachments ();
66
79
@@ -78,7 +91,7 @@ public function it_extracts_attachments()
78
91
public function it_extracts_the_from_address_and_or_name ()
79
92
{
80
93
$ email = Email::compose ()->mailable (
81
- (new TestMailable ())
94
+ ($ this -> mailable ())
82
95
->
from (
'[email protected] ' ,
'Marick ' )
83
96
)->send ();
84
97
@@ -87,7 +100,7 @@ public function it_extracts_the_from_address_and_or_name()
87
100
$ this ->assertEquals ('Marick ' , $ email ->getFromName ());
88
101
89
102
$ email = Email::compose ()->mailable (
90
- (new TestMailable ())
103
+ ($ this -> mailable ())
91
104
92
105
)->send ();
93
106
@@ -96,7 +109,7 @@ public function it_extracts_the_from_address_and_or_name()
96
109
$ this ->assertEquals (config ('mail.from.name ' ), $ email ->getFromName ());
97
110
98
111
$ email = Email::compose ()->mailable (
99
- (new TestMailable ())
112
+ ($ this -> mailable ())
100
113
->from (null , 'Marick ' )
101
114
)->send ();
102
115
@@ -132,3 +145,41 @@ public function build()
132
145
->view ('tests::dummy ' , ['name ' => 'John Doe ' ]);
133
146
}
134
147
}
148
+
149
+ class Laravel10TestMailable extends Mailable
150
+ {
151
+ public function content (): Content
152
+ {
153
+ $ content = new Content (
154
+ 'tests::dummy '
155
+ );
156
+
157
+ $ content ->with ('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 (
'[email protected] ' ,
'John Doe ' )
168
+ ],
169
+
170
+
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