master

laravel/framework

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

ChainedBatchTruthTest.php

TLDR

This file contains the ChainedBatchTruthTest class, which is used to create a truth test with a closure as a callback.

Classes

ChainedBatchTruthTest

The ChainedBatchTruthTest class is responsible for creating a truth test with a closure as a callback. It has the following methods:

  • __construct(Closure $callback): A constructor method that takes a closure as a parameter and sets it as the callback for the truth test.
  • __invoke($pendingBatch): A magic method that is called when an object is invoked as a function. It invokes the truth test callback with the given pending batch as an argument.
<?php

namespace Illuminate\Support\Testing\Fakes;

use Closure;

class ChainedBatchTruthTest
{
    /**
     * The underlying truth test.
     *
     * @var \Closure
     */
    protected $callback;

    /**
     * Create a new truth test instance.
     *
     * @param  \Closure  $callback
     * @return void
     */
    public function __construct(Closure $callback)
    {
        $this->callback = $callback;
    }

    /**
     * Invoke the truth test with the given pending batch.
     *
     * @param  \Illuminate\Bus\PendingBatch
     * @return bool
     */
    public function __invoke($pendingBatch)
    {
        return call_user_func($this->callback, $pendingBatch);
    }
}