mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-04 11:17:58 +00:00 
			
		
		
		
	Implemented type for FormClassNameService and solved reference bugs
This commit is contained in:
		@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@ use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
final class RequestedEntityFormBuilderService implements EntityFormBuilderServiceInterface
 | 
			
		||||
final class RequestedEntityFormBuilderService implements RequestedEntityFormBuilderServiceInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var FormBuilderInterface
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user