PHP code example of circle33 / laravel-bus-fluentable

1. Go to this page and download the library: Download circle33/laravel-bus-fluentable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

circle33 / laravel-bus-fluentable example snippets


use Circle33\LaravelBusFluentable\Bus as BusFacade;
use Circle33\LaravelBusFluentable\FluentPendingBatch;

Bus::fake();

Bus::batch([
    new AJob(1, 2),
    new BJob,
])->dispatch();

BusFacade::assertPendingBatched(fn (FluentPendingBatch $batch) =>
    $batch->has(2)
        ->has(AJob::class, [1, 2])
);

use Circle33\LaravelBusFluentable\Bus as BusFacade;
use Circle33\LaravelBusFluentable\FluentPendingBatch;

Bus::fake();

Bus::batch([
    new BJob,
])->dispatch();

BusFacade::assertPendingBatched(fn (FluentPendingBatch $batch) =>
    $batch->missing(AJob::class)
);

use Circle33\LaravelBusFluentable\Bus as BusFacade;
use Circle33\LaravelBusFluentable\FluentPendingBatch;

Bus::fake();

Bus::batch([
    new AJob,
    new BJob,
])->dispatch();

BusFacade::assertPendingBatched(fn (FluentPendingBatch $batch) =>
    $batch->hasAll([AJob::class, BJob::class])
);

use Circle33\LaravelBusFluentable\Bus as BusFacade;
use Circle33\LaravelBusFluentable\FluentPendingBatch;

Bus::fake();

Bus::batch([
    new AJob,
    new BJob,
])->dispatch();

BusFacade::assertPendingBatched(fn (FluentPendingBatch $batch) =>
    $batch->missingAll([CJob::class, DJob::class])
);

use Circle33\LaravelBusFluentable\Bus as BusFacade;
use Circle33\LaravelBusFluentable\FluentPendingBatch;

Bus::fake();

Bus::batch([
    new AJob(1, 2),
    new BJob,
])->dispatch();

BusFacade::assertPendingBatched(fn (FluentPendingBatch $batch) =>
    $batch->hasAny(AJob::class, CJob::class)
);

use Circle33\LaravelBusFluentable\Bus as BusFacade;
use Circle33\LaravelBusFluentable\FluentPendingBatch;

Bus::fake();

Bus::batch([
    [
        new AJob(1, 2),
        new BJob,
    ],
    new CJob,
])->dispatch();

BusFacade::assertPendingBatched(fn (FluentPendingBatch $batch) =>
    $batch->first(fn (PendingBatchFake $firstBatch) =>
        $firstBatch->has(AJob::class, [1, 2])
            ->has(BJob::class)
    )
);

use Circle33\LaravelBusFluentable\Bus as BusFacade;
use Circle33\LaravelBusFluentable\FluentPendingBatch;

Bus::fake();

Bus::batch([
    [
        new AJob(1, 2),
        new BJob
    ],
    new CJob::class(1)
])->dispatch();

BusFacade::assertPendingBatched(fn (FluentPendingBatch $batch) =>
    $batch->nth(0, fn (FluentPendingBatch $batch) =>
        $batch->has(AJob::class, [1, 2])
            ->has(BJob::class)
    )->nth(1, CJob::class, [1])
);

use Circle33\LaravelBusFluentable\Bus as BusFacade;
use Circle33\LaravelBusFluentable\FluentPendingBatch;

Bus::fake();

Bus::batch([
    [
        new AJob(1, 2),
        new BJob
    ],
    new CJob::class(1)
])->dispatch();

BusFacade::assertPendingBatched(fn (FluentPendingBatch $batch) =>
    $batch->equal([
        [
            AJob::class => [1, 2],
            BJob::class
        ],
        CJob::class => [1]
    ])
);

use Circle33\LaravelBusFluentable\Bus as BusFacade;
use Circle33\LaravelBusFluentable\FluentPendingBatch;

Bus::fake();

Bus::batch([
    new AJob(1, 2),
    new BJob,
    new CJob::class(1)
])->dispatch();

BusFacade::assertPendingBatched(fn (FluentPendingBatch $batch) =>
    $batch->has(AJob::class, [1, 2])
        ->has(BJob::class)
        ->etc()
);

Bus::assertBatched(fn (PendingBatchFake $batchedCollection) =>
    $batchedCollection->jobs->count() === 1 && $batchedCollection->jobs->first()->value === 'hello';
);