circle33/laravel-bus-fluentable 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

circle33/laravel-bus-fluentable

Composer 安装命令:

composer require circle33/laravel-bus-fluentable

包简介

Make Laravel testing batched jobs more fluent.

README 文档

README

Laravel Bus Fluentable

Latest Version on Packagist PHPUnit Static Analysis Check Style

When using Laravel, the current approach to testing batched jobs, as shown below, is somewhat unconventional:

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

This package introduces some helper functions to enhance the testability of batched jobs. Inspired by fluent JSON testing, these methods provide a more streamlined and readable approach to testing job batches within the Laravel application. The goal is to improve developer experience by offering clear, concise methods with illustrative examples.

Installation

composer require --dev circle33/laravel-bus-fluentable

Documentation

has

Assert that the batch contains a job of the given type. You can also pass an integer to assert that the batch contains the exact number of jobs.

Example:

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])
);

missing

Assert that the batch does not contain a job of the given type.

Example:

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)
);

hasAll

Assert that the batch contains all of the given jobs.

Example:

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])
);

missingAll

Assert that the batch does not contain any of the given jobs.

Example:

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])
);

hasAny

Assert that the batch contains any of the given jobs.

Example:

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)
);

first

Assert that the first job in the batch matches the given callback.

Example:

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)
    )
);

nth

Assert that the nth job in the batch matches the given callback or type and parameters.

Example:

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])
);

equal

Assert that the batch contains exactly the given jobs with the specified parameters.

Example:

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]
    ])
);

etc

Assert that the batch has unexpected jobs beyond those checked.

Example:

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()
);

Contributing

Thank you for considering contributing to this project! We welcome and appreciate your help.

  1. Fork the repository to your GitHub account.
  2. Clone your forked repository to your local machine:
    git clone https://github.com/your-username/laravel-bus-fluentable.git
    

License

The MIT License (MIT). Please see License File for more information.

circle33/laravel-bus-fluentable 适用场景与选型建议

circle33/laravel-bus-fluentable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「laravel-bus-fluentable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 circle33/laravel-bus-fluentable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 circle33/laravel-bus-fluentable 我们能提供哪些服务?
定制开发 / 二次开发

基于 circle33/laravel-bus-fluentable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-18