hershel-theodore-layton/expect
最新稳定版本:v0.2.1
Composer 安装命令:
composer require hershel-theodore-layton/expect
包简介
Basic test assertions `expect(...)->toEqual('valid')`.
README 文档
README
Basic test assertions expect(...)->toEqual('valid').
This package replaces and is inspired by fbexpect.
Usage
You pass the expression under test to expect(...) as the first argument. The
returned object exposes some common assertions you'd want to make about a value,
such as ->toEqual(). The simplest test you could write is:
expect(1 + 1)->toEqual(2);
Customization
If your assertion is not included in the basic set, fear not. You can create
your own assertions object. Simply use the BasicAssertions trait in a class
and add methods specific to your project to it. For example:
use namespace HH\Lib\Str; use namespace HTL\Expect; final class MyAssertions<T> { use Expect\BasicAssertions<T>; public function __construct(private T $value)[] {} <<__Override>> protected function getValue()[]: T { return $this->value; } public function toThrowMyDomainExpection<<<__Enforceable>> reify T>( )[]: void where { try { ($this->value)(); throw new Expect\Surprise( 'Expected a MyDomainException to be thrown, but no exception was thrown.' ); } catch (\Exception $e) { if (!$e is T) { throw new Expect\Surprise(Str\format( 'Expected a MyDomainException to be thrown, but got %s instead.', \get_class($e), )); } } } }
Then create your own expect() function in your own namespace:
function expect(T $value)[]: MyAssertions<T> { return new MyAssertions($value); }
统计信息
- 总下载量: 3.26k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 9
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-16