byteout/psr-logger-codeception-module
Composer 安装命令:
composer require byteout/psr-logger-codeception-module
包简介
Codeception module for validation of messages logged by PSR3 loggers.
README 文档
README
Codeception module for validation of messages logged by PSR3 loggers.
Developed by Byteout Software.
Compatibility
| PHP | codeception | psr/log | Module Version |
|---|---|---|---|
=5.6.0 <9.0 |
^2.2|^3.0|^4.0 |
^1.0 |
byteout/psr-logger-codeception-module:^1.0 |
^8.0 |
^4.1.9|^5.0 |
^2.0|^3.0 |
byteout/psr-logger-codeception-module:^2.0 |
Installation
-
Install and configure Codeception
-
Install module using composer
composer require "byteout/psr-logger-codeception-module" --dev -
Enable the module in your suite
{NAME}.suite.yml:modules: enabled: - Byteout\Codeception\Module\PsrLogger
Examples
-
Simple usage
<?php $logger = $I->grabLogger(); $logger->notice('This is logger example.'); $I->seeLoggerHasNotice('This is logger example.');
-
Track logs from other services
<?php use Psr\Log\LoggerInterface; class HelloWorld { private $logger; public function __construct(LoggerInterface $logger) { $this->logger = $logger; } public function sayHello($name) { $this->logger->info("Hello $name"); } } $logger = $I->grabLogger(); $service = new HelloWorld($logger); $service->sayHello('John'); $I->seeLoggerHasInfo('Hello John');
-
Simulate logs
<?php $I->haveWarning('Something bad happened', ['problem' => 'This is more info.']); $I->dontSeeLoggerHasAnyError(); $I->seeLoggerHasAnyWarning(); $I->seeLoggerHasWarningThatContains('bad');
Actions
Get logger instance
public function grabLogger(): \Psr\Log\LoggerInterface;
Log message
public function haveEmergency(string $message, array $context = []); public function haveAlert(string $message, array $context = []); public function haveCritical(string $message, array $context = []); public function haveError(string $message, array $context = []); public function haveWarning(string $message, array $context = []); public function haveNotice(string $message, array $context = []); public function haveInfo(string $message, array $context = []); public function haveDebug(string $message, array $context = []);
Example:
$I->haveEmergency('This is emergency'); $I->haveEmergency('This is emergency with context', ['error' => 'This is context array']);
Check if specific message was logged
When context is null only message is matched, and context is ignored. When context is array it will
be fully matched, along with the message.
public function seeLoggerHasEmergency(string $message, array $context = null); public function seeLoggerHasAlert(string $message, array $context = null); public function seeLoggerHasCritical(string $message, array $context = null); public function seeLoggerHasError(string $message, array $context = null); public function seeLoggerHasWarning(string $message, array $context = null); public function seeLoggerHasNotice(string $message, array $context = null); public function seeLoggerHasInfo(string $message, array $context = null); public function seeLoggerHasDebug(string $message, array $context = null);
Example
// matches all 'This is emergency' emergency messages, despite the context $I->seeLoggerHasEmergency('This is emergency'); // matches only message with the given context $I->seeLoggerHasEmergency('This is emergency with context', ['error' => 'This is context array']);
Check if specific message was not logged
When context is null only message is matched, and context is ignored. When context is array it will
be fully matched, along with the message.
public function dontSeeLoggerHasEmergency(string $message, array $context = null); public function dontSeeLoggerHasAlert(string $message, array $context = null); public function dontSeeLoggerHasCritical(string $message, array $context = null); public function dontSeeLoggerHasError(string $message, array $context = null); public function dontSeeLoggerHasWarning(string $message, array $context = null); public function dontSeeLoggerHasNotice(string $message, array $context = null); public function dontSeeLoggerHasInfo(string $message, array $context = null); public function dontSeeLoggerHasDebug(string $message, array $context = null);
Example
// fails if any 'This is emergency' emergency message was logged, despite the context $I->dontSeeLoggerHasEmergency('This is emergency'); // fails only when a message with the given content and context was logged $I->dontSeeLoggerHasEmergency('This is emergency with context', ['error' => 'This is context array']);
Check if any message was logged
public function seeLoggerHasAnyEmergency(); public function seeLoggerHasAnyAlert(); public function seeLoggerHasAnyCritical(); public function seeLoggerHasAnyError(); public function seeLoggerHasAnyWarning(); public function seeLoggerHasAnyNotice(); public function seeLoggerHasAnyInfo(); public function seeLoggerHasAnyDebug();
Check if no message was logged
public function dontSeeLoggerHasAnyEmergency(); public function dontSeeLoggerHasAnyAlert(); public function dontSeeLoggerHasAnyCritical(); public function dontSeeLoggerHasAnyError(); public function dontSeeLoggerHasAnyWarning(); public function dontSeeLoggerHasAnyNotice(); public function dontSeeLoggerHasAnyInfo(); public function dontSeeLoggerHasAnyDebug();
Check if message containing substring was logged
public function seeLoggerHasEmergencyThatContains(string $message); public function seeLoggerHasAlertThatContains(string $message); public function seeLoggerHasCriticalThatContains(string $message); public function seeLoggerHasErrorThatContains(string $message); public function seeLoggerHasWarningThatContains(string $message); public function seeLoggerHasNoticeThatContains(string $message); public function seeLoggerHasInfoThatContains(string $message); public function seeLoggerHasDebugThatContains(string $message);
Example:
// matches all emergency messages containing 'emergency' substring $I->seeLoggerHasEmergencyThatContains('emergency');
Check if message containing substring was not logged
public function dontSeeLoggerHasEmergencyThatContains(string $message); public function dontSeeLoggerHasAlertThatContains(string $message); public function dontSeeLoggerHasCriticalThatContains(string $message); public function dontSeeLoggerHasErrorThatContains(string $message); public function dontSeeLoggerHasWarningThatContains(string $message); public function dontSeeLoggerHasNoticeThatContains(string $message); public function dontSeeLoggerHasInfoThatContains(string $message); public function dontSeeLoggerHasDebugThatContains(string $message);
Example:
// fails is any emergency message containing 'emergency' substring was logged $I->dontSeeLoggerHasEmergencyThatContains('emergency');
Check if message matching regular expression was logged
public function seeLoggerHasEmergencyThatMatchesRegex(string $regex); public function seeLoggerHasAlertThatMatchesRegex(string $regex); public function seeLoggerHasCriticalThatMatchesRegex(string $regex); public function seeLoggerHasErrorThatMatchesRegex(string $regex); public function seeLoggerHasWarningThatMatchesRegex(string $regex); public function seeLoggerHasNoticeThatMatchesRegex(string $regex); public function seeLoggerHasInfoThatMatchesRegex(string $regex); public function seeLoggerHasDebugThatMatchesRegex(string $regex);
Example:
// matches all emergency messages passing regex '/emergency/i' $I->seeLoggerHasEmergencyThatMatchesRegex('/emergency/i');
Check if message matching regular expression was not logged
public function dontSeeLoggerHasEmergencyThatMatchesRegex(string $regex); public function dontSeeLoggerHasAlertThatMatchesRegex(string $regex); public function dontSeeLoggerHasCriticalThatMatchesRegex(string $regex); public function dontSeeLoggerHasErrorThatMatchesRegex(string $regex); public function dontSeeLoggerHasWarningThatMatchesRegex(string $regex); public function dontSeeLoggerHasNoticeThatMatchesRegex(string $regex); public function dontSeeLoggerHasInfoThatMatchesRegex(string $regex); public function dontSeeLoggerHasDebugThatMatchesRegex(string $regex);
Example:
// fails is any emergency message passing regex '/emergency/i was logged $I->dontSeeLoggerHasEmergencyThatMatchesRegex('emergency');
Check if message was logged using callback
public function seeLoggerHasEmergencyThatPasses(callable $matcher); public function seeLoggerHasAlertThatPasses(callable $matcher); public function seeLoggerHasCriticalThatPasses(callable $matcher); public function seeLoggerHasErrorThatPasses(callable $matcher); public function seeLoggerHasWarningThatPasses(callable $matcher); public function seeLoggerHasNoticeThatPasses(callable $matcher); public function seeLoggerHasInfoThatPasses(callable $matcher); public function seeLoggerHasDebugThatPasses(callable $matcher);
Example:
$I->seeLoggerHasEmergencyThatPasses(function ($record) { return $record['message'] === 'Test message' && $record['context']['error'] = 'Test error'; });
Check if message was not logged using callback
public function dontSeeLoggerHasEmergencyThatPasses(callable $matcher); public function dontSeeLoggerHasAlertThatPasses(callable $matcher); public function dontSeeLoggerHasCriticalThatPasses(callable $matcher); public function dontSeeLoggerHasErrorThatPasses(callable $matcher); public function dontSeeLoggerHasWarningThatPasses(callable $matcher); public function dontSeeLoggerHasNoticeThatPasses(callable $matcher); public function dontSeeLoggerHasInfoThatPasses(callable $matcher); public function dontSeeLoggerHasDebugThatPasses(callable $matcher);
Example:
$I->dontSeeLoggerHasEmergencyThatPasses(function ($record) { return $record['message'] === 'Test message' && $record['context']['error'] = 'Test error'; });
byteout/psr-logger-codeception-module 适用场景与选型建议
byteout/psr-logger-codeception-module 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.12k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2019 年 04 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「test」 「module」 「codeception」 「psr」 「psr-3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 byteout/psr-logger-codeception-module 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 byteout/psr-logger-codeception-module 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 byteout/psr-logger-codeception-module 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Testing Suite For Lumen like Laravel does.
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
Laravel 5.x.x library for integration Monolog Sentry
Specification-oriented BDD helpers for PHPUnit
Pacote simplificado para persistência de logs
Collection of tools to use the full power of the Enyalius framework
统计信息
- 总下载量: 1.12k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 26
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-22