一个具有 Rspec 风格的 PHP 单元测试库

dev-master 2018-04-27 12:41 UTC

This package is not auto-updated.

Last update: 2024-09-22 04:12:49 UTC


README

一个具有 Rspec 风格的 PHP 单元测试库。

[开发中]

示例

use Acro5piano\Pest\Spec;

function add(int $x, int $y)
{
    return $x + $y;
}

Spec::describe('add', function ($it) {
    $it('returns 3 given 1, 2', function ($expect) {
        $expect(add(1, 2))->toBe(3);
    });
    $it('a failing test', function ($expect) {
        $expect(add(1, 2))->toBe(4);
    });
});

结果

image

文档

安装

composer require --dev acro5piano/pest

分组

你可以使用类型提示进行嵌套。

use Acro5piano\Pest\Describe;

Spec::describe('1: first describe', function (Describe $describe) {
    $describe('2: second describe', function ($it) {
        $it('3: finally it comes', function ($expect) {
            $expect([1, 2])->not()->toContain(1);
        });
    });
});

结果

Failed
  1: first describe
      2: second describe
            3: finally it comes

断言

  • toBe
  • toContain

not() 取反条件。例如)

$expect([1, 2])->not()->toContain(3); // -> Fails