hhspecify / hhassert
针对 Hack 的简单断言库
0.2.0
2015-06-25 08:31 UTC
Requires
- hhvm: >=3.5.0
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-14 17:42:54 UTC
README
hhassert 是针对 Hack 的简单断言库。
您可以使用它作为 nodejs 的 assert 模块。
基本用法
它将在 use 关键字中指定 hhassert\Assert。
use hhassert\Assert; Assert::ok(1 === 1); //Passed Assert::ok("a" === "b"); //Failed Assert::equal("a", "a"); //Passed Assert::equal(1, 1); //Passed Assert::equal(1.0, 2.0); //Failed Assert::notEqual("a", "b"); //Passed Assert::notEqual("a", "a"); //Failed Assert::throws(() ==> { throw new InvalidArgumentException("exception!!"); }, InvalidArgumentException::class);
自定义匹配器
您可以在 configure 方法 中注册匹配器。匹配器在 lambda 表达式中指定。
Assert::configure((ContextBuilder $builder) ==> { $builder->registerMatcher('custom_matcher', (...) ==> { list($a, $b) = func_get_args(); if ($a !== $b) { throw new AssertionFailedException("custom matcher"); } }); }); Assert::custom_matcher("a", "b");
运行测试
composer install
composer test