Implemented type for FormClassNameService and solved reference bugs

This commit is contained in:
Kevin Frantz 2019-02-03 15:40:44 +01:00
parent ed3062a203
commit 22c9a92853
4 changed files with 24 additions and 5 deletions

View File

@ -7,10 +7,19 @@ namespace App\Domain\FormManagement;
*/
final class FormClassNameService implements FormClassNameServiceInterface
{
/**
* @var string Folder in which the entities are stored
*/
const ENTITY_BASE_PATH = 'App\\Entity';
/**
* @var string Folder in which the forms are stored
*/
const FORM_BASE_PATH = 'App\\Form';
/**
* @var string Suffix to identifie form classes
*/
const SUFFIX = 'Type';
/**
@ -18,10 +27,11 @@ final class FormClassNameService implements FormClassNameServiceInterface
*
* @see \App\Domain\FormManagement\FormClassNameServiceInterface::getClass()
*/
public function getClass(string $origineClass): string
public function getClass(string $origineClass, string $type = ''): string
{
$replaced = str_replace(self::ENTITY_BASE_PATH, self::FORM_BASE_PATH, $origineClass);
$withSuffix = $replaced.self::SUFFIX;
$withType = $replaced.ucfirst($type);
$withSuffix = $withType.self::SUFFIX;
return $withSuffix;
}

View File

@ -14,5 +14,5 @@ interface FormClassNameServiceInterface
*
* @return string The name of the form of the entity
*/
public function getClass(string $origineClass): string;
public function getClass(string $origineClass, string $type = ''): string;
}

View File

@ -8,7 +8,7 @@ use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
/**
* @author kevinfrantz
*/
final class RequestedEntityFormBuilderService implements EntityFormBuilderServiceInterface
final class RequestedEntityFormBuilderService implements RequestedEntityFormBuilderServiceInterface
{
/**
* @var FormBuilderInterface

View File

@ -5,17 +5,26 @@ namespace tests\Unit\Domain\FormManagement;
use PHPUnit\Framework\TestCase;
use App\Domain\FormManagement\FormClassNameService;
use App\Entity\Source\PureSource;
use App\DBAL\Types\ActionType;
/**
* @author kevinfrantz
*/
class FormClassNameServiceTest extends TestCase
{
public function testGetName()
public function testGetName(): void
{
$entityClass = PureSource::class;
$formNameService = new FormClassNameService();
$entityForm = $formNameService->getClass($entityClass);
$this->assertEquals('App\\Form\\Source\\PureSourceType', $entityForm);
}
public function testWithType(): void
{
$entityClass = PureSource::class;
$formNameService = new FormClassNameService();
$entityForm = $formNameService->getClass($entityClass, ActionType::CREATE);
$this->assertEquals('App\\Form\\Source\\PureSourceCreateType', $entityForm);
}
}