infinito/application/symfony/tests/Unit/Domain/SourceManagement/SourceMetaInformationTest.php

95 lines
2.9 KiB
PHP
Raw Normal View History

2018-11-23 13:22:45 +01:00
<?php
namespace Tests\Unit\Domain\SourceManagement;
use PHPUnit\Framework\TestCase;
use Infinito\Entity\Source\Complex\UserSource;
use Infinito\Entity\Source\Complex\UserSourceInterface;
use Infinito\Entity\Source\SourceInterface;
use Infinito\Domain\SourceManagement\SourceMetaInformation;
use Infinito\Domain\SourceManagement\SourceMetaInformationInterface;
use Infinito\Domain\TemplateManagement\TemplatePathFormAndViewInterface;
use Infinito\Domain\FormManagement\FormMetaInformationInterface;
use Infinito\Entity\EntityInterface;
use Infinito\Exception\NotCorrectInstanceException;
2018-11-23 13:22:45 +01:00
class SourceMetaInformationTest extends TestCase
2018-11-23 13:22:45 +01:00
{
const FOLDERS = [
'source',
'complex',
];
2018-11-23 13:22:45 +01:00
/**
* @var SourceMetaInformationInterface
2018-11-23 13:22:45 +01:00
*/
private $sourceMetaInformation;
2018-11-23 13:22:45 +01:00
/**
* @var SourceInterface
*/
private $source;
2018-11-23 13:22:45 +01:00
public function setUp(): void
{
$this->source = new UserSource();
$this->sourceMetaInformation = new SourceMetaInformation($this->source);
2018-11-23 13:22:45 +01:00
}
public function testBasicName(): void
{
$this->assertEquals('user', $this->sourceMetaInformation->getPureName());
$this->assertNotEquals('user2', $this->sourceMetaInformation->getPureName());
2018-11-23 13:22:45 +01:00
}
public function testFolders(): void
2018-11-23 13:22:45 +01:00
{
$amount = count(self::FOLDERS);
$folders = $this->sourceMetaInformation->getNamespacePathMap()->getFolders();
2018-11-23 13:22:45 +01:00
for ($index = 0; $index < $amount; ++$index) {
$this->assertEquals(self::FOLDERS[$index], $folders[$index]);
2018-11-23 13:22:45 +01:00
}
$this->assertArraySubset(self::FOLDERS, $folders);
$this->assertEquals($amount, count($folders));
2018-11-23 13:22:45 +01:00
}
public function testInterfaceReflection(): void
{
/**
* @var \ReflectionClass
*/
$interfaceReflection = $this->sourceMetaInformation->getInterfaceReflection();
2018-11-23 13:22:45 +01:00
$this->assertEquals(UserSourceInterface::class, $interfaceReflection->getName());
}
public function testSourceReflection(): void
{
/**
* @var \ReflectionClass
*/
$sourceReflection = $this->sourceMetaInformation->getEntityReflection();
2018-11-23 13:22:45 +01:00
$this->assertEquals(UserSource::class, $sourceReflection->getName());
}
public function testTemplateMeta(): void
{
$this->assertInstanceOf(TemplatePathFormAndViewInterface::class, $this->sourceMetaInformation->getTemplatePathFormAndView());
2018-11-23 13:22:45 +01:00
}
public function testSource(): void
{
$this->assertEquals($this->source, $this->sourceMetaInformation->getEntity());
2018-11-23 13:22:45 +01:00
}
2018-11-23 16:50:37 +01:00
public function testFormMeta(): void
{
$this->assertInstanceOf(FormMetaInformationInterface::class, $this->sourceMetaInformation->getFormMetaInformation());
2018-11-23 16:50:37 +01:00
}
2019-01-06 15:42:40 +01:00
public function testTypeError(): void
{
$this->expectException(NotCorrectInstanceException::class);
new SourceMetaInformation($this->createMock(EntityInterface::class));
}
2018-11-23 13:22:45 +01:00
}