Implemented test for exception

This commit is contained in:
Kevin Frantz 2019-01-06 15:42:40 +01:00
parent c7c4e1c16e
commit 3ab9cb0e99
3 changed files with 17 additions and 1 deletions

View File

@ -4,6 +4,7 @@ namespace App\Domain\SourceManagement;
use App\Domain\EntityManagement\EntityMetaInformation; use App\Domain\EntityManagement\EntityMetaInformation;
use App\Entity\Source\AbstractSource; use App\Entity\Source\AbstractSource;
use App\Exception\NotCorrectInstanceException;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -22,7 +23,7 @@ final class SourceMetaInformation extends EntityMetaInformation implements Sourc
public function __construct(\App\Entity\EntityInterface $entity) public function __construct(\App\Entity\EntityInterface $entity)
{ {
if (!$entity instanceof AbstractSource) { if (!$entity instanceof AbstractSource) {
throw new \TypeError('Entity has to be an instance of '.AbstractSource::class); throw new NotCorrectInstanceException('Entity has to be an instance of '.AbstractSource::class);
} }
parent::__construct($entity); parent::__construct($entity);
} }

View File

@ -0,0 +1,7 @@
<?php
namespace App\Exception;
class NotCorrectInstanceException extends \TypeError
{
}

View File

@ -10,6 +10,8 @@ use App\Domain\SourceManagement\SourceMetaInformation;
use App\Domain\SourceManagement\SourceMetaInformationInterface; use App\Domain\SourceManagement\SourceMetaInformationInterface;
use App\Domain\TemplateManagement\TemplatePathFormAndViewInterface; use App\Domain\TemplateManagement\TemplatePathFormAndViewInterface;
use App\Domain\FormManagement\FormMetaInformationInterface; use App\Domain\FormManagement\FormMetaInformationInterface;
use App\Entity\EntityInterface;
use App\Exception\NotCorrectInstanceException;
class SourceMetaInformationTest extends TestCase class SourceMetaInformationTest extends TestCase
{ {
@ -79,4 +81,10 @@ class SourceMetaInformationTest extends TestCase
{ {
$this->assertInstanceOf(FormMetaInformationInterface::class, $this->sourceMetaInformation->getFormMetaInformation()); $this->assertInstanceOf(FormMetaInformationInterface::class, $this->sourceMetaInformation->getFormMetaInformation());
} }
public function testTypeError(): void
{
$this->expectException(NotCorrectInstanceException::class);
new SourceMetaInformation($this->createMock(EntityInterface::class));
}
} }