Skip to content

Commit

Permalink
DefinitionSchema: better exception on empty definition
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Sep 29, 2021
1 parent cc7c4e7 commit 3c615cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/DI/Config/DefinitionSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ private function sniffType($key, array $def): string
} elseif (isset($def['imported'])) {
return Definitions\ImportedDefinition::class;

} elseif (!$def) {
throw new Nette\DI\InvalidConfigurationException("Service '$key': Empty definition.");

} else {
return Definitions\ServiceDefinition::class;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/DI/Compiler.missingDefinition.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ Assert::throws(function () {
services:
-
');
}, Nette\InvalidStateException::class, 'Factory and type are missing in definition of service.');
}, Nette\InvalidStateException::class, "Service '0': Empty definition.");


Assert::throws(function () {
createContainer(new DI\Compiler, '
services:
foo:
');
}, Nette\InvalidStateException::class, "Service 'foo': Factory and type are missing in definition of service.");
}, Nette\InvalidStateException::class, "Service 'foo': Empty definition.");

0 comments on commit 3c615cb

Please sign in to comment.