lundi 20 juillet 2020

Call to undefined method Illuminate\Support\Testing\Fakes\MailFake::assertQueued()

I have a mailable MailTransportOrder which is working fine when tested functionally. I am writing a unit test which is failing with the following error:

Call to undefined method Illuminate\Support\Testing\Fakes\MailFake::assertQueued()

Now here is my test:

    /**
     * @test
     */
    public function testMailTransportOrder()
    {
        \Mail::fake();

        \Mail::assertQueued(MailTransportOrder::class);

        $user = \Sentinel::getUser();

        \Mail::assertQueued(MailTransportOrder::class, function ($mail) use ($user) {
            return $mail->hasTo($user->email);
        });
    }

And here is my Mailable class:

class MailTransportOrder extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

    /**
     * @var
     */
    public $simulated;

    /**
     * @var
     */
    public $title;

    /**
     * @var
     */
    public $items;

    /**
     * @var array
     */
    public $groupedTransportOrders = [];

    /**
     * @var
     */
    public $grouped;

    /**
     * @var
     */
    public $emailSubject;


    /**
     * MailTransportOrder constructor.
     * @param $transportOrders
     * @param $simulated
     */
    public function __construct($transportOrders, $simulated)
    {
        $this->items = $transportOrders;
        $this->simulated = $simulated;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $this->setTransportOrders();
        $this->setTitle();
        $this->setGrouped();
        $this->setSubject();
        return $this->subject($this->emailSubject)->view('emails.price-requests.overview');
    }

    public function setSubject()
    {
        $this->emailSubject = $this->simulated ? 'Simulated Transport Orders' : 'Transport Orders';
        $this->emailSubject = $this->emailSubject . $this->getOrderNumber();

        return $this;
    }

    /**
     * @return $this
     */
    public function setGrouped()
    {
        $this->grouped = $this->groupedTransportOrders;

        return $this;
    }

    /**
     * @return $this
     */
    public function setTitle()
    {
        $this->title = $this->simulated ? 'SIMULATED TRANSPORT ORDERS' : 'TRANSPORT ORDERS';

        return $this;
    }

    /**
     * @return $this
     */
    public function setTransportOrders()
    {
        $this->groupByCarrier();

        return $this;
    }

    /**
     * @return $this
     */
    public function groupByCarrier()
    {
        $transformer = new TransportOrderEmailTransformer();

        foreach ($this->items as $transportOrder) {
            if (!array_key_exists($transportOrder->carrier_name, $this->groupedTransportOrders)) {
                $this->groupedTransportOrders[$transportOrder->carrier_name] = [
                    'transport_orders' => []
                ];
            }

            $transformed = $transformer->transform($transportOrder);

            $this->groupedTransportOrders[$transportOrder->carrier_name]['transport_orders'][] = $transformed;
        }

        return $this;
    }

    /**
     * @return string|null
     */
    private function getOrderNumber()
    {
        if (count($this->items) > 1) {
            return ' - ' . $this->items->first()->orderNumber->order_number . ' - and more references';
        }

        if (count($this->items) == 1) {
            return ' - ' . $this->items->first()->orderNumber->order_number;
        }

        return null;
    }
}

I have tried assertSent as well but it gives the following error:

The expected [Phirater\Mail\MailTransportOrder] mailable was not sent.

My Laravel version is 5.4.0! Any help as to what am I doing wrong here and what could be the solution?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire