diff --git a/src/DI/Autowiring.php b/src/DI/Autowiring.php index eef93109e..f1051e83a 100644 --- a/src/DI/Autowiring.php +++ b/src/DI/Autowiring.php @@ -50,7 +50,10 @@ public function getByType(string $type, bool $throw = false): ?string $types = $this->highPriority; if (empty($types[$type])) { if ($throw) { - throw new MissingServiceException("Service of type '$type' not found."); + if (!class_exists($type) && !interface_exists($type)) { + throw new MissingServiceException(sprintf("Service of type '%s' not found. Check the class name because it cannot be found.", $type)); + } + throw new MissingServiceException(sprintf('Service of type %s not found. Did you add it to configuration file?', $type)); } return null; diff --git a/src/DI/Container.php b/src/DI/Container.php index ef6929765..a02c802cd 100644 --- a/src/DI/Container.php +++ b/src/DI/Container.php @@ -234,7 +234,7 @@ public function getByType(string $type, bool $throw = true) } elseif ($throw) { if (!class_exists($type) && !interface_exists($type)) { - throw new MissingServiceException("Service of type '$type' not found. Check class name because it cannot be found."); + throw new MissingServiceException(sprintf("Service of type '%s' not found. Check the class name because it cannot be found.", $type)); } foreach ($this->methods as $method => $foo) { $methodType = (new \ReflectionMethod(static::class, $method))->getReturnType()->getName(); diff --git a/src/DI/Definitions/AccessorDefinition.php b/src/DI/Definitions/AccessorDefinition.php index cc0dd7541..0c9bc1b3d 100644 --- a/src/DI/Definitions/AccessorDefinition.php +++ b/src/DI/Definitions/AccessorDefinition.php @@ -90,9 +90,13 @@ public function complete(Nette\DI\Resolver $resolver): void $returnType = Nette\DI\Helpers::getReturnType($method); if (!$returnType) { - throw new ServiceCreationException("Method $interface::get() has not return type hint or annotation @return."); + throw new ServiceCreationException(sprintf('Method %s::get() has no return type or annotation @return.', $interface)); } elseif (!class_exists($returnType) && !interface_exists($returnType)) { - throw new ServiceCreationException("Check a type hint or annotation @return of the $interface::get() method, class '$returnType' cannot be found."); + throw new ServiceCreationException(sprintf( + "Class '%s' not found.\nCheck the return type or annotation @return of the %s::get() method.", + $returnType, + $interface + )); } $this->setReference($returnType); } diff --git a/src/DI/Definitions/FactoryDefinition.php b/src/DI/Definitions/FactoryDefinition.php index 362c397e3..004f57b5a 100644 --- a/src/DI/Definitions/FactoryDefinition.php +++ b/src/DI/Definitions/FactoryDefinition.php @@ -182,9 +182,13 @@ public function resolveType(Nette\DI\Resolver $resolver): void $method = new \ReflectionMethod($interface, self::METHOD_CREATE); $returnType = Nette\DI\Helpers::getReturnType($method); if (!$returnType) { - throw new ServiceCreationException("Method $interface::create() has not return type hint or annotation @return."); + throw new ServiceCreationException(sprintf('Method %s::create() has no return type or annotation @return.', $interface)); } elseif (!class_exists($returnType) && !interface_exists($returnType)) { - throw new ServiceCreationException("Check a type hint or annotation @return of the $interface::create() method, class '$returnType' cannot be found."); + throw new ServiceCreationException(sprintf( + "Class '%s' not found.\nCheck the return type or annotation @return of the %s::create() method.", + $returnType, + $interface + )); } $resultDef->setType($returnType); } @@ -237,7 +241,12 @@ private function completeParameters(Nette\DI\Resolver $resolver): void if ($methodHint !== $ctorHint && !is_a((string) reset($methodHint), (string) reset($ctorHint), true) ) { - throw new ServiceCreationException("Type hint for \${$param->name} in $interface::create() doesn't match type hint in $class constructor."); + throw new ServiceCreationException(sprintf( + "Type of \$%s in %s::create() doesn't match type in %s constructor.", + $param->name, + $interface, + $class + )); } $this->resultDefinition->getFactory()->arguments[$ctorParam->getPosition()] = Nette\DI\ContainerBuilder::literal('$' . $ctorParam->name); diff --git a/src/DI/Extensions/InjectExtension.php b/src/DI/Extensions/InjectExtension.php index f5a890a58..30bc1afc3 100644 --- a/src/DI/Extensions/InjectExtension.php +++ b/src/DI/Extensions/InjectExtension.php @@ -158,11 +158,21 @@ private static function checkType($class, string $name, ?string $type, $containe { $propName = Reflection::toString(new \ReflectionProperty($class, $name)); if (!$type) { - throw new Nette\InvalidStateException("Property $propName has no type hint."); + throw new Nette\InvalidStateException(sprintf('Property %s has no type.', $propName)); + } 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(sprintf( + "Class '%s' required by %s not found. Check the property type and 'use' statements.", + $type, + $propName + )); + } 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(sprintf( + 'Service of type %s required by %s not found. Did you add it to configuration file?', + $type, + $propName + )); } } } diff --git a/src/DI/Resolver.php b/src/DI/Resolver.php index 9be06fcda..e0acfdd67 100644 --- a/src/DI/Resolver.php +++ b/src/DI/Resolver.php @@ -127,7 +127,7 @@ public function resolveEntityType(Statement $statement): ?string $type = Helpers::getReturnType($reflection); if ($type && !class_exists($type) && !interface_exists($type)) { - throw new ServiceCreationException(sprintf("Class or interface '%s' not found. Is return type of %s() correct?", $type, Nette\Utils\Callback::toString($entity))); + throw new ServiceCreationException(sprintf("Class or interface '%s' not found. Check the return type of %s() method.", $type, Nette\Utils\Callback::toString($entity))); } return $type; @@ -136,11 +136,12 @@ public function resolveEntityType(Statement $statement): ?string } elseif (is_string($entity)) { // class if (!class_exists($entity)) { - throw new ServiceCreationException( + throw new ServiceCreationException(sprintf( interface_exists($entity) - ? "Interface $entity can not be used as 'factory', did you mean 'implement'?" - : "Class $entity not found." - ); + ? "Interface %s can not be used as 'factory', did you mean 'implement'?" + : "Class '%s' not found.", + $entity + )); } return $entity; } @@ -205,7 +206,7 @@ public function completeStatement(Statement $statement, bool $currentServiceAllo case is_string($entity): // create class if (!class_exists($entity)) { - throw new ServiceCreationException("Class $entity not found."); + throw new ServiceCreationException(sprintf("Class '%s' not found.", $entity)); } elseif ((new ReflectionClass($entity))->isAbstract()) { throw new ServiceCreationException("Class $entity is abstract."); } elseif (($rm = (new ReflectionClass($entity))->getConstructor()) !== null && !$rm->isPublic()) { @@ -556,14 +557,22 @@ 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()} (required 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(sprintf( + 'Service of type %s required by %s not found. Did you add it to configuration file?', + $type, + $desc + )); } else { - throw new ServiceCreationException("Class $type needed by $desc not found. Check type hint and 'use' statements."); + throw new ServiceCreationException(sprintf( + "Class '%s' required by %s not found. Check the parameter type and 'use' statements.", + $type, + $desc + )); } } elseif ( @@ -587,8 +596,11 @@ private static function autowireArgument(\ReflectionParameter $parameter, callab : null; } else { - $tmp = count($types) > 1 ? 'union' : 'no class'; - throw new ServiceCreationException("Parameter $desc has $tmp type hint and no default value, so its value must be specified."); + throw new ServiceCreationException(sprintf( + 'Parameter %s has %s, so its value must be specified.', + $desc, + count($types) > 1 ? 'union type and no default value' : 'no class type or default value' + )); } } } diff --git a/tests/DI/Compiler.generatedFactory.phpt b/tests/DI/Compiler.generatedFactory.phpt index 3a63e05d7..b100ee6d0 100644 --- a/tests/DI/Compiler.generatedFactory.phpt +++ b/tests/DI/Compiler.generatedFactory.phpt @@ -294,7 +294,7 @@ 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' (type of Bad2): Type of \$bar in create() doesn't match type in Bad1 constructor."); diff --git a/tests/DI/Compiler.generatedFactory.polymorphism.phpt b/tests/DI/Compiler.generatedFactory.polymorphism.phpt index 9ba2913c7..fbfc44dd5 100644 --- a/tests/DI/Compiler.generatedFactory.polymorphism.phpt +++ b/tests/DI/Compiler.generatedFactory.polymorphism.phpt @@ -1,7 +1,7 @@ getByType('unknown', false)); Assert::exception(function () use ($container) { $container->getByType('unknown'); -}, Nette\DI\MissingServiceException::class, "Service of type 'unknown' not found. Check class name because it cannot be found."); +}, Nette\DI\MissingServiceException::class, "Service of type 'unknown' not found. Check the class name because it cannot be found."); Assert::exception(function () use ($container) { $container->getByType('Exception'); diff --git a/tests/DI/ContainerBuilder.autowiring.novalue.phpt b/tests/DI/ContainerBuilder.autowiring.novalue.phpt index 43bb07788..e5b7b21fe 100644 --- a/tests/DI/ContainerBuilder.autowiring.novalue.phpt +++ b/tests/DI/ContainerBuilder.autowiring.novalue.phpt @@ -24,7 +24,7 @@ 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' (type of Foo): Parameter \$x in __construct() has no class type or default value, so its value must be specified."); class Bar @@ -38,7 +38,7 @@ 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' (type of Bar): Parameter \$x in __construct() has no class type or default value, so its value must be specified."); class Bar2 diff --git a/tests/DI/ContainerBuilder.factory.error.phpt b/tests/DI/ContainerBuilder.factory.error.phpt index cd42e7a5b..2a58e3cc3 100644 --- a/tests/DI/ContainerBuilder.factory.error.phpt +++ b/tests/DI/ContainerBuilder.factory.error.phpt @@ -25,7 +25,7 @@ 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 +33,7 @@ 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,7 +41,7 @@ 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 () { @@ -76,7 +76,7 @@ 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' (type of Bad4): Method create() has no return type or annotation @return."); interface Bad5 @@ -146,7 +146,7 @@ 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' (type of Good): Class 'Unknown' not found. (used in __construct())"); // fail in argument Assert::exception(function () { @@ -208,7 +208,7 @@ 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' (type of ConstructorParam): Multiple services of type stdClass found: a, b (required by \$x in __construct())"); // forced autowiring fail @@ -230,7 +230,7 @@ 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' (type of MethodParam): Multiple services of type stdClass found: a, b (required by \$x in foo())"); // forced autowiring fail in chain @@ -252,7 +252,7 @@ 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' (type of Good): Multiple services of type stdClass found: a, b (required by \$x in ConstructorParam::__construct()) (used in __construct())"); // forced autowiring fail in argument @@ -274,7 +274,7 @@ 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' (type of Good): Multiple services of type stdClass found: a, b (required by \$x in MethodParam::foo()) (used in __construct())"); // forced autowiring fail in chain in argument @@ -327,7 +327,7 @@ 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' (type of MethodParam): Multiple services of type stdClass found: a, b (required by \$x in foo())"); // forced autowiring fail in method calling diff --git a/tests/DI/ContainerBuilder.factory.resolveBuiltinTypes.phpt b/tests/DI/ContainerBuilder.factory.resolveBuiltinTypes.phpt index 4e15e3d9b..9829f563e 100644 --- a/tests/DI/ContainerBuilder.factory.resolveBuiltinTypes.phpt +++ b/tests/DI/ContainerBuilder.factory.resolveBuiltinTypes.phpt @@ -82,7 +82,7 @@ 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. Check the return type of A\\Factory::createArray() method."); Assert::exception(function () { $builder = new DI\ContainerBuilder; @@ -91,7 +91,7 @@ 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. Check the return type of A\\Factory::createCallable() method."); Assert::exception(function () { $builder = new DI\ContainerBuilder; @@ -100,7 +100,7 @@ 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. Check the return type of A\\Factory::createString() method."); Assert::exception(function () { $builder = new DI\ContainerBuilder; @@ -109,7 +109,7 @@ namespace $builder->addDefinition('i') ->setFactory('@factory::createInt'); $container = createContainer($builder); - }, Nette\DI\ServiceCreationException::class, "Service 'i': Class or interface 'int' not found. Is return type of A\\Factory::createInt() correct?"); + }, Nette\DI\ServiceCreationException::class, "Service 'i': Class or interface 'int' not found. Check the return type of A\\Factory::createInt() method."); Assert::exception(function () { $builder = new DI\ContainerBuilder; @@ -118,7 +118,7 @@ namespace $builder->addDefinition('b') ->setFactory('@factory::createBool'); $container = createContainer($builder); - }, Nette\DI\ServiceCreationException::class, "Service 'b': Class or interface 'bool' not found. Is return type of A\\Factory::createBool() correct?"); + }, Nette\DI\ServiceCreationException::class, "Service 'b': Class or interface 'bool' not found. Check the return type of A\\Factory::createBool() method."); Assert::exception(function () { $builder = new DI\ContainerBuilder; @@ -127,7 +127,7 @@ namespace $builder->addDefinition('f') ->setFactory('@factory::createFloat'); $container = createContainer($builder); - }, Nette\DI\ServiceCreationException::class, "Service 'f': Class or interface 'float' not found. Is return type of A\\Factory::createFloat() correct?"); + }, Nette\DI\ServiceCreationException::class, "Service 'f': Class or interface 'float' not found. Check the return type of A\\Factory::createFloat() method."); Assert::exception(function () { $builder = new DI\ContainerBuilder; diff --git a/tests/DI/ContainerBuilder.getByType.phpt b/tests/DI/ContainerBuilder.getByType.phpt index 0ddd40b82..2aa6a3f6c 100644 --- a/tests/DI/ContainerBuilder.getByType.phpt +++ b/tests/DI/ContainerBuilder.getByType.phpt @@ -47,7 +47,7 @@ Assert::null($builder->getByType('Child')); Assert::exception(function () use ($builder) { $builder->getByType('Child', true); -}, Nette\DI\MissingServiceException::class, "Service of type 'Child' not found."); +}, Nette\DI\MissingServiceException::class, 'Service of type Child not found. Did you add it to configuration file?'); Assert::same('two', $builder->getByType('Service2')); @@ -57,7 +57,7 @@ Assert::exception(function () use ($builder) { Assert::exception(function () use ($builder) { $builder->getByType('unknown', true); -}, Nette\DI\MissingServiceException::class, "Service of type 'unknown' not found."); +}, Nette\DI\MissingServiceException::class, "Service of type 'unknown' not found. Check the class name because it cannot be found."); Assert::null($builder->getByType('unknown')); diff --git a/tests/DI/ContainerBuilder.getDefinitionByType.phpt b/tests/DI/ContainerBuilder.getDefinitionByType.phpt index c0be5caf9..6fcfa0ca6 100644 --- a/tests/DI/ContainerBuilder.getDefinitionByType.phpt +++ b/tests/DI/ContainerBuilder.getDefinitionByType.phpt @@ -28,7 +28,7 @@ Assert::same($definitionOne, $definition); Assert::exception(function () use ($builder) { $builder->getDefinitionByType('unknown'); -}, Nette\DI\MissingServiceException::class, "Service of type 'unknown' not found."); +}, Nette\DI\MissingServiceException::class, "Service of type 'unknown' not found. Check the class name because it cannot be found."); Assert::exception(function () use ($builder) { $builder->getDefinitionByType(SplFileInfo::class); diff --git a/tests/DI/ContainerBuilder.selfdependency.phpt b/tests/DI/ContainerBuilder.selfdependency.phpt index d3bd587c5..0e89c3d8a 100644 --- a/tests/DI/ContainerBuilder.selfdependency.phpt +++ b/tests/DI/ContainerBuilder.selfdependency.phpt @@ -27,4 +27,4 @@ $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 required 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..f65d7b303 100644 --- a/tests/DI/Definitions.AccessorDefinition.resolve.phpt +++ b/tests/DI/Definitions.AccessorDefinition.resolve.phpt @@ -37,7 +37,7 @@ 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 no return type or annotation @return.'); Assert::noError(function () { @@ -66,4 +66,4 @@ 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. Did you add it to configuration file?'); diff --git a/tests/DI/Definitions.FactoryDefinition.resolve.phpt b/tests/DI/Definitions.FactoryDefinition.resolve.phpt index 5f06aefa9..a32930e14 100644 --- a/tests/DI/Definitions.FactoryDefinition.resolve.phpt +++ b/tests/DI/Definitions.FactoryDefinition.resolve.phpt @@ -36,7 +36,7 @@ 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 no return type or annotation @return.'); Assert::noError(function () { diff --git a/tests/DI/InjectExtension.errors.phpt b/tests/DI/InjectExtension.errors.phpt index 765e6094e..67128bd64 100644 --- a/tests/DI/InjectExtension.errors.phpt +++ b/tests/DI/InjectExtension.errors.phpt @@ -46,7 +46,7 @@ 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 required by ServiceA::$a not found. Did you add it to configuration file?'); Assert::exception(function () use ($compiler) { @@ -56,7 +56,7 @@ 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 'Unknown' required by ServiceB::\$a not found. Check the property type and 'use' statements."); Assert::exception(function () use ($compiler) { @@ -66,4 +66,4 @@ services: factory: ServiceC inject: yes '); -}, InvalidStateException::class, 'Property ServiceC::$a has no type hint.'); +}, InvalidStateException::class, 'Property ServiceC::$a has no type.'); diff --git a/tests/DI/Resolver.autowireArguments.80.phpt b/tests/DI/Resolver.autowireArguments.80.phpt index ed9bf63f1..3c6adee52 100644 --- a/tests/DI/Resolver.autowireArguments.80.phpt +++ b/tests/DI/Resolver.autowireArguments.80.phpt @@ -34,7 +34,7 @@ class Test Assert::exception(function () { Resolver::autowireArguments(new ReflectionMethod('Test', 'methodUnion'), [], function () {}); -}, Nette\InvalidStateException::class, 'Parameter $self in Test::methodUnion() has union type hint and no default value, so its value must be specified.'); +}, Nette\InvalidStateException::class, 'Parameter $self in Test::methodUnion() has union type and no default value, so its value must be specified.'); Assert::same( [null], diff --git a/tests/DI/Resolver.autowireArguments.errors.phpt b/tests/DI/Resolver.autowireArguments.errors.phpt index 7f5cdc078..6f36aa8d6 100644 --- a/tests/DI/Resolver.autowireArguments.errors.phpt +++ b/tests/DI/Resolver.autowireArguments.errors.phpt @@ -15,19 +15,19 @@ 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 required 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' required by \$x in {closure}() not found. Check the parameter type and 'use' statements."); Assert::exception(function () { Resolver::autowireArguments(new ReflectionFunction(function ($x) {}), [], function () {}); -}, Nette\DI\ServiceCreationException::class, 'Parameter $x in {closure}() has no class type hint and no default value, so its value must be specified.'); +}, Nette\DI\ServiceCreationException::class, 'Parameter $x in {closure}() has no class type or default value, so its value must be specified.'); Assert::exception(function () { Resolver::autowireArguments(new ReflectionFunction(function (int $x) {}), [], function () {}); -}, Nette\DI\ServiceCreationException::class, 'Parameter $x in {closure}() has no class type hint and no default value, so its value must be specified.'); +}, Nette\DI\ServiceCreationException::class, 'Parameter $x in {closure}() has no class type or default value, so its value must be specified.');