From 17c985a57fa9fd827e9b91687514301f86042c87 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 14 Mar 2024 12:06:20 +0300 Subject: [PATCH] fix --- src/NotFoundException.php | 4 ++-- tests/Unit/ContainerTest.php | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/NotFoundException.php b/src/NotFoundException.php index 72cb58a3..2616ce71 100644 --- a/src/NotFoundException.php +++ b/src/NotFoundException.php @@ -24,12 +24,12 @@ public function __construct( ) { if (empty($this->buildStack)) { $message = sprintf('No definition or class found or resolvable for "%s".', $id); - } elseif (count($this->buildStack) === 1) { + } elseif ($this->buildStack === [$id]) { $message = sprintf('No definition or class found or resolvable for "%s" while building it.', $id); } else { $message = sprintf( 'No definition or class found or resolvable for "%s" while building "%s".', - $id, + end($this->buildStack), implode('" -> "', $buildStack), ); } diff --git a/tests/Unit/ContainerTest.php b/tests/Unit/ContainerTest.php index 3e569466..f0de6d0f 100644 --- a/tests/Unit/ContainerTest.php +++ b/tests/Unit/ContainerTest.php @@ -1973,12 +1973,20 @@ public function testInvalidTags(string $message, array $tags): void new Container($config); } - public function testNotFoundExceptionMessageWithDefinitions(): void + public static function dataNotFoundExceptionMessageWithDefinitions(): array { - $config = ContainerConfig::create() - ->withDefinitions([ - SportCar::class => SportCar::class, - ]); + return [ + 'without-definition' => [[]], + 'with-definition' => [[SportCar::class => SportCar::class]], + ]; + } + + /** + * @dataProvider dataNotFoundExceptionMessageWithDefinitions + */ + public function testNotFoundExceptionMessageWithDefinitions(array $definitions): void + { + $config = ContainerConfig::create()->withDefinitions($definitions); $container = new Container($config); $this->expectException(NotFoundException::class);