Php ReflectionException:类mailer不存在
如果我在测试类中使用Php ReflectionException:类mailer不存在,php,laravel,Php,Laravel,如果我在测试类中使用\mail,Laravel 5.7告诉我类mailer不存在 以下是我的测试函数: /** * A basic test example. * * @return void */ public function testBasicTest() { \Mail::raw('Hello world', function($message){ $message->to('foo@bar.com
\mail
,Laravel 5.7告诉我类mailer
不存在
以下是我的测试函数:
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
\Mail::raw('Hello world', function($message){
$message->to('foo@bar.com');
$message->from('bar@foo.com');
});
}
当我在终端中输入phpunit
时会发生这种情况:
1) Tests\Feature\ExampleTest::testBasicTest ReflectionException:类
mailer不存在
/home/www/testmachine/vendor/laravel/framework/src/illumb/Container/Container.php:779
/home/www/testmachine/vendor/laravel/framework/src/illusted/Container/Container.php:658
/home/www/testmachine/vendor/laravel/framework/src/illumb/Container/Container.php:609
/home/www/testmachine/vendor/laravel/framework/src/illusted/Foundation/Application.php:735
/home/www/testmachine/vendor/laravel/framework/src/illumb/Container/Container.php:1222
/home/www/testmachine/vendor/laravel/framework/src/illusted/Support/Facades/Facade.php:175
/home/www/testmachine/vendor/laravel/framework/src/light/Support/Facades/Facade.php:144
/home/www/testmachine/vendor/laravel/framework/src/illusted/Support/Facades/Facade.php:231
/home/www/testmachine/tests/Feature/ExampleTest.php:14
但是,当我在应用程序的其他地方使用邮件时,它会工作,例如在Route.php
:
Route::get('/test', function(){
\Mail::raw('Hello world', function($message){
$message->to('foo@bar.com');
$message->from('bar@foo.com');
});
dd('hi');
});
我按照建议检查了app.php中是否有illighted\Mail\MailServiceProvider::class
,并执行了composer更新
,然后按照建议执行了composer dump autoload
知道为什么会抛出此错误吗?在测试类中,我认为您需要使用use语句指定邮件类:
use Illuminate\Support\Facades\Mail;
但是,在测试进行得太远之前,请查看邮件伪造功能(mail::fake()
)
要模拟邮件,只需查看以下文档: 但对于发送实际邮件,可以使用laracasts编写的MailTrap测试类
在一次
编写器转储自动加载过程中,我也遇到了这个错误。事实证明,我的代码中有一个简单的语法错误,而且我还设置了一个异常处理程序,每当网站上出现错误时,它都会向我发送电子邮件
我认为发生的事情是,在composer转储autoload
期间,遇到语法错误时,composer没有构建其autoload
文件,因此当这触发发送给我的电子邮件时,Mail
facade调用失败,即使使用了正确的use
语句
可能不是导致此错误的普遍原因,但希望这对某些人有用。您真的想从测试中发送邮件还是想伪造发送邮件?我尝试使用use-illumb\Support\Facades\mail
并使用Mail::
而不是\Mail
,但我会收到相同的错误消息。谢谢你提到了伪造的课程。