mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 05:47:11 +02:00
In between commit solving tests for meta and template management
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
@@ -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());
|
||||
}
|
||||
}
|
@@ -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());
|
||||
}
|
||||
}
|
@@ -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());
|
||||
}
|
||||
}
|
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user