Laravel Log Fake 2.0包用于断言/伪造记录/假日志
Laravel  /  管理员 发布于 3星期前   248
Laravel Log Fake发布了v2.0,支持Laravel 9和一个完全基于闭包的断言 API:
- Laravel 9 支持
- 重写日志断言 API
- 上下文支持 + 针对通道上下文的断言
- 检查功能 (dump, dd)
- 支持自定义消息
Log fake 包是确保通过测试断言发生关键日志记录的绝佳方式。
作为自述文件中的一个基本示例,您首先绑定LogFake实例,然后您可以断言日志记录:
LogFake::bind();
// Run test code
// Logging assertions
Log::assertLogged(fn (LogEntry $log) =>
$log->level === 'info'
&& $log->message === 'User logged in.'
&& $log->context === ['user_id' => 5]
);
v2.0 中的新功能还有在测试期间调试日志消息的dd()和dump()助手:
Log::dump();
// array:1 [
// 0 => array:4 [
// "level" => "info"
// "message" => "User logged in."
// "context" => []
// "channel" => "stack"
// ]
// ]
Log::channel('slack')->dump();
Log::dumpAll();
Log::dd();
Log::ddAll();
您还可以使用各种logs()帮助程序检查日志记录并围绕它们编写断言:
$logs = Log::allLogs();
assert($logs->count() === 2);
$logs = Log::allLogs();
assert($logs->count() === 2);
最后,与Laravel 9.12 的per-channel logging context API 一起,
Log Fake 包还可以断言 context:
Log::assertCurrentContext(
fn (array $context) => $context['app'] === 'Acme CRM')
);
请务必检查可用的断言以查看可用的完整日志断言 API。
您可以了解有关此软件包的更多信息,获取完整的安装说明,并在 GitHub 上查看源代码。
https://github.com/timacdonald/log-fake#available-assertions
https://github.com/timacdonald/log-fake
https://laravel-news.com/laravel-9-12-0
nkt 在
阿里云香港服务器搭建自用vpn:Shadowsocks使用流程步骤中评论 用了三分钟就被禁了,直接阿里云服务器22端口都禁了..熊丽 在
安装docker + locust + boomer压测环境实现对接口的压测中评论 试试水..博主 在
阿里云香港服务器搭建自用vpn:Shadowsocks使用流程步骤中评论 @test 也可能是国内大环境所至,也是好事,督促你该研究学习新技术..test 在
阿里云香港服务器搭建自用vpn:Shadowsocks使用流程步骤中评论 打了一次网页,然后再也打不开了。。是阿里云的缘故吗?..博主 在
centos7中Meili Search搜索引擎安装流程步骤中评论 @鹿 执行以下命令看看你的2.27版本是否存在strin..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号