Allow custom arch expectations

This commit is contained in:
olivernybroe
2024-11-20 11:54:36 +01:00
parent 91afc81222
commit 5331b44a18

View File

@ -330,7 +330,7 @@ final class Expectation
* @param array<int, mixed> $parameters * @param array<int, mixed> $parameters
* @return Expectation<TValue>|HigherOrderExpectation<Expectation<TValue>, TValue> * @return Expectation<TValue>|HigherOrderExpectation<Expectation<TValue>, TValue>
*/ */
public function __call(string $method, array $parameters): Expectation|HigherOrderExpectation|PendingArchExpectation public function __call(string $method, array $parameters): Expectation|HigherOrderExpectation|PendingArchExpectation|ArchExpectation
{ {
if (! self::hasMethod($method)) { if (! self::hasMethod($method)) {
if (! is_object($this->value) && method_exists(PendingArchExpectation::class, $method)) { if (! is_object($this->value) && method_exists(PendingArchExpectation::class, $method)) {
@ -355,6 +355,10 @@ final class Expectation
$reflectionClosure = new \ReflectionFunction($closure); $reflectionClosure = new \ReflectionFunction($closure);
$expectation = $reflectionClosure->getClosureThis(); $expectation = $reflectionClosure->getClosureThis();
if ($reflectionClosure->getReturnType()?->__toString() === ArchExpectation::class) {
return $closure(...$parameters);
}
assert(is_object($expectation)); assert(is_object($expectation));
ExpectationPipeline::for($closure) ExpectationPipeline::for($closure)