Skip to content

Commit

Permalink
Add unit test case to ValueToClassTransformer
Browse files Browse the repository at this point in the history
  • Loading branch information
praem90 committed Oct 11, 2023
1 parent 54932a9 commit d4463c8
Showing 1 changed file with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

declare(strict_types=1);

namespace Test\Unit\Core\Configuration\ValueTransformer;

use BumbleDocGen\Core\Cache\LocalCache\LocalObjectCache;
use BumbleDocGen\Core\Configuration\Configuration;
use BumbleDocGen\Core\Configuration\ConfigurationParameterBag;
use BumbleDocGen\Core\Configuration\ValueTransformer\ValueToClassTransformer;
use BumbleDocGen\DocGeneratorFactory;
use BumbleDocGen\LanguageHandler\Php\Parser\Entity\ClassEntityCollection;
use BumbleDocGen\LanguageHandler\Php\PhpHandler;
use BumbleDocGen\LanguageHandler\Php\PhpHandlerSettings;
use DI\Container;
use Exception;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;

final class ValueToClassTransformerTest extends TestCase
{
protected ValueToClassTransformer $valueToClassTransformer;

public function setUp(): void
{
$this->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(''));
}
}

0 comments on commit d4463c8

Please sign in to comment.