From 4be0116dd45f344ef6e1e3ad8674ded429e189c1 Mon Sep 17 00:00:00 2001 From: mattamon Date: Tue, 21 May 2024 08:46:30 +0200 Subject: [PATCH] Add hydratortest --- src/Dto/Dependency.php | 69 ----------------- .../Dependency/DependencyHydratorTest.php | 77 +++++++++++++++++++ 2 files changed, 77 insertions(+), 69 deletions(-) delete mode 100644 src/Dto/Dependency.php create mode 100644 tests/Unit/Dependency/DependencyHydratorTest.php diff --git a/src/Dto/Dependency.php b/src/Dto/Dependency.php deleted file mode 100644 index 840b73539..000000000 --- a/src/Dto/Dependency.php +++ /dev/null @@ -1,69 +0,0 @@ -dependency->getSourceId(); - } - - public function getRequires(int $offset = null, int $limit = null): array - { - return $this->dependency->getRequires($offset, $limit); - } - - public function getFilterRequiresByPath(int $offset = null, int $limit = null, string $value = null): array - { - return $this->dependency->getFilterRequiresByPath($offset, $limit, $value); - } - - public function getFilterRequiredByPath(int $offset = null, int $limit = null, string $value = null): array - { - return $this->dependency->getFilterRequiredByPath($offset, $limit, $value); - } - - public function getRequiredBy(int $offset = null, int $limit = null): array - { - return $this->dependency->getRequiredBy($offset, $limit); - } - - public function getSourceType(): string - { - return $this->dependency->getSourceType(); - } - - public function getRequiresTotalCount(): int - { - return $this->dependency->getRequiresTotalCount(); - } - - public function getRequiredByTotalCount(): int - { - return $this->dependency->getRequiredByTotalCount(); - } - - public function isRequired(): bool - { - return $this->dependency->isRequired(); - } -} diff --git a/tests/Unit/Dependency/DependencyHydratorTest.php b/tests/Unit/Dependency/DependencyHydratorTest.php new file mode 100644 index 000000000..da219f254 --- /dev/null +++ b/tests/Unit/Dependency/DependencyHydratorTest.php @@ -0,0 +1,77 @@ +getHydrator(); + + $dependency = $hydrator->hydrate(['id' => 1, 'type' => 'document']); + + $this->assertSame(1, $dependency->getId()); + $this->assertSame('/testtest', $dependency->getPath()); + $this->assertSame('document', $dependency->getType()); + $this->assertSame('page', $dependency->getSubType()); + $this->assertTrue($dependency->isPublished()); + $this->assertEmpty($dependency->getAdditionalAttributes()); + } + + + /** + * @throws Exception + */ + private function getHydrator(): DependencyHydratorInterface + { + return new DependencyHydrator($this->mockServiceResolver()); + } + + /** + * @throws Exception + */ + private function mockServiceResolver(): ServiceResolverInterface + { + return $this->makeEmpty(ServiceResolverInterface::class, + [ + 'getElementById' => $this->getDocument(), + 'getElementType' => 'document', + 'isPublished' => true, + ]); + } + + private function getDocument(): Document + { + $document = new Document(); + $document->setPath('/test'); + $document->setId(1); + $document->setType('page'); + $document->setKey('test'); + + return $document; + } +}