From f3608c4d8684c880c2af0cf7b4d2b7143bc459b0 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 3 Feb 2021 21:46:54 +0100 Subject: [PATCH] improved style of error messages WIP --- src/DI/Extensions/InjectExtension.php | 4 +- src/DI/Resolver.php | 18 ++-- tests/DI/Compiler.functions.phpt | 4 +- tests/DI/Compiler.generatedFactory.phpt | 9 +- tests/DI/Compiler.missingDefinition.phpt | 3 +- .../ContainerBuilder.autowiring.novalue.phpt | 6 +- tests/DI/ContainerBuilder.error.phpt | 6 +- tests/DI/ContainerBuilder.factory.error.phpt | 95 ++++++++++++++----- ...erBuilder.factory.resolveBuiltinTypes.phpt | 9 +- tests/DI/ContainerBuilder.recursive.phpt | 3 +- tests/DI/ContainerBuilder.selfdependency.phpt | 4 +- ...efinitions.AccessorDefinition.resolve.phpt | 6 +- ...Definitions.FactoryDefinition.resolve.phpt | 3 +- tests/DI/InjectExtension.errors.phpt | 6 +- .../DI/Resolver.autowireArguments.errors.phpt | 6 +- 15 files changed, 124 insertions(+), 58 deletions(-) diff --git a/src/DI/Extensions/InjectExtension.php b/src/DI/Extensions/InjectExtension.php index bfab4c17d..94443a698 100644 --- a/src/DI/Extensions/InjectExtension.php +++ b/src/DI/Extensions/InjectExtension.php @@ -153,9 +153,9 @@ private static function checkType( if (!$type) { throw new Nette\InvalidStateException("Property $propName has no type hint."); } elseif (!class_exists($type) && !interface_exists($type)) { - throw new Nette\InvalidStateException("Class or interface '$type' used in type hint at $propName not found. Check type and 'use' statements."); + throw new Nette\InvalidStateException("Class or interface '$type' used in type hint at $propName not found.\nCheck type and 'use' statements."); } elseif ($container && !$container->getByType($type, false)) { - throw new Nette\DI\MissingServiceException("Service of type $type used in type hint at $propName not found. Did you add it to configuration file?"); + throw new Nette\DI\MissingServiceException("Service of type $type used in type hint at $propName not found.\nDid you add it to configuration file?"); } } } diff --git a/src/DI/Resolver.php b/src/DI/Resolver.php index ef8f1d02c..6713b59fd 100644 --- a/src/DI/Resolver.php +++ b/src/DI/Resolver.php @@ -269,8 +269,8 @@ public function completeStatement(Statement $statement, bool $currentServiceAllo try { $arguments = $this->completeArguments($arguments); } catch (ServiceCreationException $e) { - if (!str_contains($e->getMessage(), ' (used in')) { - $e->setMessage($e->getMessage() . " (used in {$this->entityToString($entity)})"); + if (!str_contains($e->getMessage(), "\nUsed in")) { + $e->setMessage($e->getMessage() . "\nUsed in {$this->entityToString($entity)}."); } throw $e; } @@ -404,18 +404,18 @@ public function addDependency(\ReflectionClass|\ReflectionFunctionAbstract|strin private function completeException(\Exception $e, Definition $def): ServiceCreationException { - if ($e instanceof ServiceCreationException && Strings::startsWith($e->getMessage(), "Service '")) { + if ($e instanceof ServiceCreationException && Strings::startsWith($e->getMessage(), "(Service '")) { return $e; } $name = $def->getName(); $type = $def->getType(); if ($name && !ctype_digit($name)) { - $message = "Service '$name'" . ($type ? " (type of $type)" : '') . ': '; + $message = "(Service '$name'" . ($type ? " of type $type" : '') . ")\n"; } elseif ($type) { - $message = "Service of type $type: "; + $message = "(Service of type $type)\n"; } elseif ($def instanceof Definitions\ServiceDefinition && $def->getEntity()) { - $message = 'Service (' . $this->entityToString($def->getEntity()) . '): '; + $message = '(Service ' . $this->entityToString($def->getEntity()) . ")\n"; } else { $message = ''; } @@ -541,14 +541,14 @@ private static function autowireArgument(\ReflectionParameter $parameter, callab } catch (MissingServiceException $e) { $res = null; } catch (ServiceCreationException $e) { - throw new ServiceCreationException("{$e->getMessage()} (needed by $desc)", 0, $e); + throw new ServiceCreationException($e->getMessage() . "\nNeeded by $desc.", 0, $e); } if ($res !== null || $parameter->allowsNull()) { return $res; } elseif (class_exists($type) || interface_exists($type)) { - throw new ServiceCreationException("Service of type $type needed by $desc not found. Did you add it to configuration file?"); + throw new ServiceCreationException("Service of type $type needed by $desc not found.\nDid you add it to configuration file?"); } else { - throw new ServiceCreationException("Class $type needed by $desc not found. Check type hint and 'use' statements."); + throw new ServiceCreationException("Class $type needed by $desc not found.\nCheck type hint and 'use' statements."); } } elseif ( diff --git a/tests/DI/Compiler.functions.phpt b/tests/DI/Compiler.functions.phpt index bf027462e..15881449b 100644 --- a/tests/DI/Compiler.functions.phpt +++ b/tests/DI/Compiler.functions.phpt @@ -85,4 +85,6 @@ Assert::exception(function () { services: - Service(bool(123, 10)) '); -}, Nette\InvalidStateException::class, 'Service of type Service: Function bool() expects at most 1 parameter, 2 given. (used in __construct())'); +}, Nette\InvalidStateException::class, '(Service of type Service) +Function bool() expects at most 1 parameter, 2 given. +Used in __construct().'); diff --git a/tests/DI/Compiler.generatedFactory.phpt b/tests/DI/Compiler.generatedFactory.phpt index 3a63e05d7..08cb09bf6 100644 --- a/tests/DI/Compiler.generatedFactory.phpt +++ b/tests/DI/Compiler.generatedFactory.phpt @@ -294,7 +294,8 @@ Assert::exception(function () { ->getResultDefinition() ->setFactory('Bad1'); $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of Bad2): Type hint for \$bar in create() doesn't match type hint in Bad1 constructor."); +}, Nette\InvalidStateException::class, "(Service 'one' of type Bad2) +Type hint for \$bar in create() doesn't match type hint in Bad1 constructor."); @@ -317,7 +318,8 @@ Assert::exception(function () { ->getResultDefinition() ->setFactory('Bad3'); $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of Bad4): Unused parameter \$baz when implementing method create(), did you mean \$bar?"); +}, Nette\InvalidStateException::class, "(Service 'one' of type Bad4) +Unused parameter \$baz when implementing method create(), did you mean \$bar?"); @@ -340,7 +342,8 @@ Assert::exception(function () { ->getResultDefinition() ->setFactory('Bad5'); $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of Bad6): Unused parameter \$baz when implementing method create()."); +}, Nette\InvalidStateException::class, "(Service 'one' of type Bad6) +Unused parameter \$baz when implementing method create()."); diff --git a/tests/DI/Compiler.missingDefinition.phpt b/tests/DI/Compiler.missingDefinition.phpt index d98187b47..b03888158 100644 --- a/tests/DI/Compiler.missingDefinition.phpt +++ b/tests/DI/Compiler.missingDefinition.phpt @@ -22,4 +22,5 @@ Assert::throws(function () { services: foo: '); -}, Nette\InvalidStateException::class, "Service 'foo': Factory and type are missing in definition of service."); +}, Nette\InvalidStateException::class, "(Service 'foo') +Factory and type are missing in definition of service."); diff --git a/tests/DI/ContainerBuilder.autowiring.novalue.phpt b/tests/DI/ContainerBuilder.autowiring.novalue.phpt index 43bb07788..22da601ed 100644 --- a/tests/DI/ContainerBuilder.autowiring.novalue.phpt +++ b/tests/DI/ContainerBuilder.autowiring.novalue.phpt @@ -24,7 +24,8 @@ Assert::exception(function () { $builder = new DI\ContainerBuilder; $builder->addDefinition('foo')->setType('Foo'); $container = createContainer($builder); -}, Nette\DI\ServiceCreationException::class, "Service 'foo' (type of Foo): Parameter \$x in __construct() has no class type hint and no default value, so its value must be specified."); +}, Nette\DI\ServiceCreationException::class, "(Service 'foo' of type Foo) +Parameter \$x in __construct() has no class type hint or default value, so its value must be specified."); class Bar @@ -38,7 +39,8 @@ Assert::exception(function () { $builder = new DI\ContainerBuilder; $builder->addDefinition('foo')->setType('Bar'); $container = createContainer($builder); -}, Nette\DI\ServiceCreationException::class, "Service 'foo' (type of Bar): Parameter \$x in __construct() has no class type hint and no default value, so its value must be specified."); +}, Nette\DI\ServiceCreationException::class, "(Service 'foo' of type Bar) +Parameter \$x in __construct() has no class type hint or default value, so its value must be specified."); class Bar2 diff --git a/tests/DI/ContainerBuilder.error.phpt b/tests/DI/ContainerBuilder.error.phpt index b78631f2b..533e55fdd 100644 --- a/tests/DI/ContainerBuilder.error.phpt +++ b/tests/DI/ContainerBuilder.error.phpt @@ -20,7 +20,8 @@ $builder->addDefinition('one') Assert::exception(function () use ($builder) { $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of stdClass): Expected function, method or property name, '1234' given."); +}, Nette\InvalidStateException::class, "(Service 'one' of type stdClass) +Expected function, method or property name, '1234' given."); @@ -43,4 +44,5 @@ $builder->addDefinition('one') Assert::exception(function () use ($builder) { $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of stdClass): Missing argument for \$prop[]."); +}, Nette\InvalidStateException::class, "(Service 'one' of type stdClass) +Missing argument for \$prop[]."); diff --git a/tests/DI/ContainerBuilder.factory.error.phpt b/tests/DI/ContainerBuilder.factory.error.phpt index cd42e7a5b..adb2ebc56 100644 --- a/tests/DI/ContainerBuilder.factory.error.phpt +++ b/tests/DI/ContainerBuilder.factory.error.phpt @@ -25,7 +25,8 @@ Assert::exception(function () { $builder = new DI\ContainerBuilder; $builder->addDefinition(null)->setFactory('Unknown'); $builder->complete(); -}, Nette\DI\ServiceCreationException::class, 'Service (Unknown::__construct()): Class Unknown not found.'); +}, Nette\DI\ServiceCreationException::class, '(Service Unknown::__construct()) +Class Unknown not found.'); Assert::exception(function () { @@ -33,7 +34,8 @@ Assert::exception(function () { $builder->addDefinition('one')->setFactory('@two'); $builder->addDefinition('two')->setFactory('Unknown'); $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'two': Class Unknown not found."); +}, Nette\InvalidStateException::class, "(Service 'two') +Class Unknown not found."); Assert::exception(function () { @@ -41,21 +43,24 @@ Assert::exception(function () { $builder->addDefinition('one')->setFactory(new Reference('two')); $builder->addDefinition('two')->setFactory('Unknown'); $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'two': Class Unknown not found."); +}, Nette\InvalidStateException::class, "(Service 'two') +Class Unknown not found."); Assert::exception(function () { $builder = new DI\ContainerBuilder; $builder->addDefinition('one')->setFactory('stdClass::foo'); $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one': Method stdClass::foo() is not callable."); +}, Nette\InvalidStateException::class, "(Service 'one') +Method stdClass::foo() is not callable."); Assert::exception(function () { $builder = new DI\ContainerBuilder; $builder->addDefinition('one')->setFactory('Nette\DI\Container::foo'); // has __magic $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one': Method Nette\\DI\\Container::foo() is not callable."); +}, Nette\InvalidStateException::class, "(Service 'one') +Method Nette\\DI\\Container::foo() is not callable."); Assert::exception(function () { @@ -76,7 +81,8 @@ Assert::exception(function () { $builder->addFactoryDefinition('one') ->setImplement('Bad4'); $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of Bad4): Method create() has not return type hint or annotation @return."); +}, Nette\InvalidStateException::class, "(Service 'one' of type Bad4) +Method create() has not return type hint or annotation @return."); interface Bad5 @@ -103,7 +109,8 @@ Assert::exception(function () { $builder = new DI\ContainerBuilder; $builder->addDefinition('one')->setFactory('Bad6::create'); $builder->complete(); -}, Nette\DI\ServiceCreationException::class, "Service 'one': Method Bad6::create() is not callable."); +}, Nette\DI\ServiceCreationException::class, "(Service 'one') +Method Bad6::create() is not callable."); class Bad7 @@ -117,7 +124,8 @@ Assert::exception(function () { $builder = new DI\ContainerBuilder; $builder->addDefinition('one')->setFactory('Bad7::create'); $builder->complete(); -}, Nette\DI\ServiceCreationException::class, "Service 'one': Unknown service type, specify it or declare return type of factory."); +}, Nette\DI\ServiceCreationException::class, "(Service 'one') +Unknown service type, specify it or declare return type of factory."); class Bad8 @@ -131,7 +139,8 @@ Assert::exception(function () { $builder = new DI\ContainerBuilder; $builder->addDefinition('one')->setType('Bad8'); $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of Bad8): Class Bad8 has private constructor."); +}, Nette\InvalidStateException::class, "(Service 'one' of type Bad8) +Class Bad8 has private constructor."); class Good @@ -146,14 +155,18 @@ Assert::exception(function () { $builder = new DI\ContainerBuilder; $builder->addDefinition('one')->setFactory('Good', [new Statement('Unknown')]); $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of Good): Class Unknown not found. (used in __construct())"); +}, Nette\InvalidStateException::class, "(Service 'one' of type Good) +Class Unknown not found. +Used in __construct()."); // fail in argument Assert::exception(function () { $builder = new DI\ContainerBuilder; $builder->addDefinition('one')->setFactory('Good', [new Statement('Bad8')]); $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of Good): Class Bad8 has private constructor. (used in __construct())"); +}, Nette\InvalidStateException::class, "(Service 'one' of type Good) +Class Bad8 has private constructor. +Used in __construct()."); abstract class Bad9 @@ -168,7 +181,8 @@ Assert::exception(function () { $builder = new DI\ContainerBuilder; $builder->addDefinition('one')->setType('Bad9'); $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of Bad9): Class Bad9 is abstract."); +}, Nette\InvalidStateException::class, "(Service 'one' of type Bad9) +Class Bad9 is abstract."); trait Bad10 @@ -183,7 +197,8 @@ Assert::exception(function () { $builder = new DI\ContainerBuilder; $builder->addDefinition('one')->setFactory('Bad10::method'); $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one': Method Bad10::method() is not callable."); +}, Nette\InvalidStateException::class, "(Service 'one') +Method Bad10::method() is not callable."); class ConstructorParam @@ -208,7 +223,9 @@ services: b: stdClass bad: ConstructorParam '); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of ConstructorParam): Multiple services of type stdClass found: a, b (needed by \$x in __construct())"); +}, Nette\DI\ServiceCreationException::class, "(Service 'bad' of type ConstructorParam) +Multiple services of type stdClass found: a, b +Needed by \$x in __construct()."); // forced autowiring fail @@ -219,7 +236,9 @@ services: b: stdClass bad: ConstructorParam(@\stdClass) '); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of ConstructorParam): Multiple services of type stdClass found: a, b (used in __construct())"); +}, Nette\DI\ServiceCreationException::class, "(Service 'bad' of type ConstructorParam) +Multiple services of type stdClass found: a, b +Used in __construct()."); // autowiring fail in chain @@ -230,7 +249,9 @@ services: b: stdClass bad: MethodParam()::foo() '); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of MethodParam): Multiple services of type stdClass found: a, b (needed by \$x in foo())"); +}, Nette\DI\ServiceCreationException::class, "(Service 'bad' of type MethodParam) +Multiple services of type stdClass found: a, b +Needed by \$x in foo()."); // forced autowiring fail in chain @@ -241,7 +262,9 @@ services: b: stdClass bad: MethodParam()::foo(@\stdClass) '); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of MethodParam): Multiple services of type stdClass found: a, b (used in foo())"); +}, Nette\DI\ServiceCreationException::class, "(Service 'bad' of type MethodParam) +Multiple services of type stdClass found: a, b +Used in foo()."); // autowiring fail in argument @@ -252,7 +275,10 @@ services: b: stdClass bad: Good(ConstructorParam()) '); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of Good): Multiple services of type stdClass found: a, b (needed by \$x in ConstructorParam::__construct()) (used in __construct())"); +}, Nette\DI\ServiceCreationException::class, "(Service 'bad' of type Good) +Multiple services of type stdClass found: a, b +Needed by \$x in ConstructorParam::__construct(). +Used in __construct()."); // forced autowiring fail in argument @@ -263,7 +289,9 @@ services: b: stdClass bad: Good(ConstructorParam(@\stdClass)) '); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of Good): Multiple services of type stdClass found: a, b (used in ConstructorParam::__construct())"); +}, Nette\DI\ServiceCreationException::class, "(Service 'bad' of type Good) +Multiple services of type stdClass found: a, b +Used in ConstructorParam::__construct()."); // autowiring fail in chain in argument @@ -274,7 +302,10 @@ services: b: stdClass bad: Good(MethodParam()::foo()) '); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of Good): Multiple services of type stdClass found: a, b (needed by \$x in MethodParam::foo()) (used in __construct())"); +}, Nette\DI\ServiceCreationException::class, "(Service 'bad' of type Good) +Multiple services of type stdClass found: a, b +Needed by \$x in MethodParam::foo(). +Used in __construct()."); // forced autowiring fail in chain in argument @@ -285,7 +316,9 @@ services: b: stdClass bad: Good(MethodParam()::foo(@\stdClass)) '); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of Good): Multiple services of type stdClass found: a, b (used in foo())"); +}, Nette\DI\ServiceCreationException::class, "(Service 'bad' of type Good) +Multiple services of type stdClass found: a, b +Used in foo()."); // forced autowiring fail in property passing @@ -299,7 +332,9 @@ services: setup: - $a = @\stdClass '); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of Good): Multiple services of type stdClass found: a, b (used in @bad::\$a)"); +}, Nette\DI\ServiceCreationException::class, "(Service 'bad' of type Good) +Multiple services of type stdClass found: a, b +Used in @bad::\$a."); // autowiring fail in rich property passing @@ -313,7 +348,9 @@ services: setup: - $a = MethodParam()::foo(@\stdClass) '); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of Good): Multiple services of type stdClass found: a, b (used in foo())"); +}, Nette\DI\ServiceCreationException::class, "(Service 'bad' of type Good) +Multiple services of type stdClass found: a, b +Used in foo()."); // autowiring fail in method calling @@ -327,7 +364,9 @@ services: setup: - foo '); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of MethodParam): Multiple services of type stdClass found: a, b (needed by \$x in foo())"); +}, Nette\DI\ServiceCreationException::class, "(Service 'bad' of type MethodParam) +Multiple services of type stdClass found: a, b +Needed by \$x in foo()."); // forced autowiring fail in method calling @@ -341,7 +380,9 @@ services: setup: - bar(@\stdClass) '); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of Good): Multiple services of type stdClass found: a, b (used in @bad::bar())"); +}, Nette\DI\ServiceCreationException::class, "(Service 'bad' of type Good) +Multiple services of type stdClass found: a, b +Used in @bad::bar()."); // autowiring fail in rich method calling @@ -355,4 +396,6 @@ services: setup: - bar(MethodParam()::foo(@\stdClass)) '); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of Good): Multiple services of type stdClass found: a, b (used in foo())"); +}, Nette\DI\ServiceCreationException::class, "(Service 'bad' of type Good) +Multiple services of type stdClass found: a, b +Used in foo()."); diff --git a/tests/DI/ContainerBuilder.factory.resolveBuiltinTypes.phpt b/tests/DI/ContainerBuilder.factory.resolveBuiltinTypes.phpt index 4e15e3d9b..971452604 100644 --- a/tests/DI/ContainerBuilder.factory.resolveBuiltinTypes.phpt +++ b/tests/DI/ContainerBuilder.factory.resolveBuiltinTypes.phpt @@ -82,7 +82,8 @@ namespace $builder->addDefinition('a') ->setFactory('@factory::createArray'); $container = createContainer($builder); - }, Nette\DI\ServiceCreationException::class, "Service 'a': Class or interface 'array' not found. Is return type of A\\Factory::createArray() correct?"); + }, Nette\DI\ServiceCreationException::class, "(Service 'a') +Class or interface 'array' not found. Is return type of A\\Factory::createArray() correct?"); Assert::exception(function () { $builder = new DI\ContainerBuilder; @@ -91,7 +92,8 @@ namespace $builder->addDefinition('c') ->setFactory('@factory::createCallable'); $container = createContainer($builder); - }, Nette\DI\ServiceCreationException::class, "Service 'c': Class or interface 'callable' not found. Is return type of A\\Factory::createCallable() correct?"); + }, Nette\DI\ServiceCreationException::class, "(Service 'c') +Class or interface 'callable' not found. Is return type of A\\Factory::createCallable() correct?"); Assert::exception(function () { $builder = new DI\ContainerBuilder; @@ -100,7 +102,8 @@ namespace $builder->addDefinition('s') ->setFactory('@factory::createString'); $container = createContainer($builder); - }, Nette\DI\ServiceCreationException::class, "Service 's': Class or interface 'string' not found. Is return type of A\\Factory::createString() correct?"); + }, Nette\DI\ServiceCreationException::class, "(Service 's') +Class or interface 'string' not found. Is return type of A\\Factory::createString() correct?"); Assert::exception(function () { $builder = new DI\ContainerBuilder; diff --git a/tests/DI/ContainerBuilder.recursive.phpt b/tests/DI/ContainerBuilder.recursive.phpt index 50ca69c71..71d217844 100644 --- a/tests/DI/ContainerBuilder.recursive.phpt +++ b/tests/DI/ContainerBuilder.recursive.phpt @@ -29,4 +29,5 @@ $builder->addDefinition('two') Assert::exception(function () use ($builder) { $container = createContainer($builder); -}, Nette\DI\ServiceCreationException::class, "Service 'two': Circular reference detected for services: one, two."); +}, Nette\DI\ServiceCreationException::class, "(Service 'two') +Circular reference detected for services: one, two."); diff --git a/tests/DI/ContainerBuilder.selfdependency.phpt b/tests/DI/ContainerBuilder.selfdependency.phpt index d3bd587c5..027ce7064 100644 --- a/tests/DI/ContainerBuilder.selfdependency.phpt +++ b/tests/DI/ContainerBuilder.selfdependency.phpt @@ -27,4 +27,6 @@ $builder->addDefinition(null) Assert::exception(function () use ($builder) { createContainer($builder); -}, Nette\DI\ServiceCreationException::class, 'Service of type Foo: Service of type Foo needed by $foo in __construct() not found. Did you add it to configuration file?'); +}, Nette\DI\ServiceCreationException::class, '(Service of type Foo) +Service of type Foo needed by $foo in __construct() not found. +Did you add it to configuration file?'); diff --git a/tests/DI/Definitions.AccessorDefinition.resolve.phpt b/tests/DI/Definitions.AccessorDefinition.resolve.phpt index 2bb67e1d3..5c391946e 100644 --- a/tests/DI/Definitions.AccessorDefinition.resolve.phpt +++ b/tests/DI/Definitions.AccessorDefinition.resolve.phpt @@ -37,7 +37,8 @@ Assert::exception(function () { $resolver = new Nette\DI\Resolver(new Nette\DI\ContainerBuilder); $resolver->resolveDefinition($def); $resolver->completeDefinition($def); -}, Nette\DI\ServiceCreationException::class, 'Service of type Good1: Method get() has not return type hint or annotation @return.'); +}, Nette\DI\ServiceCreationException::class, '(Service of type Good1) +Method get() has not return type hint or annotation @return.'); Assert::noError(function () { @@ -66,4 +67,5 @@ Assert::exception(function () { $resolver = new Nette\DI\Resolver(new Nette\DI\ContainerBuilder); $resolver->resolveDefinition($def); $resolver->completeDefinition($def); -}, Nette\DI\ServiceCreationException::class, "Service of type Good2: Service of type 'stdClass' not found."); +}, Nette\DI\ServiceCreationException::class, "(Service of type Good2) +Service of type 'stdClass' not found."); diff --git a/tests/DI/Definitions.FactoryDefinition.resolve.phpt b/tests/DI/Definitions.FactoryDefinition.resolve.phpt index 5f06aefa9..91341aeb2 100644 --- a/tests/DI/Definitions.FactoryDefinition.resolve.phpt +++ b/tests/DI/Definitions.FactoryDefinition.resolve.phpt @@ -36,7 +36,8 @@ Assert::exception(function () { $def->setImplement('Good1'); $resolver = new Nette\DI\Resolver(new Nette\DI\ContainerBuilder); $resolver->resolveDefinition($def); -}, Nette\DI\ServiceCreationException::class, 'Service of type Good1: Method create() has not return type hint or annotation @return.'); +}, Nette\DI\ServiceCreationException::class, '(Service of type Good1) +Method create() has not return type hint or annotation @return.'); Assert::noError(function () { diff --git a/tests/DI/InjectExtension.errors.phpt b/tests/DI/InjectExtension.errors.phpt index 765e6094e..aa8c52b9e 100644 --- a/tests/DI/InjectExtension.errors.phpt +++ b/tests/DI/InjectExtension.errors.phpt @@ -46,7 +46,8 @@ services: factory: ServiceA inject: yes '); -}, InvalidStateException::class, 'Service of type DateTimeImmutable used in type hint at ServiceA::$a not found. Did you add it to configuration file?'); +}, InvalidStateException::class, 'Service of type DateTimeImmutable used in type hint at ServiceA::$a not found. +Did you add it to configuration file?'); Assert::exception(function () use ($compiler) { @@ -56,7 +57,8 @@ services: factory: ServiceB inject: yes '); -}, InvalidStateException::class, "Class or interface 'Unknown' used in type hint at ServiceB::\$a not found. Check type and 'use' statements."); +}, InvalidStateException::class, "Class or interface 'Unknown' used in type hint at ServiceB::\$a not found. +Check type and 'use' statements."); Assert::exception(function () use ($compiler) { diff --git a/tests/DI/Resolver.autowireArguments.errors.phpt b/tests/DI/Resolver.autowireArguments.errors.phpt index 7f5cdc078..06fa82f9d 100644 --- a/tests/DI/Resolver.autowireArguments.errors.phpt +++ b/tests/DI/Resolver.autowireArguments.errors.phpt @@ -15,12 +15,14 @@ require __DIR__ . '/../bootstrap.php'; Assert::exception(function () { Resolver::autowireArguments(new ReflectionFunction(function (stdClass $x) {}), [], function () {}); -}, Nette\DI\ServiceCreationException::class, 'Service of type stdClass needed by $x in {closure}() not found. Did you add it to configuration file?'); +}, Nette\DI\ServiceCreationException::class, 'Service of type stdClass needed by $x in {closure}() not found. +Did you add it to configuration file?'); Assert::exception(function () { Resolver::autowireArguments(new ReflectionFunction(function (Foo $x) {}), [], function () {}); -}, Nette\DI\ServiceCreationException::class, "Class Foo needed by \$x in {closure}() not found. Check type hint and 'use' statements."); +}, Nette\DI\ServiceCreationException::class, "Class Foo needed by \$x in {closure}() not found. +Check type hint and 'use' statements."); Assert::exception(function () {