hershel-theodore-layton/expect 问题修复 & 功能扩展

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

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

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: Hack

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-16