@@ -39,6 +39,9 @@ public function output_writes_nothing_for_empty_tree()
3939 $ this ->filesystem ->expects ('stub ' )
4040 ->with ('mail.stub ' )
4141 ->andReturn ($ this ->stub ('mail.stub ' ));
42+ $ this ->filesystem ->expects ('stub ' )
43+ ->with ('mail.view.stub ' )
44+ ->andReturn ($ this ->stub ('mail.view.stub ' ));
4245
4346 $ this ->filesystem ->shouldNotHaveReceived ('put ' );
4447
@@ -53,6 +56,9 @@ public function output_writes_nothing_tree_without_validate_statements()
5356 $ this ->filesystem ->expects ('stub ' )
5457 ->with ('mail.stub ' )
5558 ->andReturn ($ this ->stub ('mail.stub ' ));
59+ $ this ->filesystem ->expects ('stub ' )
60+ ->with ('mail.view.stub ' )
61+ ->andReturn ($ this ->stub ('mail.view.stub ' ));
5662
5763 $ this ->filesystem ->shouldNotHaveReceived ('put ' );
5864
@@ -70,30 +76,57 @@ public function output_writes_mails()
7076 $ this ->filesystem ->expects ('stub ' )
7177 ->with ('mail.stub ' )
7278 ->andReturn ($ this ->stub ('mail.stub ' ));
79+ $ this ->filesystem ->expects ('stub ' )
80+ ->with ('mail.view.stub ' )
81+ ->andReturn ($ this ->stub ('mail.view.stub ' ));
7382 $ this ->filesystem ->shouldReceive ('stub ' )
7483 ->with ('constructor.stub ' )
7584 ->andReturn ($ this ->stub ('constructor.stub ' ));
76- $ this ->filesystem ->shouldReceive ('exists ' )
85+ $ this ->filesystem ->expects ('exists ' )
7786 ->twice ()
7887 ->with ('app/Mail ' )
7988 ->andReturns (false , true );
89+ $ this ->filesystem ->expects ('exists ' )
90+ ->twice ()
91+ ->with ('resources/views/emails ' )
92+ ->andReturns (false , true );
8093 $ this ->filesystem ->expects ('exists ' )
8194 ->with ('app/Mail/ReviewPost.php ' )
8295 ->andReturnFalse ();
8396 $ this ->filesystem ->expects ('makeDirectory ' )
8497 ->with ('app/Mail ' , 0755 , true );
8598 $ this ->filesystem ->expects ('put ' )
8699 ->with ('app/Mail/ReviewPost.php ' , $ this ->fixture ('mailables/review-post.php ' ));
100+ $ this ->filesystem ->expects ('exists ' )
101+ ->with ('resources/views/emails/review-post.blade.php ' )
102+ ->andReturnFalse ();
103+ $ this ->filesystem ->expects ('makeDirectory ' )
104+ ->with ('resources/views/emails ' , 0755 , true );
105+ $ this ->filesystem ->expects ('put ' )
106+ ->with ('resources/views/emails/review-post.blade.php ' , $ this ->fixture ('mailables/review-post-view.blade.php ' ));
107+
87108 $ this ->filesystem ->expects ('exists ' )
88109 ->with ('app/Mail/PublishedPost.php ' )
89110 ->andReturnFalse ();
90111 $ this ->filesystem ->expects ('put ' )
91112 ->with ('app/Mail/PublishedPost.php ' , $ this ->fixture ('mailables/published-post.php ' ));
113+ $ this ->filesystem ->expects ('exists ' )
114+ ->with ('resources/views/emails/published-post.blade.php ' )
115+ ->andReturnFalse ();
116+ $ this ->filesystem ->expects ('put ' )
117+ ->with ('resources/views/emails/published-post.blade.php ' , $ this ->fixture ('mailables/published-post-view.blade.php ' ));
92118
93119 $ tokens = $ this ->blueprint ->parse ($ this ->fixture ('drafts/send-statements.yaml ' ));
94120 $ tree = $ this ->blueprint ->analyze ($ tokens );
95121
96- $ this ->assertEquals (['created ' => ['app/Mail/ReviewPost.php ' , 'app/Mail/PublishedPost.php ' ]], $ this ->subject ->output ($ tree ));
122+ $ this ->assertEquals ([
123+ 'created ' => [
124+ 'app/Mail/ReviewPost.php ' ,
125+ 'resources/views/emails/review-post.blade.php ' ,
126+ 'app/Mail/PublishedPost.php ' ,
127+ 'resources/views/emails/published-post.blade.php ' ,
128+ ],
129+ ], $ this ->subject ->output ($ tree ));
97130 }
98131
99132 /**
@@ -104,6 +137,9 @@ public function it_only_outputs_new_mails()
104137 $ this ->filesystem ->expects ('stub ' )
105138 ->with ('mail.stub ' )
106139 ->andReturn ($ this ->stub ('mail.stub ' ));
140+ $ this ->filesystem ->expects ('stub ' )
141+ ->with ('mail.view.stub ' )
142+ ->andReturn ($ this ->stub ('mail.view.stub ' ));
107143 $ this ->filesystem ->expects ('exists ' )
108144 ->with ('app/Mail/ReviewPost.php ' )
109145 ->andReturnTrue ();
@@ -128,6 +164,9 @@ public function it_respects_configuration()
128164 $ this ->filesystem ->expects ('stub ' )
129165 ->with ('mail.stub ' )
130166 ->andReturn ($ this ->stub ('mail.stub ' ));
167+ $ this ->filesystem ->expects ('stub ' )
168+ ->with ('mail.view.stub ' )
169+ ->andReturn ($ this ->stub ('mail.view.stub ' ));
131170 $ this ->filesystem ->expects ('stub ' )
132171 ->with ('constructor.stub ' )
133172 ->andReturn ($ this ->stub ('constructor.stub ' ));
@@ -141,11 +180,23 @@ public function it_respects_configuration()
141180 ->with ('src/path/Mail ' , 0755 , true );
142181 $ this ->filesystem ->expects ('put ' )
143182 ->with ('src/path/Mail/ReviewPost.php ' , $ this ->fixture ('mailables/mail-configured.php ' ));
183+ $ this ->filesystem ->expects ('exists ' )
184+ ->with ('resources/views/emails/review-post.blade.php ' )
185+ ->andReturnFalse ();
186+ $ this ->filesystem ->expects ('makeDirectory ' )
187+ ->with ('resources/views/emails ' , 0755 , true );
188+ $ this ->filesystem ->expects ('put ' )
189+ ->with ('resources/views/emails/review-post.blade.php ' , $ this ->fixture ('mailables/review-post-view.blade.php ' ));
144190
145191 $ tokens = $ this ->blueprint ->parse ($ this ->fixture ('drafts/readme-example.yaml ' ));
146192 $ tree = $ this ->blueprint ->analyze ($ tokens );
147193
148- $ this ->assertEquals (['created ' => ['src/path/Mail/ReviewPost.php ' ]], $ this ->subject ->output ($ tree ));
194+ $ this ->assertEquals ([
195+ 'created ' => [
196+ 'src/path/Mail/ReviewPost.php ' ,
197+ 'resources/views/emails/review-post.blade.php ' ,
198+ ],
199+ ], $ this ->subject ->output ($ tree ));
149200 }
150201
151202 /**
@@ -160,6 +211,9 @@ public function output_using_return_types()
160211 $ this ->filesystem ->expects ('stub ' )
161212 ->with ('mail.stub ' )
162213 ->andReturn ($ this ->stub ('mail.stub ' ));
214+ $ this ->filesystem ->expects ('stub ' )
215+ ->with ('mail.view.stub ' )
216+ ->andReturn ($ this ->stub ('mail.view.stub ' ));
163217 $ this ->filesystem ->expects ('stub ' )
164218 ->with ('constructor.stub ' )
165219 ->andReturn ($ this ->stub ('constructor.stub ' ));
@@ -173,10 +227,113 @@ public function output_using_return_types()
173227 ->with ('src/path/Mail ' , 0755 , true );
174228 $ this ->filesystem ->expects ('put ' )
175229 ->with ('src/path/Mail/ReviewPost.php ' , $ this ->fixture ('mailables/return-type-declarations.php ' ));
230+ $ this ->filesystem ->expects ('exists ' )
231+ ->with ('resources/views/emails/review-post.blade.php ' )
232+ ->andReturnFalse ();
233+ $ this ->filesystem ->expects ('makeDirectory ' )
234+ ->with ('resources/views/emails ' , 0755 , true );
235+ $ this ->filesystem ->expects ('put ' )
236+ ->with ('resources/views/emails/review-post.blade.php ' , $ this ->fixture ('mailables/review-post-view.blade.php ' ));
176237
177238 $ tokens = $ this ->blueprint ->parse ($ this ->fixture ('drafts/readme-example.yaml ' ));
178239 $ tree = $ this ->blueprint ->analyze ($ tokens );
179240
180- $ this ->assertEquals (['created ' => ['src/path/Mail/ReviewPost.php ' ]], $ this ->subject ->output ($ tree ));
241+ $ this ->assertEquals ([
242+ 'created ' => [
243+ 'src/path/Mail/ReviewPost.php ' ,
244+ 'resources/views/emails/review-post.blade.php ' ,
245+ ],
246+ ], $ this ->subject ->output ($ tree ));
247+ }
248+
249+ /**
250+ * @test
251+ */
252+ public function output_writes_mails_but_not_existing_templates ()
253+ {
254+ $ this ->filesystem ->expects ('stub ' )
255+ ->with ('mail.stub ' )
256+ ->andReturn ($ this ->stub ('mail.stub ' ));
257+ $ this ->filesystem ->expects ('stub ' )
258+ ->with ('mail.view.stub ' )
259+ ->andReturn ($ this ->stub ('mail.view.stub ' ));
260+ $ this ->filesystem ->shouldReceive ('stub ' )
261+ ->with ('constructor.stub ' )
262+ ->andReturn ($ this ->stub ('constructor.stub ' ));
263+ $ this ->filesystem ->expects ('exists ' )
264+ ->twice ()
265+ ->with ('app/Mail ' )
266+ ->andReturns (false );
267+ $ this ->filesystem ->expects ('exists ' )
268+ ->with ('app/Mail/ReviewPost.php ' )
269+ ->andReturnFalse ();
270+ $ this ->filesystem ->expects ('put ' )
271+ ->with ('app/Mail/ReviewPost.php ' , $ this ->fixture ('mailables/review-post.php ' ));
272+ $ this ->filesystem ->expects ('exists ' )
273+ ->with ('resources/views/emails/review-post.blade.php ' )
274+ ->andReturnTrue ();
275+
276+ $ this ->filesystem ->expects ('exists ' )
277+ ->with ('app/Mail/PublishedPost.php ' )
278+ ->andReturnFalse ();
279+ $ this ->filesystem ->expects ('put ' )
280+ ->with ('app/Mail/PublishedPost.php ' , $ this ->fixture ('mailables/published-post.php ' ));
281+ $ this ->filesystem ->expects ('exists ' )
282+ ->with ('resources/views/emails/published-post.blade.php ' )
283+ ->andReturnTrue ();
284+
285+ $ tokens = $ this ->blueprint ->parse ($ this ->fixture ('drafts/send-statements.yaml ' ));
286+ $ tree = $ this ->blueprint ->analyze ($ tokens );
287+
288+ $ this ->assertEquals ([
289+ 'created ' => [
290+ 'app/Mail/ReviewPost.php ' ,
291+ 'app/Mail/PublishedPost.php ' ,
292+ ],
293+ ], $ this ->subject ->output ($ tree ));
294+ }
295+
296+ /**
297+ * @test
298+ */
299+ public function output_writes_mail_with_custom_template ()
300+ {
301+ $ this ->filesystem ->expects ('stub ' )
302+ ->with ('mail.stub ' )
303+ ->andReturn ($ this ->stub ('mail.stub ' ));
304+ $ this ->filesystem ->expects ('stub ' )
305+ ->with ('mail.view.stub ' )
306+ ->andReturn ($ this ->stub ('mail.view.stub ' ));
307+ $ this ->filesystem ->shouldReceive ('stub ' )
308+ ->with ('constructor.stub ' )
309+ ->andReturn ($ this ->stub ('constructor.stub ' ));
310+ $ this ->filesystem ->expects ('exists ' )
311+ ->with ('app/Mail ' )
312+ ->andReturns (true );
313+ $ this ->filesystem ->expects ('exists ' )
314+ ->with ('resources/views/emails/admin ' )
315+ ->andReturns (false );
316+ $ this ->filesystem ->expects ('exists ' )
317+ ->with ('app/Mail/AddedAdmin.php ' )
318+ ->andReturnFalse ();
319+ $ this ->filesystem ->expects ('put ' )
320+ ->with ('app/Mail/AddedAdmin.php ' , $ this ->fixture ('mailables/added-admin.php ' ));
321+ $ this ->filesystem ->expects ('exists ' )
322+ ->with ('resources/views/emails/admin/added.blade.php ' )
323+ ->andReturnFalse ();
324+ $ this ->filesystem ->expects ('makeDirectory ' )
325+ ->with ('resources/views/emails/admin ' , 0755 , true );
326+ $ this ->filesystem ->expects ('put ' )
327+ ->with ('resources/views/emails/admin/added.blade.php ' , $ this ->fixture ('mailables/added-admin-view.blade.php ' ));
328+
329+ $ tokens = $ this ->blueprint ->parse ($ this ->fixture ('drafts/send-statement-with-view.yaml ' ));
330+ $ tree = $ this ->blueprint ->analyze ($ tokens );
331+
332+ $ this ->assertEquals ([
333+ 'created ' => [
334+ 'app/Mail/AddedAdmin.php ' ,
335+ 'resources/views/emails/admin/added.blade.php ' ,
336+ ],
337+ ], $ this ->subject ->output ($ tree ));
181338 }
182339}
0 commit comments