Skip to content

Commit

Permalink
feat: make some TestEmail::assertHasFile() parameters optional
Browse files Browse the repository at this point in the history
  • Loading branch information
kbond committed Jan 11, 2023
1 parent a60b4e7 commit 673510d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/TestEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,11 @@ final public function assertTextContains(string $expected): self
/**
* @return static
*/
final public function assertHasFile(string $expectedFilename, string $expectedContentType, string $expectedContents): self
{
final public function assertHasFile(
string $expectedFilename,
?string $expectedContentType = null,
?string $expectedContents = null
): self {
foreach ($this->email->getAttachments() as $attachment) {
/** @var ParameterizedHeader $header */
$header = $attachment->getPreparedHeaders()->get('content-disposition');
Expand All @@ -246,7 +249,15 @@ final public function assertHasFile(string $expectedFilename, string $expectedCo
continue;
}

Assert::that($attachment->getBody())->is($expectedContents);
Assert::pass();

if ($expectedContents) {
Assert::that($attachment->getBody())->is($expectedContents);
}

if (!$expectedContentType) {
return $this;
}

/** @var ParameterizedHeader $header */
$header = $attachment->getPreparedHeaders()->get('content-type');
Expand Down
2 changes: 2 additions & 0 deletions tests/InteractsWithMailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public function can_assert_email_sent(string $environment): void
->assertHtmlContains('html body')
->assertTextContains('text body')
->assertContains('body')
->assertHasFile('attachment.txt')
->assertHasFile('attachment.txt', 'text/plain')
->assertHasFile('attachment.txt', 'text/plain', "attachment contents\n")
->assertHasFile('name with space.txt', 'text/plain', "attachment contents\n")
;
Expand Down

0 comments on commit 673510d

Please sign in to comment.