In between commit solving tests for meta and template management

This commit is contained in:
Kevin Frantz 2019-01-06 13:13:24 +01:00
parent 6352e82ce1
commit 72d0a6ba95
11 changed files with 289 additions and 108 deletions

View File

@ -4,9 +4,10 @@ namespace App\Domain\EntityManagement;
use App\Domain\TemplateManagement\TemplatePathFormAndViewInterface;
use App\Entity\EntityInterface;
use src\Domain\TemplateManagement\TemplatePathFormAndView;
use App\Domain\TemplateManagement\TemplatePathFormAndView;
use App\Domain\FormManagement\FormMetaInformationInterface;
use App\Domain\FormManagement\FormMetaInformation;
use App\Domain\PathManagement\NamespacePathMapInterface;
/**
* @author kevinfrantz
@ -36,7 +37,7 @@ class EntityMetaInformation implements EntityMetaInformationInterface
/**
* @var string
*/
private $pureName;
protected $pureName;
/**
* @var EntityInterface
@ -48,6 +49,16 @@ class EntityMetaInformation implements EntityMetaInformationInterface
*/
private $formMetaInformation;
/**
* @var string
*/
private $basicPathString;
/**
* @var NamespacePathMapInterface
*/
private $namespacePathMap;
/**
* @param EntityInterface $entity
*/
@ -56,12 +67,18 @@ class EntityMetaInformation implements EntityMetaInformationInterface
$this->entity = $entity;
$this->entityReflection = new \ReflectionClass($entity);
$this->setBasicPathArray();
$this->setBasicPathString();
$this->setPureName();
$this->setInterfaceReflection();
$this->setTemplatePathFormAndView();
$this->formMetaInformation = new FormMetaInformation($this);
}
private function setBasicPathString(): void
{
$this->basicPathString = implode('/', $this->basicPathArray);
}
private function setTemplatePathFormAndView(): void
{
$this->templatePathFormAndView = new TemplatePathFormAndView(implode('/', $this->basicPathArray), $this->pureName);
@ -158,4 +175,14 @@ class EntityMetaInformation implements EntityMetaInformationInterface
{
return $this->formMetaInformation;
}
/**
* {@inheritdoc}
*
* @see \App\Domain\EntityManagement\EntityMetaInformationInterface::getBasicPathString()
*/
public function getBasicPathString(): string
{
return $this->basicPathString;
}
}

View File

@ -47,4 +47,9 @@ interface EntityMetaInformationInterface
* @return FormMetaInformationInterface The meta informations about the form
*/
public function getFormMetaInformation(): FormMetaInformationInterface;
/**
* @return string
*/
public function getBasicPathString(): string;
}

View File

@ -0,0 +1,75 @@
<?php
namespace App\Domain\PathManagement;
/**
* @author kevinfrantz
*/
final class NamespacePathMap implements NamespacePathMapInterface
{
/**
* @var array|string[]
*/
private $folders;
/**
* @var string
*/
private $namespace;
/**
* @var string
*/
private $path;
/**
* {@inheritdoc}
*
* @see \App\Domain\PathManagement\NamespacePathMapInterface::getNamespace()
*/
public function getNamespace(): string
{
return $this->namespace;
}
/**
* {@inheritdoc}
*
* @see \App\Domain\PathManagement\NamespacePathMapInterface::getPath()
*/
public function getPath(): string
{
return $this->path;
}
/**
* {@inheritdoc}
*
* @see \App\Domain\PathManagement\NamespacePathMapInterface::setPath()
*/
public function setPath(string $path): void
{
}
/**
* {@inheritdoc}
*
* @see \App\Domain\PathManagement\NamespacePathMapInterface::setNamespace()
*/
public function setNamespace(string $namespace): void
{
}
/**
* {@inheritdoc}
*
* @see \App\Domain\PathManagement\NamespacePathMapInterface::setFolderArray()
*/
public function setFolderArray(array $folders): void
{
}
public function getFolderArray(): array
{
}
}

View File

@ -0,0 +1,41 @@
<?php
namespace App\Domain\PathManagement;
/**
* Allows to map a path to an namespace.
*
* @author kevinfrantz
*/
interface NamespacePathMapInterface
{
/**
* @param string $namespace
*/
public function setNamespace(string $namespace): void;
/**
* @param string $path
*/
public function setPath(string $path): void;
/**
* @return string
*/
public function getNamespace(): string;
/**
* @return string
*/
public function getPath(): string;
/**
* @param array|string[] $folders
*/
public function setFolderArray(array $folders): void;
/**
* @return array|string[]
*/
public function getFolderArray(): array;
}

View File

@ -3,12 +3,30 @@
namespace App\Domain\SourceManagement;
use App\Domain\EntityManagement\EntityMetaInformation;
use App\Entity\Source\AbstractSource;
/**
* @author kevinfrantz
*/
final class SourceMetaInformation extends EntityMetaInformation implements SourceMetaInformationInterface
{
const UNPURE = 'source';
/**
* {@inheritdoc}
*
* @see \App\Domain\EntityManagement\EntityMetaInformation::__construct()
*
* @param $entity AbstractSource
*/
public function __construct(\App\Entity\EntityInterface $entity)
{
if (!$entity instanceof AbstractSource) {
throw new \TypeError('Entity has to be an instance of '.AbstractSource::class);
}
parent::__construct($entity);
}
/**
* {@inheritdoc}
*
@ -17,6 +35,6 @@ final class SourceMetaInformation extends EntityMetaInformation implements Sourc
protected function setPureName(): void
{
parent::setPureName();
$this->pureName = str_replace('Source', '', $this->pureName);
$this->pureName = substr($this->pureName, 0, -strlen(self::UNPURE));
}
}

View File

@ -9,6 +9,10 @@ use App\DBAL\Types\RESTResponseType;
*/
final class TemplatePathInformation implements TemplatePathInformationInterface
{
const MOLECULE_FOLDER = 'molecule';
const ATOM_FOLDER = 'atom';
/**
* @var string
*/
@ -73,12 +77,12 @@ final class TemplatePathInformation implements TemplatePathInformationInterface
private function setMoleculeTemplatePath(): void
{
$this->moleculeTemplatePath = 'molecule/'.$this->suffix;
$this->moleculeTemplatePath = self::MOLECULE_FOLDER.'/'.$this->prefix.'/'.$this->suffix;
}
private function setAtomTemplatePath(): void
{
$this->atomTemplatePath = 'atom/'.$this->suffix;
$this->atomTemplatePath = self::ATOM_FOLDER.'/'.$this->prefix.'/'.$this->suffix;
}
/**

View File

@ -0,0 +1,36 @@
<?php
namespace Tests\Unit\Domain\FormManagement;
use PHPUnit\Framework\TestCase;
use App\Entity\Source\Primitive\Name\SurnameSource;
use App\Domain\FormManagement\FormMetaInformationInterface;
use App\Domain\SourceManagement\SourceMetaInformation;
use App\Domain\FormManagement\FormMetaInformation;
use App\Domain\TemplateManagement\TemplatePathInformationInterface;
class FormMetaInformationTest extends TestCase
{
/**
* @var FormMetaInformationInterface
*/
private $formMeta;
public function setUp(): void
{
$sourceMeta = new SourceMetaInformation(new SurnameSource());
$this->formMeta = new FormMetaInformation($sourceMeta);
}
public function testGetFormClass(): void
{
$this->assertEquals('App\Form\Source\Primitive\Name\SurnameType', $this->formMeta->getFormClass());
}
public function testTemplateMeta(): void
{
$templatePathInformation = $this->formMeta->getTemplatePathInformation();
$this->assertInstanceOf(TemplatePathInformationInterface::class, $templatePathInformation);
$this->assertEquals('atom/form/source/primitive/name/surname.html.twig', $templatePathInformation->getAtomTemplatePath());
}
}

View File

@ -1,34 +0,0 @@
<?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

@ -3,20 +3,20 @@
namespace Tests\Unit\Domain\SourceManagement;
use PHPUnit\Framework\TestCase;
use App\Domain\SourceManagement\SourceMetaInterface;
use App\Entity\Source\Complex\UserSource;
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;
use App\Domain\SourceManagement\SourceMetaInformation;
use App\Domain\SourceManagement\SourceMetaInformationInterface;
use App\Domain\TemplateManagement\TemplatePathFormAndViewInterface;
use App\Domain\FormManagement\FormMetaInformationInterface;
class SourceMetaTest extends TestCase
class SourceMetaInformationTest extends TestCase
{
/**
* @var SourceMetaInterface
* @var SourceMetaInformationInterface
*/
protected $sourceMeta;
protected $sourceMetaInformation;
/**
* @var SourceInterface
@ -26,20 +26,20 @@ class SourceMetaTest extends TestCase
public function setUp(): void
{
$this->source = new UserSource();
$this->sourceMeta = new SourceMeta($this->source);
$this->sourceMetaInformation = new SourceMetaInformation($this->source);
}
public function testBasicName(): void
{
$this->assertEquals('user', $this->sourceMeta->getBasicName());
$this->assertNotEquals('user2', $this->sourceMeta->getBasicName());
$this->assertEquals('user', $this->sourceMetaInformation->getPureName());
$this->assertNotEquals('user2', $this->sourceMetaInformation->getPureName());
}
public function testBasicPath(): void
{
$subset = ['source', 'complex'];
$amount = count($subset);
$basicPathArray = $this->sourceMeta->getBasicPathArray();
$basicPathArray = $this->sourceMetaInformation->getBasicPathArray();
for ($index = 0; $index < $amount; ++$index) {
$this->assertEquals($subset[$index], $basicPathArray[$index]);
}
@ -52,7 +52,7 @@ class SourceMetaTest extends TestCase
/**
* @var \ReflectionClass
*/
$interfaceReflection = $this->sourceMeta->getInterfaceReflection();
$interfaceReflection = $this->sourceMetaInformation->getInterfaceReflection();
$this->assertEquals(UserSourceInterface::class, $interfaceReflection->getName());
}
@ -61,22 +61,22 @@ class SourceMetaTest extends TestCase
/**
* @var \ReflectionClass
*/
$sourceReflection = $this->sourceMeta->getSourceReflection();
$sourceReflection = $this->sourceMetaInformation->getEntityReflection();
$this->assertEquals(UserSource::class, $sourceReflection->getName());
}
public function testTemplateMeta(): void
{
$this->assertInstanceOf(TemplateMetaInterface::class, $this->sourceMeta->getTemplateMeta());
$this->assertInstanceOf(TemplatePathFormAndViewInterface::class, $this->sourceMetaInformation->getTemplatePathFormAndView());
}
public function testSource(): void
{
$this->assertEquals($this->source, $this->sourceMeta->getSource());
$this->assertEquals($this->source, $this->sourceMetaInformation->getEntity());
}
public function testFormMeta(): void
{
$this->assertInstanceOf(FormMetaInterface::class, $this->sourceMeta->getFormMeta());
$this->assertInstanceOf(FormMetaInformationInterface::class, $this->sourceMetaInformation->getFormMetaInformation());
}
}

View File

@ -1,53 +0,0 @@
<?php
namespace Tests\Unit\Domain\TemplateManagement;
use PHPUnit\Framework\TestCase;
use App\Domain\TemplateManagement\TemplateMetaInterface;
use App\Entity\Source\Primitive\Name\FirstNameSource;
use App\Entity\Source\SourceInterface;
use App\Domain\TemplateManagement\TemplateMeta;
use App\Domain\SourceManagement\SourceMeta;
class TemplateMetaTest extends TestCase
{
/**
* @var TemplateMetaInterface
*/
protected $templateMeta;
/**
* @var SourceInterface
*/
protected $source;
private function getExpectedPath(string $type, string $context): string
{
return $context.'/entity/source/primitive/name/firstname.'.$type.'.twig';
}
public function setUp(): void
{
$this->source = new FirstNameSource();
$sourceMeta = new SourceMeta($this->source);
$this->templateMeta = new TemplateMeta($sourceMeta->getBasicPathArray(), $sourceMeta->getBasicName(), 'entity');
}
public function testFrameTemplatePath(): void
{
$this->assertEquals($this->getExpectedPath('html', 'frame'), $this->templateMeta->getFrameTemplatePath());
}
public function testContentTemplatePath(): void
{
$this->assertEquals($this->getExpectedPath('html', 'content'), $this->templateMeta->getContentTemplatePath());
}
public function testSetType(): void
{
$this->templateMeta->setTemplateType('json');
$this->assertEquals($this->getExpectedPath('json', 'content'), $this->templateMeta->getContentTemplatePath());
$this->assertEquals($this->getExpectedPath('json', 'frame'), $this->templateMeta->getFrameTemplatePath());
$this->assertEquals('json', $this->templateMeta->getTemplateType());
}
}

View File

@ -0,0 +1,62 @@
<?php
namespace Tests\Unit\Domain\TemplateManagement;
use PHPUnit\Framework\TestCase;
use App\Entity\Source\Primitive\Name\FirstNameSource;
use App\Entity\Source\SourceInterface;
use App\Domain\TemplateManagement\TemplatePathInformation;
use App\Domain\SourceManagement\SourceMetaInformation;
use App\DBAL\Types\RESTResponseType;
class TemplatePathInformationTest extends TestCase
{
/**
* @var TemplatePathInformation
*/
private $templateMeta;
/**
* @var SourceInterface
*/
private $source;
/**
* @param string $type
* @param string $context
*
* @return string
*/
private function getExpectedPath(string $type, string $context): string
{
return $context.'/entity/source/primitive/name/firstname.'.$type.'.twig';
}
public function setUp(): void
{
$this->source = new FirstNameSource();
$sourceMeta = new SourceMetaInformation($this->source);
$folder = implode('/', $sourceMeta->getBasicPathArray());
$this->templateMeta = new TemplatePathInformation($sourceMeta->getPureName(), $folder, 'entity');
}
public function testFrameTemplatePath(): void
{
$this->assertEquals($this->getExpectedPath('html', 'molecule'), $this->templateMeta->getMoleculeTemplatePath());
}
public function testContentTemplatePath(): void
{
$this->assertEquals($this->getExpectedPath('html', 'atom'), $this->templateMeta->getAtomTemplatePath());
}
public function testSetType(): void
{
foreach (RESTResponseType::getChoices() as $type) {
$this->templateMeta->reloadType($type);
$this->assertEquals($this->getExpectedPath($type, 'atom'), $this->templateMeta->getAtomTemplatePath());
$this->assertEquals($this->getExpectedPath($type, 'molecule'), $this->templateMeta->getMoleculeTemplatePath());
$this->assertEquals($type, $this->templateMeta->getTemplateType());
}
}
}