Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Ensure getHeaders() always returns an instance of Headers #141

Merged
merged 2 commits into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Storage/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ public function countParts()
* Lazy-loads if not already attached.
*
* @return Headers
* @throws Exception\RuntimeException
*/
public function getHeaders()
{
Expand All @@ -277,6 +278,11 @@ public function getHeaders()
$this->headers = new Headers();
}
}
if (!($this->headers instanceof Headers)) {
throw new Exception\RuntimeException(
'$this->headers must be an instance of Headers'
);
}

return $this->headers;
}
Expand Down
9 changes: 9 additions & 0 deletions test/Storage/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,15 @@ public function testEmptyHeader()
$this->setExpectedException('Zend\\Mail\\Exception\\InvalidArgumentException');
$message->subject;
}

public function testWrongHeaderType()
{
$this->setExpectedException('Zend\\Mail\\Exception\\RuntimeException');
$badMessge = unserialize(
"O:25:\"Zend\Mail\Storage\Message\":9:{s:8:\"\x00*\x00flags\";a:0:{}s:10:\"\x00*\x00headers\";s:16:\"Yellow submarine\";s:10:\"\x00*\x00content\";N;s:11:\"\x00*\x00topLines\";s:0:\"\";s:8:\"\x00*\x00parts\";a:0:{}s:13:\"\x00*\x00countParts\";N;s:15:\"\x00*\x00iterationPos\";i:1;s:7:\"\x00*\x00mail\";N;s:13:\"\x00*\x00messageNum\";i:0;}"
);
$this->getHeaders();
}

public function testEmptyBody()
{
Expand Down