wmde/psr-log-test-doubles
Composer 安装命令:
composer require wmde/psr-log-test-doubles
包简介
Test Doubles for the PSR-3 Logger Interface
关键字:
README 文档
README
Test Doubles for the PSR-3 Logger Interface
Motivation
In PHP world, most people create Test Doubles via PHPUnits mocking framework ($this->createMock).
(Please beware that a PHPUnit mock really is a Test Double and not necessarily a mock.)
While this framework is often helpful, using it instead of creating your own Test Doubles comes with
some cost:
- Tools do not understand the PHPUnit magic. You will not be able to use automated refactorings such as method rename without your Test Doubles breaking. You will also get incorrect type warnings.
- When using
LoggerInterface, your test will bind to an implementation detail: if you uselogand provide a log level, or call a shortcut method such aserror. - Developers need to be familiar with the mocking tool.
- Simple things such as asserting the logger got called with two messages become difficult.
Usage
This library is unit testing tool agnostic. So while these examples use PHPUnit, any testing tool can be used.
Assert the logger is called twice with expected messages
public function testWhenStuffIsDone_loggerGetsCalled() { $logger = new LoggerSpy(); $serviceToTest = new ServiceToTest( $logger /*, other dependencies */ ); $serviceToTest->doStuff( /**/ ); $this->assertSame( [ 'First message', 'Second message' ], $logger->getLogCalls()->getMessages() ); }
Assert the logger is called twice
$this->assertCount( 2, $logger->getLogCalls() );
Assert the message and log level of the first logger call
$firstLogCall = $logger->getFirstLogCall(); $this->assertSame( 'First message', $firstLogCall->getMessage() ); $this->assertSame( LogLevel::ERROR, $firstLogCall->getLevel() );
Release notes
3.2.0 (2022-03-28)
- Added
LogCall::isError - Added
LogCall::withoutContext - Added
LogCalls::filter - Added
LogCalls::getErrors - Added
LogCalls::map - Added
LogCalls::withoutContexts
3.1.0 (2022-01-26)
- Added
LogCalls::getLastCall
3.0.0 (2022-01-26)
- Added support for
psr/log2.x and 3.x - Changed minimum PHP version from PHP 7.1 to 8.0
- Added several property, parameter and return types
- Added Psalm and PHPStan CI and compliance with level 1 checks
2.2.0 (2017-05-23)
- Added
LoggerSpy::getFirstLogCallconvenience method - Changed minimum PHP version from PHP 7.0 to 7.1
2.1.0 (2017-01-17)
LogCallsnow implementsCountable
2.0.0 (2017-01-16)
LoggerSpy::getLogCallsnow returns an instance ofLogCalls, which is a collection ofLogCall- Added
LogCalls::getMessages - Added
LogCalls::getFirstCall
1.1.0 (2016-11-11)
- Added
LoggerSpy::assertNoLoggingCallsWhereMade
1.0.0 (2016-10-18)
- Initial release with minimal
LoggerSpy
wmde/psr-log-test-doubles 适用场景与选型建议
wmde/psr-log-test-doubles 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 148.85k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2016 年 10 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「fixtures」 「test」 「Fixture」 「mock」 「test double」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wmde/psr-log-test-doubles 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wmde/psr-log-test-doubles 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wmde/psr-log-test-doubles 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Testing object factory for PHP
Testing Suite For Lumen like Laravel does.
Testing object factory for PHP
Plugin to compare fixtures with live DB tables
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
Laravel 5.x.x library for integration Monolog Sentry
统计信息
- 总下载量: 148.85k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 28
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2016-10-15