Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Unit Tests for BumbleDocGen\Core\Configuration\ValueTransformer Namespace #45

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(''));
}
}