If I use \mail
in a test class, Laravel 5.7 tells me that class mailer
does not exists.
Here is my test function:
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
\Mail::raw('Hello world', function($message){
$message->to('[email protected]');
$message->from('[email protected]');
});
}
This happens when I enter phpunit
in terminal:
1) Tests\Feature\ExampleTest::testBasicTest ReflectionException: Class mailer does not exist
/home/www/testmachine/vendor/laravel/framework/src/Illuminate/Container/Container.php:779 /home/www/testmachine/vendor/laravel/framework/src/Illuminate/Container/Container.php:658 /home/www/testmachine/vendor/laravel/framework/src/Illuminate/Container/Container.php:609 /home/www/testmachine/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:735 /home/www/testmachine/vendor/laravel/framework/src/Illuminate/Container/Container.php:1222 /home/www/testmachine/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:175 /home/www/testmachine/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:144 /home/www/testmachine/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:231 /home/www/testmachine/tests/Feature/ExampleTest.php:14
However, when I use mail somewhere else in my application it works, for example in Route.php
:
Route::get('/test', function(){
\Mail::raw('Hello world', function($message){
$message->to('[email protected]');
$message->from('[email protected]');
});
dd('hi');
});
I checked that Illuminate\Mail\MailServiceProvider::class
is in app.php as suggested here and I also performed a composer update
and then composer dump-autoload
as suggested here.
Any ideas why this error is thrown?