Skip to content

Commit b07b541

Browse files
committed
return check for afterApplicationCreated
1 parent 88e807f commit b07b541

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/LaravelMailAssertions/MakesMailAssertions.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,13 @@ public function emptyMail()
126126
*/
127127
public function fakeMail()
128128
{
129-
Mail::shouldReceive('send')->andReturnUsing(function (...$args) {
130-
$this->getEmailSender()->send(...$args);
131-
});
132-
133-
Mail::shouldReceive('raw')->andReturnUsing(function (...$args) {
134-
$this->getEmailSender()->sendRaw(...$args);
135-
});
136-
137-
Mail::shouldReceive('failures');
129+
if (method_exists($this, 'afterApplicationCreated')) {
130+
$this->afterApplicationCreated(function () {
131+
$this->mockMailFacade();
132+
});
133+
} else {
134+
$this->mockMailFacade();
135+
}
138136
}
139137

140138
/**
@@ -183,4 +181,21 @@ private function getEmailSender()
183181
{
184182
return Mailer::instance();
185183
}
184+
185+
/**
186+
* Mock the mail facade
187+
* @return void
188+
*/
189+
private function mockMailFacade()
190+
{
191+
Mail::shouldReceive('send')->andReturnUsing(function (...$args) {
192+
$this->getEmailSender()->send(...$args);
193+
});
194+
195+
Mail::shouldReceive('raw')->andReturnUsing(function (...$args) {
196+
$this->getEmailSender()->sendRaw(...$args);
197+
});
198+
199+
Mail::shouldReceive('failures');
200+
}
186201
}

0 commit comments

Comments
 (0)