{"record":{"id":"dedb0ae6576bf802","repo":"briannesbitt/Carbon","slug":"the-test-closure-defined-in-at-line-returned","errorCode":null,"errorMessage":"The test closure defined in {} at line {} returned {}; expected Carbon\\CarbonInterface|null","messagePattern":"The test closure defined in (.+?) at line (.+?) returned (.+?); expected Carbon\\\\CarbonInterface\\|null","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Carbon/Factory.php","lineNumber":689,"sourceCode":"    }\n\n    public function handleTestNowClosure(\n        Closure|CarbonInterface|null $testNow,\n        DateTimeZone|string|int|null $timezone = null,\n    ): ?CarbonInterface {\n        if ($testNow instanceof Closure) {\n            $callback = Callback::fromClosure($testNow);\n            $realNow = new DateTimeImmutable('now');\n            $testNow = $testNow($callback->prepareParameter($this->parse(\n                $realNow->format('Y-m-d H:i:s.u'),\n                $timezone ?? $realNow->getTimezone(),\n            )));\n\n            if ($testNow !== null && !($testNow instanceof DateTimeInterface)) {\n                $function = $callback->getReflectionFunction();\n                $type = \\is_object($testNow) ? $testNow::class : \\gettype($testNow);\n\n                throw new RuntimeException(\n                    'The test closure defined in '.$function->getFileName().\n                    ' at line '.$function->getStartLine().' returned '.$type.\n                    '; expected '.CarbonInterface::class.'|null',\n                );\n            }\n\n            if (!($testNow instanceof CarbonInterface)) {\n                $timezone ??= $this->useTimezoneFromTestNow\n                    ? $testNow->getTimezone()\n                    : new CarbonTimeZone(date_default_timezone_get());\n                $testNow = $this->__call('instance', [$testNow, $timezone]);\n            }\n        }\n\n        if ($testNow !== null && $timezone === null) {\n            if ($testNow instanceof DateTime) {\n                $testNow = clone $testNow;\n            }","sourceCodeStart":671,"sourceCodeEnd":707,"githubUrl":"https://github.com/briannesbitt/Carbon/blob/b13f05955dcfd7da71d60af745fd148cbdb73505/src/Carbon/Factory.php#L671-L707","documentation":"Error \"The test closure defined in {} at line {} returned {}; expected Carbon\\CarbonInterface|null\" thrown in briannesbitt/Carbon.","triggerScenarios":"Thrown at src/Carbon/Factory.php:689 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b13f05955dcfd7da71d60af745fd148cbdb73505","analyzedAt":"2026-08-17T04:40:56.953Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}