master

laravel/framework

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

PendingBatchFake.php

TLDR

This file, PendingBatchFake.php, is part of the Illuminate\Support\Testing\Fakes namespace and extends the PendingBatch class. It provides a fake implementation of the PendingBatch class and adds additional methods to it.

Methods

__construct

The __construct method is the constructor for the PendingBatchFake class. It takes two parameters: $bus of type BusFake and $jobs of type Collection. It sets the $bus property and the $jobs property of the object.

dispatch

The dispatch method dispatches the batch by calling the recordPendingBatch method on the $bus object and passing itself ($this) as an argument. It returns an instance of the Batch class.

dispatchAfterResponse

The dispatchAfterResponse method dispatches the batch after the response is sent to the browser. It has the same implementation as the dispatch method, calling the recordPendingBatch method on the $bus object with itself ($this) as an argument. It also returns an instance of the Batch class.

Classes

PendingBatchFake

The PendingBatchFake class extends the PendingBatch class. It provides a fake implementation of the PendingBatch class for testing purposes. It adds a constructor, dispatch method, and dispatchAfterResponse method to the PendingBatch class.

<?php

namespace Illuminate\Support\Testing\Fakes;

use Illuminate\Bus\PendingBatch;
use Illuminate\Support\Collection;

class PendingBatchFake extends PendingBatch
{
    /**
     * The fake bus instance.
     *
     * @var \Illuminate\Support\Testing\Fakes\BusFake
     */
    protected $bus;

    /**
     * Create a new pending batch instance.
     *
     * @param  \Illuminate\Support\Testing\Fakes\BusFake  $bus
     * @param  \Illuminate\Support\Collection  $jobs
     * @return void
     */
    public function __construct(BusFake $bus, Collection $jobs)
    {
        $this->bus = $bus;
        $this->jobs = $jobs;
    }

    /**
     * Dispatch the batch.
     *
     * @return \Illuminate\Bus\Batch
     */
    public function dispatch()
    {
        return $this->bus->recordPendingBatch($this);
    }

    /**
     * Dispatch the batch after the response is sent to the browser.
     *
     * @return \Illuminate\Bus\Batch
     */
    public function dispatchAfterResponse()
    {
        return $this->bus->recordPendingBatch($this);
    }
}