Optimized FormMeta and Tests

This commit is contained in:
Kevin Frantz 2018-11-23 16:50:37 +01:00
parent 2009f1b691
commit 926eb0c3fb
6 changed files with 59 additions and 9 deletions

View File

@ -8,6 +8,8 @@ use App\Domain\TemplateManagement\TemplateMeta;
/**
* @author kevinfrantz
*
* @todo Optimize contructor parameter!
*/
class FormMeta implements FormMetaInterface
{
@ -37,7 +39,11 @@ class FormMeta implements FormMetaInterface
private function setFormClass(): void
{
$this->formClass = 'App\\Form\\'.implode('\\', $this->sourceMeta->getBasicPathArray()).'\\'.$this->sourceMeta->getBasicName().'Type';
$this->formClass = 'App\\Form';
foreach ($this->sourceMeta->getBasicPathArray() as $element) {
$this->formClass .= '\\'.ucfirst($element);
}
$this->formClass .= '\\'.ucfirst($this->sourceMeta->getBasicName()).'Type';
}
private function setMeta(): void
@ -50,7 +56,7 @@ class FormMeta implements FormMetaInterface
return $this->formClass;
}
public function getTemplateMeta(): string
public function getTemplateMeta(): TemplateMetaInterface
{
return $this->templateMeta;
}

View File

@ -2,9 +2,11 @@
namespace App\Domain\FormManagement;
use App\Domain\TemplateManagement\TemplateMetaInterface;
interface FormMetaInterface
{
public function getFormClass(): string;
public function getTemplateMeta(): string;
public function getTemplateMeta(): TemplateMetaInterface;
}

View File

@ -13,6 +13,8 @@ use App\Domain\FormManagement\FormMeta;
*/
class SourceMeta implements SourceMetaInterface
{
const FOLDER = 'entity';
/**
* @var \ReflectionClass
*/
@ -55,10 +57,15 @@ class SourceMeta implements SourceMetaInterface
$this->setBasicPathArray();
$this->setBasicName();
$this->setInterfaceReflection();
$this->templateMeta = new TemplateMeta($this->basicPathArray, $this->basicName, 'entity');
$this->setTemplateMeta();
$this->formMeta = new FormMeta($this);
}
private function setTemplateMeta(): void
{
$this->templateMeta = new TemplateMeta($this->basicPathArray, $this->basicName, self::FOLDER);
}
private function setBasicPathArray(): void
{
$namespace = $this->sourceReflection->getNamespaceName();

View File

@ -94,9 +94,4 @@ class TemplateMeta implements TemplateMetaInterface
{
return $this->type;
}
public function getPathSuffix(): string
{
return $this->pathSuffix;
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace Tests\Unit\Domain;
use PHPUnit\Framework\TestCase;
use App\Domain\FormManagement\FormMetaInterface;
use App\Domain\FormManagement\FormMeta;
use App\Entity\Source\Primitive\Name\SurnameSource;
use App\Domain\SourceManagement\SourceMeta;
use App\Domain\TemplateManagement\TemplateMetaInterface;
class FormMetaTest extends TestCase
{
/**
* @var FormMetaInterface
*/
protected $formMeta;
public function setUp(): void
{
$sourceMeta = new SourceMeta(new SurnameSource());
$this->formMeta = new FormMeta($sourceMeta);
}
public function testGetFormClass(): void
{
$this->assertEquals('App\Form\Source\Primitive\Name\SurnameType', $this->formMeta->getFormClass());
}
public function testTemplateMeta(): void
{
$this->assertInstanceOf(TemplateMetaInterface::class, $this->formMeta->getTemplateMeta());
}
}

View File

@ -9,6 +9,7 @@ use App\Domain\SourceManagement\SourceMeta;
use App\Entity\Source\Complex\UserSourceInterface;
use App\Domain\TemplateManagement\TemplateMetaInterface;
use App\Entity\Source\SourceInterface;
use App\Domain\FormManagement\FormMetaInterface;
class SourceMetaTest extends TestCase
{
@ -73,4 +74,9 @@ class SourceMetaTest extends TestCase
{
$this->assertEquals($this->source, $this->sourceMeta->getSource());
}
public function testFormMeta(): void
{
$this->assertInstanceOf(FormMetaInterface::class, $this->sourceMeta->getFormMeta());
}
}