From 3ab9cb0e994b3511e1bedb69eb9b55923b35cf4b Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sun, 6 Jan 2019 15:42:40 +0100 Subject: [PATCH] Implemented test for exception --- .../src/Domain/SourceManagement/SourceMetaInformation.php | 3 ++- .../symfony/src/Exception/NotCorrectInstanceException.php | 7 +++++++ .../Domain/SourceManagement/SourceMetaInformationTest.php | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 application/symfony/src/Exception/NotCorrectInstanceException.php diff --git a/application/symfony/src/Domain/SourceManagement/SourceMetaInformation.php b/application/symfony/src/Domain/SourceManagement/SourceMetaInformation.php index cb98b89..8ef76c6 100644 --- a/application/symfony/src/Domain/SourceManagement/SourceMetaInformation.php +++ b/application/symfony/src/Domain/SourceManagement/SourceMetaInformation.php @@ -4,6 +4,7 @@ namespace App\Domain\SourceManagement; use App\Domain\EntityManagement\EntityMetaInformation; use App\Entity\Source\AbstractSource; +use App\Exception\NotCorrectInstanceException; /** * @author kevinfrantz @@ -22,7 +23,7 @@ final class SourceMetaInformation extends EntityMetaInformation implements Sourc public function __construct(\App\Entity\EntityInterface $entity) { 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); } diff --git a/application/symfony/src/Exception/NotCorrectInstanceException.php b/application/symfony/src/Exception/NotCorrectInstanceException.php new file mode 100644 index 0000000..1546858 --- /dev/null +++ b/application/symfony/src/Exception/NotCorrectInstanceException.php @@ -0,0 +1,7 @@ +assertInstanceOf(FormMetaInformationInterface::class, $this->sourceMetaInformation->getFormMetaInformation()); } + + public function testTypeError(): void + { + $this->expectException(NotCorrectInstanceException::class); + new SourceMetaInformation($this->createMock(EntityInterface::class)); + } }