From 88a18bb60e28ba9dbabefb5582c9bbbf9372f72a Mon Sep 17 00:00:00 2001 From: virtualLast Date: Wed, 15 Jul 2026 17:39:55 +0100 Subject: [PATCH 1/3] added content attachement as return type and into the match statement --- src/Entity/AbstractContent.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Entity/AbstractContent.php b/src/Entity/AbstractContent.php index bb3bbe3..8ac08ee 100644 --- a/src/Entity/AbstractContent.php +++ b/src/Entity/AbstractContent.php @@ -268,10 +268,10 @@ public function addAncestor(int $id): self /** * @param mixed[] $data - * @return AbstractContent|ContentPage|ContentComment + * @return AbstractContent|ContentPage|ContentComment|ContentAttachment * @throws HydrationException */ - public static function load(array $data): ContentComment|AbstractContent|ContentPage + public static function load(array $data): ContentComment|AbstractContent|ContentPage|ContentAttachment { /* handle older content versions */ if(isset($data['content'], $data['when'])) { @@ -287,6 +287,7 @@ public static function load(array $data): ContentComment|AbstractContent|Content $content = match ($data['type']) { Content::CONTENT_TYPE_PAGE => new ContentPage(), Content::CONTENT_TYPE_COMMENT => new ContentComment(), + Content::CONTENT_TYPE_ATTACHMENT => new ContentAttachment(), default => throw new HydrationException('Invalid content type: ' . $data['type']), }; From e6db19b4365fedd79798072782a62f16fd14d79a Mon Sep 17 00:00:00 2001 From: virtualLast Date: Wed, 15 Jul 2026 17:42:55 +0100 Subject: [PATCH 2/3] content attachment entity --- src/Entity/ContentAttachment.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/Entity/ContentAttachment.php diff --git a/src/Entity/ContentAttachment.php b/src/Entity/ContentAttachment.php new file mode 100644 index 0000000..ccdf8d1 --- /dev/null +++ b/src/Entity/ContentAttachment.php @@ -0,0 +1,13 @@ + Date: Wed, 15 Jul 2026 17:46:58 +0100 Subject: [PATCH 3/3] tests for absract content + search result content loading the new attachment --- tests/Entity/ContentTest.php | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/Entity/ContentTest.php b/tests/Entity/ContentTest.php index 738dde3..9d132bb 100644 --- a/tests/Entity/ContentTest.php +++ b/tests/Entity/ContentTest.php @@ -9,7 +9,11 @@ namespace CloudPlayDev\Tests\ConfluenceClient\Entity; +use CloudPlayDev\ConfluenceClient\Entity\AbstractContent; +use CloudPlayDev\ConfluenceClient\Entity\ContentAttachment; use CloudPlayDev\ConfluenceClient\Entity\ContentPage; +use CloudPlayDev\ConfluenceClient\Entity\ContentSearchResult; +use CloudPlayDev\ConfluenceClient\Exception\HydrationException; use PHPUnit\Framework\TestCase; /** @@ -46,4 +50,37 @@ public function testSetId(): void self::assertSame(123, $confluencePage->getId()); } + public function testLoadAttachment(): void + { + $attachment = AbstractContent::load(self::attachmentPayload()); + + self::assertInstanceOf(ContentAttachment::class, $attachment); + self::assertSame('attachment', $attachment->getType()); + } + + public function testSearchResultLoadsAttachment(): void + { + $searchResult = ContentSearchResult::load([ + 'size' => 1, + 'results' => [self::attachmentPayload()], + ]); + + self::assertInstanceOf(ContentAttachment::class, $searchResult->getResultAt(0)); + } + + /** + * @return mixed[] + */ + private static function attachmentPayload(): array + { + return [ + 'id' => '123456', + 'type' => 'attachment', + 'title' => 'example.pdf', + '_links' => [ + 'self' => 'https://example.test/rest/api/content/123456', + ], + ]; + } + }