testomat / phpunit-printer
:crystal_ball: PHPUnit 打印机,断言等...
Requires
- php: ^7.3
- narrowspark/exception-inspector: ^1.0.2
- ondram/ci-detector: ^3.3
- phpunit/php-timer: ^2.1.2 || ^3.0.0
- testomat/phpunit-common: ^1.0.0
- testomat/terminal-colour: ^1.1.0
Suggests
- phpunit/phpunit: Required to use this printer (^8.0.0 || ^9.0.0).
This package is auto-updated.
Last update: 2024-02-26 09:49:23 UTC
README
提供 PHPUnit 打印机类,具有
- 美观的错误报告
- 慢速运行的测试报告
- 过度断言的测试报告
- 提供美观的文本覆盖率输出
- 提供紧凑和扩展的测试运行器视图输出
安装
运行
$ composer require testomat/phpunit-printer
使用
通过将以下内容添加到您的 phpunit.xml
或 phpunit.xml.dist
文件中启用打印机:
<phpunit printerClass="Testomat\PHPUnit\Printer\Printer"> </phpunit>
现在正常运行您的测试套件。
配置
在配置文件 testomat.xml
中,可以向打印机传递多个选项。
首先在您项目的根目录中创建一个 testomat.xml
,并将其内容复制进去。
<?xml version="1.0" encoding="UTF-8"?> <testomat xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/testomat/phpunit-common/Schema/testomat.xsd" > ... printer configuration </testomat>
打印机设置
打印机包含两种打印机视图 expanded
和 compact
(默认)。要更改打印机视图,请使用 type
参数。
<printer type="expanded"/>
要更改 PHPUnit 打印机打印的错误方式,请使用 show_error_on
选项。
<printer show_error_on="end"/>
要打印失败的测试后的错误,请使用 show_error_on="test"
,默认是在测试运行器完成后打印错误。
注意:打印机支持所有 PHPUnit stopOn... 设置。
要减少美观错误输出中的异常跟踪,请使用 <exclude>...</exclude>
参数。
<printer> <exclude> <directory>vendor/phpunit/phpunit/src</directory> <directory>vendor/mockery/mockery</directory> </exclude> </printer>
注意:PHPUnit 和 Mockery 的异常跟踪默认被过滤掉。
速度陷阱设置
默认情况下,速度陷阱收集器处于活动状态,要停用速度陷阱,请使用 enabled="false"
。
<speedtrap enabled="false"/>
要将整体套件阈值从 500
(默认)更改为更高的值,请使用 <slow_threshold>500</slow_threshold>
参数。
<speedtrap> <slow_threshold>1000</slow_threshold> </speedtrap>
或 PHPUnit 注释,可以在测试类或测试方法上添加 @slowThreshold
注释来覆盖任何套件或组阈值
/** * @slowThreshold 2000 */ class SomeTestCase extends \PHPUnit\Framework\TestCase { /** * @slowThreshold 5000 */ public function testLongRunningProcess() { } }
要更改默认的速度陷阱报告长度(10个最低测试),请使用 <report_length>10</report_length>
参数。
<speedtrap> <report_length>20</report_length> </speedtrap>
过度断言设置
默认情况下,过度断言收集器处于活动状态,要停用过度断言,请使用 enabled="false"
。
<over_assertive enabled="true"/>
要将整体套件的断言从 10
(默认)更改为更高的值,请使用 <threshold>10</threshold>
参数。
<over_assertive> <threshold>15</threshold> </over_assertive>
或 PHPUnit 注释,可以在测试类或测试方法上添加 @assertionThreshold
注释来覆盖任何套件或组阈值
/** * @assertionThreshold 15 */ class SomeTestCase extends \PHPUnit\Framework\TestCase { /** * @assertionThreshold 20 */ public function testLongRunningProcess() { self::assertTrue(true); ... } }
要更改默认的过度断言报告长度(每个测试10个断言),请使用 <report_length>10</report_length>
参数。
<over_assertive> <report_length>20</report_length> </over_assertive>
版本控制
该库遵循语义化版本控制,代码规则集的更新将在主要版本中进行。
变更日志
请参阅CHANGELOG.md
。
贡献
请参阅CONTRIBUTING.md
。
行为准则
许可
本软件包使用MIT许可证授权。
请参阅LICENSE.md
。