From a06a68ec73be81498237d4f15a53f97f0214586c Mon Sep 17 00:00:00 2001 From: "Michael Albrecht (personal)" Date: Tue, 20 Aug 2024 16:50:03 +0200 Subject: [PATCH] coverage check --- tests/Target/GenericTargetFactoryTest.php | 75 +++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/Target/GenericTargetFactoryTest.php diff --git a/tests/Target/GenericTargetFactoryTest.php b/tests/Target/GenericTargetFactoryTest.php new file mode 100644 index 0000000..602c492 --- /dev/null +++ b/tests/Target/GenericTargetFactoryTest.php @@ -0,0 +1,75 @@ +factory = new GenericTargetFactory(TestTarget::class); + $result = $this->factory->create(); + + self::assertSame(1, $result->getValue()); + } + + /** + * @test + */ + public function create_with_non_instnatiable_case(): void + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Neusta\\ConverterBundle\\Tests\\Target\\TestNonInstantiableTarget" is not instantiable.'); + $this->factory = new GenericTargetFactory(TestNonInstantiableTarget::class); + } + + /** + * @test + */ + public function create_with_constructor_params_case(): void + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Neusta\\ConverterBundle\\Tests\\Target\\TestWithConstructorParamsTarget" has required constructor parameters'); + $this->factory = new GenericTargetFactory(TestWithConstructorParamsTarget::class); + } +} + +class TestTarget +{ + private int $value; + + public function __construct() + { + $this->value = 1; + } + + public function getValue(): int + { + return $this->value; + } +} + +class TestNonInstantiableTarget +{ + private int $value; + + private function __construct() + { + $this->value = 1; + } +} + +class TestWithConstructorParamsTarget +{ + public function __construct( + private int $value, + ) { + } +}