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."