Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Mar 14, 2024
1 parent 1ca74ca commit 17c985a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/NotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}
Expand Down
18 changes: 13 additions & 5 deletions tests/Unit/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 17c985a

Please sign in to comment.