@@ -112,46 +112,89 @@ protected function buildTestCases(Controller $controller)
112
112
113
113
foreach ($ statements as $ statement ) {
114
114
if ($ statement instanceof SendStatement) {
115
- $ this ->addImport ($ controller , 'Illuminate \\Support \\Facades \\Mail ' );
116
- $ this ->addImport ($ controller , config ('blueprint.namespace ' ) . '\\Mail \\' . $ statement ->mail ());
115
+ if ($ statement ->type () === 'notification ' ) {
116
+ $ this ->addImport ($ controller , 'Illuminate \\Support \\Facades \\Notification ' );
117
+ $ this ->addImport ($ controller , config ('blueprint.namespace ' ) . '\\Notification \\' . $ statement ->mail ());
117
118
118
- $ setup ['mock ' ][] = 'Mail ::fake(); ' ;
119
+ $ setup ['mock ' ][] = 'Notification ::fake(); ' ;
119
120
120
- $ assertion = sprintf ('Mail ::assertSent(%s::class ' , $ statement ->mail ());
121
+ $ assertion = sprintf ('Notification ::assertSent(%s::class ' , $ statement ->mail ());
121
122
122
- if ($ statement ->data () || $ statement ->to ()) {
123
- $ conditions = [];
124
- $ variables = [];
125
- $ assertion .= ', function ($mail ) ' ;
123
+ if ($ statement ->data () || $ statement ->to ()) {
124
+ $ conditions = [];
125
+ $ variables = [];
126
+ $ assertion .= ', function ($notification ) ' ;
126
127
127
- if ($ statement ->to ()) {
128
- $ conditions [] = '$mail ->hasTo($ ' . str_replace ('. ' , '-> ' , $ statement ->to ()) . ') ' ;
129
- }
128
+ if ($ statement ->to ()) {
129
+ $ conditions [] = '$notification ->hasTo($ ' . str_replace ('. ' , '-> ' , $ statement ->to ()) . ') ' ;
130
+ }
130
131
131
- foreach ($ statement ->data () as $ data ) {
132
- if (Str::studly (Str::singular ($ data )) === $ context ) {
133
- $ variables [] .= '$ ' . $ data ;
134
- $ conditions [] .= sprintf ('$mail->%s->is($%s) ' , $ data , $ data );
135
- } else {
136
- [$ model , $ property ] = explode ('. ' , $ data );
137
- $ variables [] .= '$ ' . $ model ;
138
- $ conditions [] .= sprintf ('$mail->%s == $%s ' , $ property ?? $ model , str_replace ('. ' , '-> ' , $ data ()));
132
+ foreach ($ statement ->data () as $ data ) {
133
+ if (Str::studly (Str::singular ($ data )) === $ context ) {
134
+ $ variables [] .= '$ ' . $ data ;
135
+ $ conditions [] .= sprintf ('$notification->%s->is($%s) ' , $ data , $ data );
136
+ } else {
137
+ [$ model , $ property ] = explode ('. ' , $ data );
138
+ $ variables [] .= '$ ' . $ model ;
139
+ $ conditions [] .= sprintf ('$notification->%s == $%s ' , $ property ?? $ model , str_replace ('. ' , '-> ' , $ data ()));
140
+ }
139
141
}
140
- }
141
142
142
- if ($ variables ) {
143
- $ assertion .= ' use ( ' . implode (', ' , array_unique ($ variables )) . ') ' ;
143
+ if ($ variables ) {
144
+ $ assertion .= ' use ( ' . implode (', ' , array_unique ($ variables )) . ') ' ;
145
+ }
146
+
147
+ $ assertion .= ' { ' . PHP_EOL ;
148
+ $ assertion .= str_pad (' ' , 12 );
149
+ $ assertion .= 'return ' . implode (' && ' , $ conditions ) . '; ' ;
150
+ $ assertion .= PHP_EOL . str_pad (' ' , 8 ) . '} ' ;
144
151
}
145
152
146
- $ assertion .= ' { ' . PHP_EOL ;
147
- $ assertion .= str_pad (' ' , 12 );
148
- $ assertion .= 'return ' . implode (' && ' , $ conditions ) . '; ' ;
149
- $ assertion .= PHP_EOL . str_pad (' ' , 8 ) . '} ' ;
150
- }
153
+ $ assertion .= '); ' ;
151
154
152
- $ assertion .= '); ' ;
155
+ $ assertions ['mock ' ][] = $ assertion ;
156
+ } else {
157
+ $ this ->addImport ($ controller , 'Illuminate \\Support \\Facades \\Mail ' );
158
+ $ this ->addImport ($ controller , config ('blueprint.namespace ' ) . '\\Mail \\' . $ statement ->mail ());
153
159
154
- $ assertions ['mock ' ][] = $ assertion ;
160
+ $ setup ['mock ' ][] = 'Mail::fake(); ' ;
161
+
162
+ $ assertion = sprintf ('Mail::assertSent(%s::class ' , $ statement ->mail ());
163
+
164
+ if ($ statement ->data () || $ statement ->to ()) {
165
+ $ conditions = [];
166
+ $ variables = [];
167
+ $ assertion .= ', function ($mail) ' ;
168
+
169
+ if ($ statement ->to ()) {
170
+ $ conditions [] = '$mail->hasTo($ ' . str_replace ('. ' , '-> ' , $ statement ->to ()) . ') ' ;
171
+ }
172
+
173
+ foreach ($ statement ->data () as $ data ) {
174
+ if (Str::studly (Str::singular ($ data )) === $ context ) {
175
+ $ variables [] .= '$ ' . $ data ;
176
+ $ conditions [] .= sprintf ('$mail->%s->is($%s) ' , $ data , $ data );
177
+ } else {
178
+ [$ model , $ property ] = explode ('. ' , $ data );
179
+ $ variables [] .= '$ ' . $ model ;
180
+ $ conditions [] .= sprintf ('$mail->%s == $%s ' , $ property ?? $ model , str_replace ('. ' , '-> ' , $ data ()));
181
+ }
182
+ }
183
+
184
+ if ($ variables ) {
185
+ $ assertion .= ' use ( ' . implode (', ' , array_unique ($ variables )) . ') ' ;
186
+ }
187
+
188
+ $ assertion .= ' { ' . PHP_EOL ;
189
+ $ assertion .= str_pad (' ' , 12 );
190
+ $ assertion .= 'return ' . implode (' && ' , $ conditions ) . '; ' ;
191
+ $ assertion .= PHP_EOL . str_pad (' ' , 8 ) . '} ' ;
192
+ }
193
+
194
+ $ assertion .= '); ' ;
195
+
196
+ $ assertions ['mock ' ][] = $ assertion ;
197
+ }
155
198
} elseif ($ statement instanceof ValidateStatement) {
156
199
$ this ->addTestAssertionsTrait ($ controller );
157
200
0 commit comments