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

@ -302,6 +302,36 @@ final class Expectation
return $this;
}
/**
* Asserts that the value has the method $name.
*
* @return self<TValue>
*/
public function toHaveMethod(string $name, string $message = ''): self
{
$this->toBeObject();
// @phpstan-ignore-next-line
Assert::assertTrue(method_exists($this->value, $name), $message);
return $this;
}
/**
* Asserts that the value has the provided methods $names.
*
* @param iterable<array-key, string> $names
* @return self<TValue>
*/
public function toHaveMethods(iterable $names, string $message = ''): self
{
foreach ($names as $name) {
$this->toHaveMethod($name, message: $message);
}
return $this;
}
/**
* Asserts that two variables have the same value.
*