Php 类App\Mail\EmailGenerator的对象无法转换为字符串
我有一个名为Php 类App\Mail\EmailGenerator的对象无法转换为字符串,php,laravel,phpunit,tdd,laravel-dusk,Php,Laravel,Phpunit,Tdd,Laravel Dusk,我有一个名为EmailGenerator的邮箱,还有一个名为NotificationTest的测试 每次我运行测试时,都会遇到这个错误 Object of class App\Mail\EmailGenerator could not be converted to string 这是我的NotificationTest.php <?php namespace Tests\Unit; use Tests\TestCase; use App\Http\Livewire\Notific
EmailGenerator
的邮箱,还有一个名为NotificationTest
的测试
每次我运行测试时,都会遇到这个错误
Object of class App\Mail\EmailGenerator could not be converted to string
这是我的NotificationTest.php
<?php
namespace Tests\Unit;
use Tests\TestCase;
use App\Http\Livewire\Notifications\CreateNotification;
use App\Http\Livewire\Notifications\ManageNotifications;
use App\Models\EmailTemplate;
use Livewire\Livewire;
use Mockery;
use Mockery\MockInterface;
use Mail;
use App\Mail\EmailGenerator;
use App\Models\User;
class NotificationTest extends TestCase
{
public function test_sample_email()
{
Mail::fake();
Mail::assertNothingSent();
$template = EmailTemplate::factory()->create([
'name' => 'foo',
]);
Mail::assertSent(new EmailGenerator($template));
}
}
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use App\Models\EmailTemplate;
class EmailGenerator extends Mailable
{
use Queueable, SerializesModels;
public $template;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(EmailTemplate $template)
{
$this->template = $template;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->subject($this->template->subject)
->markdown('emails.generator');
}
}
看起来
Mail::assertSent
所需的类名不是该类的实例
可能改为:
Mail::assertSent(EmailGenerator::class, 1);