From 6c83ab1bde08ba71a77177af78439be7e6642f60 Mon Sep 17 00:00:00 2001 From: Rene Reimann Date: Mon, 8 Jun 2026 10:06:56 +0200 Subject: [PATCH] Fixes #52 - getAttachmentContent() to return string instead of Stream object --- README.md | 2 ++ src/Resource/TicketArticle.php | 3 +++ test/ZammadAPIClient/Resource/TicketArticleTest.php | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d7d6f51..36fd22f 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,8 @@ $attachment_content = $ticket_article->getAttachmentContent(23); In the above example 23 is the ID of the attachment. This ID can be found within the `attachments` array of the ticket article data. Usually you want to loop over this array to fetch the content of all attachments. +`getAttachmentContent()` returns the attachment content as a string, ready to use. + ### Updating Resource objects If you fetched a `Resource` object and changed some values, you have to send your changes to Zammad. You do this with a simple call: ```php diff --git a/src/Resource/TicketArticle.php b/src/Resource/TicketArticle.php index c36c71a..f14b2f6 100644 --- a/src/Resource/TicketArticle.php +++ b/src/Resource/TicketArticle.php @@ -117,6 +117,9 @@ public function getAttachmentContent($attachment_id) } $content = $response->getBody(); + if ( $content instanceof \Psr\Http\Message\StreamInterface ) { + $content = $content->getContents(); + } return $content; } } diff --git a/test/ZammadAPIClient/Resource/TicketArticleTest.php b/test/ZammadAPIClient/Resource/TicketArticleTest.php index f42b0f9..7eb4e3f 100644 --- a/test/ZammadAPIClient/Resource/TicketArticleTest.php +++ b/test/ZammadAPIClient/Resource/TicketArticleTest.php @@ -166,7 +166,7 @@ public function testCreate( $values, $expected_success ) // Fetch attachment content $content = $object->getAttachmentContent( $attachment['id'] ); - $this->assertEquals( + $this->assertSame( $expected_content, $content, "Content of file $filename must match expected one."