mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-04-16 02:06:23 +02:00
Implemented type for FormClassNameService and solved reference bugs
This commit is contained in:
parent
ed3062a203
commit
22c9a92853
@ -7,10 +7,19 @@ namespace App\Domain\FormManagement;
|
|||||||
*/
|
*/
|
||||||
final class FormClassNameService implements FormClassNameServiceInterface
|
final class FormClassNameService implements FormClassNameServiceInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var string Folder in which the entities are stored
|
||||||
|
*/
|
||||||
const ENTITY_BASE_PATH = 'App\\Entity';
|
const ENTITY_BASE_PATH = 'App\\Entity';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string Folder in which the forms are stored
|
||||||
|
*/
|
||||||
const FORM_BASE_PATH = 'App\\Form';
|
const FORM_BASE_PATH = 'App\\Form';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string Suffix to identifie form classes
|
||||||
|
*/
|
||||||
const SUFFIX = 'Type';
|
const SUFFIX = 'Type';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,10 +27,11 @@ final class FormClassNameService implements FormClassNameServiceInterface
|
|||||||
*
|
*
|
||||||
* @see \App\Domain\FormManagement\FormClassNameServiceInterface::getClass()
|
* @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);
|
$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;
|
return $withSuffix;
|
||||||
}
|
}
|
||||||
|
@ -14,5 +14,5 @@ interface FormClassNameServiceInterface
|
|||||||
*
|
*
|
||||||
* @return string The name of the form of the entity
|
* @return string The name of the form of the entity
|
||||||
*/
|
*/
|
||||||
public function getClass(string $origineClass): string;
|
public function getClass(string $origineClass, string $type = ''): string;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
|
|||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*/
|
*/
|
||||||
final class RequestedEntityFormBuilderService implements EntityFormBuilderServiceInterface
|
final class RequestedEntityFormBuilderService implements RequestedEntityFormBuilderServiceInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var FormBuilderInterface
|
* @var FormBuilderInterface
|
||||||
|
@ -5,17 +5,26 @@ namespace tests\Unit\Domain\FormManagement;
|
|||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use App\Domain\FormManagement\FormClassNameService;
|
use App\Domain\FormManagement\FormClassNameService;
|
||||||
use App\Entity\Source\PureSource;
|
use App\Entity\Source\PureSource;
|
||||||
|
use App\DBAL\Types\ActionType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*/
|
*/
|
||||||
class FormClassNameServiceTest extends TestCase
|
class FormClassNameServiceTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testGetName()
|
public function testGetName(): void
|
||||||
{
|
{
|
||||||
$entityClass = PureSource::class;
|
$entityClass = PureSource::class;
|
||||||
$formNameService = new FormClassNameService();
|
$formNameService = new FormClassNameService();
|
||||||
$entityForm = $formNameService->getClass($entityClass);
|
$entityForm = $formNameService->getClass($entityClass);
|
||||||
$this->assertEquals('App\\Form\\Source\\PureSourceType', $entityForm);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user