diff --git a/src/Expectation.php b/src/Expectation.php index ebfd63023..3951bc045 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -330,7 +330,7 @@ public function when(callable|bool $condition, callable $callback): self * @param array $parameters * @return Expectation|HigherOrderExpectation, 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 (! is_object($this->value) && method_exists(PendingArchExpectation::class, $method)) { @@ -355,6 +355,10 @@ public function __call(string $method, array $parameters): Expectation|HigherOrd $reflectionClosure = new \ReflectionFunction($closure); $expectation = $reflectionClosure->getClosureThis(); + if ($reflectionClosure->getReturnType()?->__toString() === ArchExpectation::class) { + return $closure(...$parameters); + } + assert(is_object($expectation)); ExpectationPipeline::for($closure)