Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 类App\Mail\EmailGenerator的对象无法转换为字符串_Php_Laravel_Phpunit_Tdd_Laravel Dusk - Fatal编程技术网

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);