Phpunit - 如何将另一个对象类型添加到模拟对象

时间:2017-12-28 14:19:24

标签: php phpunit mockery

我需要将Mailable类型添加到我的模拟ActivationMail中。也许你最好嘲笑我的ActivationMail课程? 经过测试的课程:

class MailService
{
    public function sendActivationEmail(User $user): void
    {
        $this->sendEmail(new ActivationMail($user));
    }

    //content

    protected function sendEmail(Mailable $mailable): void
    {
        //content
    }
}

ActivationMail:

class ActivationMail extends Mailable{}

你知道我该怎么测试呢? 我的测试:

public function test_sendActivationEmail()
{
    $user = Mockery::mock(User::class);
    $mailable = Mockery::mock(Mailable::class);

    Mockery::mock('overload:App\Mail\ActivationMail');

    $mailService = new MailService();
    $mailService->sendActivationEmail($user);
}

我的错误:

  

TypeError:参数1传递给App \ Services \ MailService :: sendEmail()   必须是Illuminate \ Mail \ Mailable的实例,实例   给出了App \ Mail \ ActivationMail

0 个答案:

没有答案