Open jamesj2 opened 2 years ago
That is a great question and sorry I missed this question earlier. I'll look into that. That would be a good addition.
Any news on this ?
No news. I haven't been able to make time to make this addition. A PR is welcome, however ;)
Roughly 4 years ago, I had to implement my own mail interception as I didn't come across this library. I wanted to transition to this now but it lacks attachments api that I had already written. Here is the attachment part from my implementation which can give some direction if someone wants to implement it in this library:
public function assertMailHasAttachment($name = null, $mimeType = null)
{
$email = $this->lastEmail();
$attachments = collect($email->getAttachments())->filter(function (DataPart $dataPart) use ($mimeType, $name) {
$attachmentFilename = $dataPart->getPreparedHeaders()->getHeaderParameter('Content-Disposition', 'filename');
$attachmentMimeType = $dataPart->getPreparedHeaders()->getHeaderBody('Content-Type');
$valid = true;
if ($name) {
$valid = $valid && $attachmentFilename === $name;
}
if ($mimeType) {
$valid = $valid && $attachmentMimeType === $mimeType;
}
return $valid;
});
$helpMessage = "Could not find any attachment";
if ($name || $mimeType) {
$helpMessage .= " with " . collect(['name' => $name, 'mime type' => $mimeType])
->filter()
->map(fn($v, $key) => "$key \"$v\"")
->join(' and ');
}
Assert::assertNotEmpty($attachments, $helpMessage);
return $this;
}
Here is my full implementation:
Thank you for this! Hopefully I can get some extra time in the very near future to implement this.
Is there a way to assert attachments? I tried accessing them via intercepted mail collection but it's values are private.