wmde/psr-log-test-doubles 问题修复 & 功能扩展

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

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

wmde/psr-log-test-doubles

最新稳定版本:v3.4.0

Composer 安装命令:

composer require wmde/psr-log-test-doubles

包简介

Test Doubles for the PSR-3 Logger Interface

README 文档

README

Build Status codecov Type Coverage Latest Stable Version Download count

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 use log and provide a log level, or call a shortcut method such as error.
  • 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/log 2.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::getFirstLogCall convenience method
  • Changed minimum PHP version from PHP 7.0 to 7.1

2.1.0 (2017-01-17)

  • LogCalls now implements Countable

2.0.0 (2017-01-16)

  • LoggerSpy::getLogCalls now returns an instance of LogCalls, which is a collection of LogCall
  • 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

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 8
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 未知

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固