diff --git a/src/AttributeHandling/ResolverFactory/ReflectionAttributeResolverFactory.php b/src/AttributeHandling/ResolverFactory/ReflectionAttributeResolverFactory.php index e0c646f..c5c1c04 100644 --- a/src/AttributeHandling/ResolverFactory/ReflectionAttributeResolverFactory.php +++ b/src/AttributeHandling/ResolverFactory/ReflectionAttributeResolverFactory.php @@ -33,7 +33,7 @@ public function create(DataAttributeInterface|ParameterAttributeInterface $attri if ($reflectionClass->isAbstract()) { throw new AttributeResolverNonInstantiableException( sprintf( - '%s is not instantiable because it is abstract.', + '"%s" is not instantiable because it is abstract.', $reflectionClass->getName(), ), ); diff --git a/tests/AttributeHandling/ResolverFactory/ReflectionAttributeResolverFactoryTest.php b/tests/AttributeHandling/ResolverFactory/ReflectionAttributeResolverFactoryTest.php new file mode 100644 index 0000000..d55d1fa --- /dev/null +++ b/tests/AttributeHandling/ResolverFactory/ReflectionAttributeResolverFactoryTest.php @@ -0,0 +1,83 @@ +create($attribute); + + $this->assertInstanceOf(CounterResolver::class, $result); + } + + public function testResolverIsAttributeItself(): void + { + $attribute = new CustomValue('test'); + $factory = new ReflectionAttributeResolverFactory(); + + $result = $factory->create($attribute); + + $this->assertSame($attribute, $result); + } + + public function testNonExistClass(): void + { + $attribute = new CustomResolverAttr('NonExistClass'); + $factory = new ReflectionAttributeResolverFactory(); + + $this->expectException(AttributeResolverNonInstantiableException::class); + $this->expectExceptionMessage('Class "NonExistClass" does not exist.'); + $factory->create($attribute); + } + + public function testAbstractClass(): void + { + $attribute = new CustomResolverAttr(AbstractResolver::class); + $factory = new ReflectionAttributeResolverFactory(); + + $this->expectException(AttributeResolverNonInstantiableException::class); + $this->expectExceptionMessage('"' . AbstractResolver::class . '" is not instantiable because it is abstract.'); + $factory->create($attribute); + } + + public function testNonPublicConstructor(): void + { + $attribute = new CustomResolverAttr(PrivateConstructorResolver::class); + $factory = new ReflectionAttributeResolverFactory(); + + $this->expectException(AttributeResolverNonInstantiableException::class); + $this->expectExceptionMessage( + 'Class "' . PrivateConstructorResolver::class . '" is not instantiable because contain non-public constructor.' + ); + $factory->create($attribute); + } + + public function testConstructorWithParameters(): void + { + $attribute = new CustomResolverAttr(ParameterizedResolver::class); + $factory = new ReflectionAttributeResolverFactory(); + + $this->expectException(AttributeResolverNonInstantiableException::class); + $this->expectExceptionMessage( + 'Class "' . ParameterizedResolver::class . '" cannot be instantiated because it has 1 required parameters in constructor.' + ); + $factory->create($attribute); + } +} diff --git a/tests/Support/Attribute/AbstractResolver.php b/tests/Support/Attribute/AbstractResolver.php new file mode 100644 index 0000000..532ee4e --- /dev/null +++ b/tests/Support/Attribute/AbstractResolver.php @@ -0,0 +1,11 @@ +resolver; + } +} diff --git a/tests/Support/Attribute/ParameterizedResolver.php b/tests/Support/Attribute/ParameterizedResolver.php new file mode 100644 index 0000000..5498040 --- /dev/null +++ b/tests/Support/Attribute/ParameterizedResolver.php @@ -0,0 +1,25 @@ +result); + } +} diff --git a/tests/Support/Attribute/PrivateConstructorResolver.php b/tests/Support/Attribute/PrivateConstructorResolver.php new file mode 100644 index 0000000..ad19872 --- /dev/null +++ b/tests/Support/Attribute/PrivateConstructorResolver.php @@ -0,0 +1,25 @@ +