Closed
Description
I changed the ForgotPasswordMail structure at the following branch https://github.com/RonasIT/laravel-empty-project/tree/error-when-testing-mail-content and found that if we do not use a viewData
it fails tests.
Illuminate\View\ViewException: Undefined variable $hash (View: /app/resources/views/emails/forgot_password.blade.php)
/app/storage/framework/views/ebbd7a56f1475ebab6e4bb80cd203236.php:25
/app/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php:60
/app/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php:73
/app/vendor/laravel/framework/src/Illuminate/View/View.php:208
/app/vendor/laravel/framework/src/Illuminate/View/View.php:191
/app/vendor/laravel/framework/src/Illuminate/View/View.php:160
/app/vendor/ronasit/laravel-helpers/src/Traits/MailsMockTrait.php:188
/app/vendor/ronasit/laravel-helpers/src/Traits/MailsMockTrait.php:79
/app/vendor/laravel/framework/src/Illuminate/Support/Testing/Fakes/MailFake.php:374
/app/vendor/laravel/framework/src/Illuminate/Collections/Arr.php:926
/app/vendor/laravel/framework/src/Illuminate/Collections/Collection.php:369
/app/vendor/laravel/framework/src/Illuminate/Support/Testing/Fakes/MailFake.php:374
/app/vendor/laravel/framework/src/Illuminate/Support/Testing/Fakes/MailFake.php:210
/app/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:357
/app/vendor/ronasit/laravel-helpers/src/Traits/MailsMockTrait.php:66
/app/tests/AuthTest.php:259
This row is the reason for error https://github.com/RonasIT/laravel-helpers/blob/master/src/Traits/MailsMockTrait.php#L188
{
$view = (method_exists($mail, 'content')) ? $mail->content()->view : $mail->view;
$mailContent = view($view, $mail->viewData)->render();
if ($exportMode) {
$this->exportContent($mailContent, $expectedMailData['fixture']);
}
We support only viewData but a Mailable object may not have any viewData.