scriptfusion/pip 问题修复 & 功能扩展

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

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

scriptfusion/pip

Composer 安装命令:

composer require scriptfusion/pip

包简介

Immediately prints exceptions and assertion failures during testing.

README 文档

README

Pip

Latest version Total downloads Build status Test coverage

PHPUnit Immediate Printer

Pip is a PHPUnit extension that immediately prints exceptions and assertion failures during a test run. Normally PHPUnit keeps failure details secret until the end of the test run, but sometimes we don't want to wait that long. With Pip, all secrets are immediately revealed, with a few extra benefits, too.

Benefits

  • Display the name of each test case as it is executed.
  • Display the execution time of each test in configurable, tiered colour bands.
  • Immediately print exceptions, assertion failures, warnings, notice and deprecation messages as they occur.
  • Flawless test suite indicator: success dot turns to red exclamation mark if any prior tests failed. Useful for CI consoles without a scrollback buffer.

Preview

The following preview is somewhat atypical but shows all supported output cases at once. Of course, we expect all your tests to be mostly green!

Preview image

Pip makes no attempt to modify the test summary; only runtime output is changed.

Usage

  1. Add the dependency to your Composer file's require-dev section.

    composer require --dev scriptfusion/pip
  2. Declare the printer extension in your phpunit.xml configuration file.

    <extensions>
        <bootstrap class="ScriptFUSION\Pip\PipExtension"/>
    </extensions>
  3. Run the tests!

    vendor/bin/phpunit
  4. Enjoy immediate test execution feedback.

Configuration

Pip's behaviour can be customized by adding <parameter> nodes as children of the <bootstrap> node in phpunit.xml, with name and value attributes corresponding to the table below.

Parameter name Default value Description
perf.slow 200 (ms) Sets the performance threshold for slow (yellow) tests.
perf.vslow 1000 (ms) Sets the performance threshold for very slow (red) tests.
test.dp.args true True to show the arguments passed by the data provider, false to hide.
test.name.strip '' Strips the specified matching portion of the test name.

Requirements

Pip version PHPUnit versions Minimum PHP version
3 10 / 11 / 12 / 13 8.1 / 8.2 / 8.3 / 8.4
2 yanked -
1 5 / 6 5.6 / 7.0

Testing Pip

To run the full test suite, use the following command.

composer test

Pip's capabilities are exploited via CapabilitiesTest. However, this test file isn't run directly because many of these tests are designed to fail. Instead, we write tests that run PHPUnit internally, each of which invokes one of the capability test cases and verifies its output. To run CapabilitiesTest, specify the following command

composer test test/CapabilitiesTest.php

The real tests, also known as functional tests, are located in test/functional, written in PHPT format. PHPT is a scarcely documented format designed to support testing PHP itself. An undocumented feature of PHPUnit is its limited support for a subset of the PHPT test specification, which we exploit to test PHPUnit itself with our printer implementation loaded.

Writing functional tests

To test the output of a particular capability we run CapabilitiesTest with the --filter option to target a specific test case. Each functional test contains the arguments passed to PHPUnit in the --ARGS-- section of the file. These arguments can be pasted directly after the PHPUnit command to see the resulting output from that test case. We verify the output in the --EXPECTF-- section of the file.

One challenge we must overcome is verifying coloured output including ANSI escape sequences. To see these escape sequences we can pipe the output of a specific capability test to cat -v as shown in the following example.

vendor/bin/phpunit -c test --colors=always test/CapabilitiesTest.php --filter ::testSuccess$ | cat -v

The output from cat will print the "escape" character as ^[. We must replace each occurrence of this character sequence with the literal escape character (ASCII character 27). The easiest way to obtain the real escape character is to just copy it from an existing functional test.

Create a new functional test by copying an existing test as a template, then modify the PHPUnit arguments and the expected output to match what we expect using the techniques just described. Don't forget to give the test a clear description in the --TEST-- section!

Inspiration

Thanks to the following open source projects that inspired this project.

scriptfusion/pip 适用场景与选型建议

scriptfusion/pip 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 69.73k 次下载、GitHub Stars 达 50, 最近一次更新时间为 2024 年 07 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 scriptfusion/pip 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 scriptfusion/pip 我们能提供哪些服务?
定制开发 / 二次开发

基于 scriptfusion/pip 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 69.73k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 50
  • 点击次数: 28
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 50
  • Watchers: 4
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-only
  • 更新时间: 2024-07-18