dmx/phpunit-ext

PHPUnit 框架的约束、断言和测试用例集合。

2.0.0 2023-01-31 12:07 UTC

This package is auto-updated.

Last update: 2024-09-29 04:43:28 UTC


README

PHPUnit 框架的约束、断言和测试用例集合。

更多信息请访问 https://phpunit.de

要求

  • PHP >= 7.4
  • Composer >= 1.5
  • phpunit >= 7.0

安装

使用 composer 在项目中安装并使用此包。

使用以下命令安装:

composer require "dmx/phpunit-ext"

然后您就可以开始使用了!

使用方法

最方便的使用额外约束和资源的方法是从 DMX\PHPUnit\Framework\TestCase 继承您的测试用例类。

现在您可以在测试中使用以下约束和资源。

断言

assertIsClosure

assertIsClosure(mixed $actual [, string $message = '']): void

如果 $actual 不是 \Closure 的实例,则通过 $message 报告错误。

示例

$actual = function () {
    return 'Foo.Bar';
}

$this->assertIsClosure($actual);

assertClosure

assertClosure(mixed $expectedReturnValue, mixed $actual [, string $message = '']): void

如果 $actual 不是 \Closure 的实例或者指定的闭包的返回值不匹配 $expectedReturnValue,则通过 $message 报告错误。

示例

$actual = function () {
    return 'Foo.Bar';
}
$expectedReturnValue = 'Foo.Bar';

$this->assertClosure($expectedReturnValue, $actual);

assertCarbon

assertCarbon(mixed $expectedDateTime, mixed $actual [, int $epsilon = 0, string $message = '']): void

如果 $actual 与 $expectedCarbon 不匹配,则通过 $message 报告错误。如果设置了 $epsilon,则 $actual 的值可以相对于 epsilon 定义的秒数有差异。

示例

$expected = '2018-10-22 14:00:00';
$actual = '2018-10-22 14:00:05';

$this->assertCarbon($expected, $actual, 10);

开发 - 入门指南

查看 CONTRIBUTING 文件。

变更日志

查看 CHANGELOG 文件。