每月免费发送 4,000 封电子邮件 | Mailtrap 现在发送真正的电子邮件!

Laravel 13.3.0 中的单元测试属性及更多功能

最后更新于 经过

Laravel 13.3.0 图片中的单元测试属性及其他功能

This release introduces a #[UnitTest] PHP attribute for skipping framework boot on individual test methods, variadic support for model attributes like #[Fillable]#[Hidden] , a new BatchStarted event in the job batching lifecycle, and more.

  • 新的 #[UnitTest] attribute to skip framework boot per test method
  • Variadic args for #[Fillable] , #[Appends] , #[Hidden] , and other model attributes
  • 新的 BatchStarted event for job batch lifecycle monitoring
  • Memory usage shown in verbose queue worker output
  • Security: install:broadcasting now passes --ignore-scripts to npm/pnpm

什么是新的

#[UnitTest] 属性

新的 #[UnitTest] attribute lets you skip framework booting for individual test methods within a TestCase that extends Laravel's base test case. This is useful when most tests in a class need the container but a few are pure unit tests that don't.

Without it, every test in the class pays the cost of booting the full framework. With #[UnitTest] , those specific methods run as bare PHPUnit tests — which can be an order of magnitude faster.

使用 Illuminate\Foundation\Testing\Attributes\UnitTest ;
班级 LocationServiceTest 延伸 测试用例
{
民众 功能 test_getCoordinates_resolves_address_for_us () : 空白
{
// needs the container
}
#[ UnitTest ]
民众 功能 test_getState_returns_state_from_abbreviation () : 空白
{
// no framework boot needed
}
}

拉取请求: #59432

Variadic Model Attributes

Several Eloquent model attributes now accept variadic arguments. Previously, you had to pass an array; now you can pass each value as a separate argument:

// 前
#[ 可填写 ([ '名' , '姓' ])]
#[ ([ '密码' , '秘密' ])]
班级 用户 延伸 模型 {}
// 后
#[ 可填写 '名' , '姓' )]
#[ '密码' , '秘密' )]
班级 用户 延伸 模型 {}

Passing a single array is still supported, so there are no breaking changes.

拉取请求: #59421

BatchStarted 事件

新的 BatchStarted event fires when the first job in a batch is processed (whether it succeeds or fails). This fills in a gap in the batch lifecycle:

  • BatchDispatched — jobs are queued, no worker has touched them yet
  • BatchStarted — first job has been processed
  • BatchFinished — all jobs are done (or cancelled)
  • BatchCanceled — batch was cancelled

This makes it possible to distinguish between a batch that's been queued and one that's actively being worked, which is useful for progress monitoring and UI updates.

拉取请求: #59458

Memory Usage in Verbose Queue Worker Output

When running the queue worker with -v , each processed job now includes current memory usage alongside the existing timing information:

# 前
2026-04-01 09:45:39 App\Jobs\ProcessReport 121599597 database reports 110.57ms DONE
# 后
2026-04-01 09:45:39 App\Jobs\ProcessReport 121599597 database reports 44.58ms 132.5MB DONE

The memory reading uses the same logic as the worker's internal memoryExceeded check, so it gives you a direct view of how close a job is pushing toward the --memory limit.

拉取请求: #59379

其他修复和改进

队列和工作者:

  • Forward releaseOnTerminationSignals through schedule groups ( #59357
  • 额外 LostConnectionWorkerStopReason#59370
  • Fixed dependency injection of faked queueing dispatcher ( #59378
  • Cached getLockForPopping() result in DatabaseQueue#59435
  • Enum support added to QueueManager connection methods ( #59389
  • Enum support added to LogManager channel and driver methods ( #59391

Scheduling:

  • Fixed sub-minute scheduling skips at minute boundaries ( #59331

模型与数据库:

  • 固定的 incrementEach / decrementEach to scope to the model instance ( #59376
  • 固定的 MorphTo eager load matching when ownerKey is null and the result key is a non-primitive ( #59394
  • CollectedBy attribute now follows inheritance ( #59419
  • Stringable objects can now be returned from casts()#59479
  • Fixed macros with static closures ( #59414

HTTP & Requests:

  • 额外 ->file() 方法 $request->safe() for accessing validated file inputs ( #59396
  • Pass request to afterResponse callback ( #59410

类型:

  • 额外 isNotEmpty() 方法到 Uri class ( #59408
  • 额外 withoutFragment() 方法到 Uri class ( #59413
  • Fixed URI fragment preservation when decoding query strings ( #59481

测试:

  • 额外 assertHasNoAttachments()Mailable#59443
  • 额外 driver() 方法 MailFake#59448

收藏品:

  • Collection methods are now compatible with extended subclass constructors ( #59455

Schema:

  • MariaDbSchemaState now uses mysql --version for client detection instead of mariadb --version#59360

Security:

  • install:broadcasting command now passes --ignore-scripts to npm/pnpm when installing packages, preventing lifecycle scripts from running during installation ( #59485

升级说明

对于一般应用场景,预计不会出现重大变更。升级时请查看完整的变更日志以了解详细信息。

参考

保罗·雷德蒙德照片

Laravel News 特约撰稿人。全栈 Web 开发人员兼作家。

归档于:
立方体

Laravel 时事通讯

加入超过 4 万名开发者的行列,不错过任何新的技巧、教程等内容。

图像
SerpApi

适用于您的 LLM 和 AI 应用的 Web 搜索 API

访问 SerpApi
Tinkerwell 徽标

廷克威尔

Laravel 开发者必备的代码运行器。可在本地和生产环境中体验 AI、自动补全和即时反馈功能。

廷克威尔
几天内即可获得 Laravel 代码审查徽标的专家指导

几天内即可获得 Laravel 代码审查方面的专家指导

专家级代码审查!两位拥有 10 年以上 Laravel 开发经验的开发者将为您提供清晰、实用的反馈,帮助团队构建更优质的应用程序。

几天内即可获得 Laravel 代码审查方面的专家指导
PhpStorm 标志

PhpStorm

首选的 PHP IDE,对 Laravel 及其生态系统提供广泛的开箱即用支持。

PhpStorm
Laravel Cloud 标志

Laravel 云

轻松创建和管理服务器,并在几秒钟内部署 Laravel 应用程序。

Laravel 云
了解 Softtech 的标志

了解软科技

Acquaint Softtech 提供 AI 就绪的 Laravel 开发人员,48 小时内即可上手,每月费用为 3000 美元,没有冗长的销售流程,并提供 100% 退款保证。

了解软科技
Kirschbaum 标志

樱桃树

提供创新和稳定性,确保您的Web应用程序取得成功。

樱桃树
Shift 标志

转移

还在运行旧版本的 Laravel?立即实现 Laravel 自动升级和代码现代化,让您的应用程序保持最新状态。

转移
鱼叉:新一代时间跟踪和发票标志

Harpoon:新一代时间跟踪和发票系统

新一代时间跟踪和计费软件,帮助您的机构规划和预测盈利的未来。

Harpoon:新一代时间跟踪和发票系统
Lucky Media 标志

幸运传媒

Get Lucky Now——拥有十余年经验的 Laravel 开发理想之选!

幸运传媒
SaaSykit:Laravel SaaS 入门套件徽标

SaaSykit:Laravel SaaS 入门套件

SaaSykit 是一个多租户 Laravel SaaS 入门套件,包含运行现代 SaaS 所需的所有功能,例如支付、美观的结账界面、管理面板、用户仪表盘、身份验证、现成组件、统计数据、博客、文档等等。

SaaSykit:Laravel SaaS 入门套件
Log User Activity in Your Laravel App with Activity Log v5  image

Log User Activity in Your Laravel App with Activity Log v5

阅读文章
使用新的 Cloud CLI 镜像从终端管理 Laravel Cloud

使用新的 Cloud CLI 从终端管理 Laravel Cloud

阅读文章
Laravel 13.3.0 图片中的单元测试属性及其他功能

Laravel 13.3.0 中的单元测试属性及更多功能

阅读文章
PAO:PHP 测试工具的代理优化输出图像

PAO:PHP 测试工具的代理优化输出

阅读文章
PhpStorm 2026.1 发布镜像

PhpStorm 2026.1 发布

阅读文章
使用 Laravel 构建 AI:智能工单分类及结构化输出图像

使用 Laravel 构建 AI:基于结构化输出的智能工单分诊

阅读文章