briannesbitt/Carbon · error · RuntimeException
The test closure defined in {} at line {} returned {}; expec
Error message
The test closure defined in {} at line {} returned {}; expected Carbon\CarbonInterface|null What it means
Error "The test closure defined in {} at line {} returned {}; expected Carbon\CarbonInterface|null" thrown in briannesbitt/Carbon.
Source
Thrown at src/Carbon/Factory.php:689
}
public function handleTestNowClosure(
Closure|CarbonInterface|null $testNow,
DateTimeZone|string|int|null $timezone = null,
): ?CarbonInterface {
if ($testNow instanceof Closure) {
$callback = Callback::fromClosure($testNow);
$realNow = new DateTimeImmutable('now');
$testNow = $testNow($callback->prepareParameter($this->parse(
$realNow->format('Y-m-d H:i:s.u'),
$timezone ?? $realNow->getTimezone(),
)));
if ($testNow !== null && !($testNow instanceof DateTimeInterface)) {
$function = $callback->getReflectionFunction();
$type = \is_object($testNow) ? $testNow::class : \gettype($testNow);
throw new RuntimeException(
'The test closure defined in '.$function->getFileName().
' at line '.$function->getStartLine().' returned '.$type.
'; expected '.CarbonInterface::class.'|null',
);
}
if (!($testNow instanceof CarbonInterface)) {
$timezone ??= $this->useTimezoneFromTestNow
? $testNow->getTimezone()
: new CarbonTimeZone(date_default_timezone_get());
$testNow = $this->__call('instance', [$testNow, $timezone]);
}
}
if ($testNow !== null && $timezone === null) {
if ($testNow instanceof DateTime) {
$testNow = clone $testNow;
}View on GitHub (pinned to b13f05955d)
When it happens
Trigger: Thrown at src/Carbon/Factory.php:689 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of briannesbitt/Carbon@b13f05955d (2026-08-17).
Data as JSON: /api/errors/dedb0ae6576bf802.
Report an issue: GitHub.