Created
November 16, 2017 18:26
-
-
Save deividaspetraitis/1ca48867aededff73812c72b834b1a48 to your computer and use it in GitHub Desktop.
Laravel Fake Mailable Fails After Few Emails Inside Application Are Sent.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Test | |
{ | |
/** | |
* Api Helper | |
* | |
* @var \Helper\Api | |
*/ | |
protected $api; | |
/** | |
* Module repository | |
* | |
* @var $repository | |
*/ | |
protected $repository; | |
/** | |
* Load required helpers for cest | |
* | |
* @param \Helper\Api $api | |
*/ | |
protected function _inject(\Helper\Api $api) | |
{ | |
$this->api = $api; | |
} | |
/** | |
* Return module repository | |
* | |
* @return UserRepository | |
*/ | |
public function _getRepository() : UserRepository | |
{ | |
return $this->api->getApplication()->make('Modules\Users\Services\User\UserService')->getUserRepository(); | |
} | |
/** | |
* Actions executed before cest | |
* | |
* @param ApiTester $I | |
*/ | |
public function _before(ApiTester $I) | |
{ | |
} | |
/** | |
* Actions executed after cest | |
* | |
* @param ApiTester $I | |
*/ | |
public function _after(ApiTester $I) | |
{ | |
} | |
/** | |
* Test user activation | |
* | |
* @param ApiTester $I | |
* | |
* @return void | |
*/ | |
public function test(ApiTester $I) : void | |
{ | |
// Prevent actual email being sent | |
Mail::fake(); | |
// Do some stuff | |
// Email 1 inside application is sent.. | |
Mail::assertSent(Action1Mail::class, function (Action1Maill $mail) { | |
return $mail->getVal() == 1; | |
}); | |
// Do some stuff | |
// Email 2 inside application is sent.. | |
// Boom, error: [BadMethodCallException] Method assertSent does not exist. | |
// Because: get_class(app('mailer')) == Illuminate\Mail\Mailer | |
// And no more: get_class(app('mailer')) == Illuminate\Support\Testing\Fakes\MailFake | |
Mail::assertSent(Action2Mail::class, function (Action2Mail $mail) { | |
return $mail->getVal() == 2; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment