feat: add support for toHaveMethod and toHaveMethods

This commit is contained in:
Owen Voke
2023-01-29 12:33:25 +00:00
parent bdff30b511
commit 60358461c4
5 changed files with 102 additions and 2 deletions

View File

@ -0,0 +1,28 @@
<?php
use PHPUnit\Framework\ExpectationFailedException;
$object = new class
{
public function foo(): void
{
}
};
test('pass', function () use ($object) {
expect($object)->toHaveMethod('foo')
->and($object)->toHaveMethod('foo')
->and($object)->not->toHaveMethod('fooNull');
});
test('failures', function () use ($object) {
expect($object)->toHaveMethod('bar');
})->throws(ExpectationFailedException::class);
test('failures with message', function () use ($object) {
expect($object)->toHaveMethod(name: 'bar', message: 'oh no!');
})->throws(ExpectationFailedException::class, 'oh no!');
test('not failures', function () use ($object) {
expect($object)->not->toHaveMethod('foo');
})->throws(ExpectationFailedException::class);