From d4463c8bc96869370f867c39a61eaf6c9733c3b4 Mon Sep 17 00:00:00 2001 From: Mohan Raj Date: Wed, 11 Oct 2023 12:06:33 +0530 Subject: [PATCH] Add unit test case to ValueToClassTransformer --- .../ValueToClassTransformerTest.php | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 tests/Unit/Core/Configuration/ValueTransformer/ValueToClassTransformerTest.php diff --git a/tests/Unit/Core/Configuration/ValueTransformer/ValueToClassTransformerTest.php b/tests/Unit/Core/Configuration/ValueTransformer/ValueToClassTransformerTest.php new file mode 100644 index 00000000..14b59497 --- /dev/null +++ b/tests/Unit/Core/Configuration/ValueTransformer/ValueToClassTransformerTest.php @@ -0,0 +1,85 @@ +valueToClassTransformer = new ValueToClassTransformer(new Container()); + } + + public function testCanTransform(): void + { + $this->assertFalse($this->valueToClassTransformer->canTransform('')); + + $this->assertFalse($this->valueToClassTransformer->canTransform([])); + + $this->assertFalse($this->valueToClassTransformer->canTransform([ + 'class' => 'ClassThatDoesntExists' + ])); + + $this->assertTrue($this->valueToClassTransformer->canTransform([ + 'class' => ValueToClassTransformer::class + ])); + } + + public function testTransform(): void + { + $value = [ + 'class' => Exception::class, + ]; + + $class = $this->valueToClassTransformer->transform($value); + $this->assertInstanceOf(Exception::class, $class); + + $value = [ + 'class' => DocGeneratorFactory::class, + ]; + + $class = $this->valueToClassTransformer->transform($value); + $this->assertInstanceOf(DocGeneratorFactory::class, $class); + + $value = [ + 'class' => Configuration::class, + 'arguments' => [ + [ + 'class' => ConfigurationParameterBag::class, + 'arguments' => [ + ['class' => ValueToClassTransformer::class], + [] + ] + ], + [ + 'class' => LocalObjectCache::class + ], + [ + 'class' => NullLogger::class + ] + ] + ]; + + $class = $this->valueToClassTransformer->transform($value); + $this->assertInstanceOf(Configuration::class, $class); + + + $this->assertNull($this->valueToClassTransformer->transform('')); + } +}