master

laravel/framework

Last updated at: 29/12/2023 09:25

PendingMailFake.php

TLDR

The PendingMailFake.php file in the Illuminate\Support\Testing\Fakes namespace contains a class called PendingMailFake. This class extends Laravel's PendingMail class and provides methods to send or queue mailable messages.

Methods

__construct

This method is the constructor of the PendingMailFake class. It takes a parameter $mailer of type Illuminate\Support\Testing\Fakes\MailFake and assigns it to the mailer property of the class.

send

This method is used to send a new mailable message instance. It takes a parameter $mailable of type Illuminate\Contracts\Mail\Mailable and sends the message using the mailer property's send method after filling it.

queue

This method is used to push the given mailable onto the queue. It takes a parameter $mailable of type Illuminate\Contracts\Mail\Mailable and queues the message using the mailer property's queue method after filling it.

<?php

namespace Illuminate\Support\Testing\Fakes;

use Illuminate\Contracts\Mail\Mailable;
use Illuminate\Mail\PendingMail;

class PendingMailFake extends PendingMail
{
    /**
     * Create a new instance.
     *
     * @param  \Illuminate\Support\Testing\Fakes\MailFake  $mailer
     * @return void
     */
    public function __construct($mailer)
    {
        $this->mailer = $mailer;
    }

    /**
     * Send a new mailable message instance.
     *
     * @param  \Illuminate\Contracts\Mail\Mailable  $mailable
     * @return void
     */
    public function send(Mailable $mailable)
    {
        $this->mailer->send($this->fill($mailable));
    }

    /**
     * Push the given mailable onto the queue.
     *
     * @param  \Illuminate\Contracts\Mail\Mailable  $mailable
     * @return mixed
     */
    public function queue(Mailable $mailable)
    {
        return $this->mailer->queue($this->fill($mailable));
    }
}