hershel-theodore-layton / expect
Basic test assertions `expect(...)->toEqual('valid')`.
Package info
github.com/hershel-theodore-layton/expect
Language:Hack
pkg:composer/hershel-theodore-layton/expect
Requires
- hhvm: >=4.153
Requires (Dev)
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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
Use the BasicAssertions trait to add assertions specific to your project.
Implement getValue(), plus the trait's protected getThrown() and
withValue() methods. This example asserts that a numeric value is positive:
namespace MyProject\Tests; use namespace HTL\Expect; use type Throwable; final class MyAssertions<T> { use Expect\BasicAssertions<T>; public function __construct(private T $value)[] {} <<__Override>> public function getValue()[]: T { return $this->value; } <<__Override>> protected function getThrown()[]: ?Throwable { // This example wraps values, so it has no captured invocation failure. return null; } <<__Override>> protected function withValue<Tvalue>(Tvalue $value)[]: MyAssertions<Tvalue> { return new MyAssertions($value); } public function toBePositive()[]: this where T as num { return $this->toBeGreaterThan(0); } } function expect<T>(T $value)[]: MyAssertions<T> { return new MyAssertions($value); }