diff --git a/packages/container/src/GenericContainer.php b/packages/container/src/GenericContainer.php index 752fca8f2..213ade111 100644 --- a/packages/container/src/GenericContainer.php +++ b/packages/container/src/GenericContainer.php @@ -653,7 +653,7 @@ private function clone(): self private function resolveChain(): DependencyChain { if (! $this->chain instanceof DependencyChain) { - $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, limit: 2); $this->chain = new DependencyChain($trace[1]['file'] . ':' . $trace[1]['line']); } diff --git a/packages/container/tests/ContainerTest.php b/packages/container/tests/ContainerTest.php index 4de232ba8..5e3b23b8c 100644 --- a/packages/container/tests/ContainerTest.php +++ b/packages/container/tests/ContainerTest.php @@ -447,6 +447,16 @@ public function call_function_with_unresolvable_parameters(): void $container->invoke(fn (string $param) => $param); } + #[Test] + public function dependency_chain_reports_the_call_site_as_its_origin(): void + { + $this->expectException(DependencyCouldNotBeAutowired::class); + $this->expectExceptionMessageMatches('/Originally called in .*ContainerTest\.php:\d+/'); + + $container = new GenericContainer(); + $container->get(ContainerObjectC::class); + } + #[Test] public function call_invalid_closure(): void {