Skip to content

Commit

Permalink
[minor] add static return type for TestEmail methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kbond committed Oct 21, 2021
1 parent db31012 commit bedd52a
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/TestEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,47 +116,70 @@ final public function metadata(): array
return $metadata;
}

/**
* @return static
*/
final public function assertSubject(string $expected): self
{
Assert::that($this->email->getSubject())->is($expected);

return $this;
}

/**
* @return static
*/
final public function assertSubjectContains(string $needle): self
{
Assert::that($this->email->getSubject())->contains($needle);

return $this;
}

/**
* @return static
*/
final public function assertFrom(string $expectedEmail, ?string $expectedName = null): self
{
return $this->assertEmail($this->email->getFrom(), $expectedEmail, $expectedName, 'from');
}

/**
* @return static
*/
final public function assertTo(string $expectedEmail, ?string $expectedName = null): self
{
return $this->assertEmail($this->email->getTo(), $expectedEmail, $expectedName, 'to');
}

/**
* @return static
*/
final public function assertCc(string $expectedEmail, ?string $expectedName = null): self
{
return $this->assertEmail($this->email->getCc(), $expectedEmail, $expectedName, 'cc');
}

/**
* @return static
*/
final public function assertBcc(string $expectedEmail, ?string $expectedName = null): self
{
return $this->assertEmail($this->email->getBcc(), $expectedEmail, $expectedName, 'bcc');
}

/**
* @return static
*/
final public function assertReplyTo(string $expectedEmail, ?string $expectedName = null): self
{
return $this->assertEmail($this->email->getReplyTo(), $expectedEmail, $expectedName, 'reply-to');
}

/**
* Ensure both html and text contents contain the expected string.
*
* @return static
*/
final public function assertContains(string $expected): self
{
Expand All @@ -166,6 +189,9 @@ final public function assertContains(string $expected): self
;
}

/**
* @return static
*/
final public function assertHtmlContains(string $expected): self
{
Assert::that($this->email->getHtmlBody())
Expand All @@ -175,6 +201,9 @@ final public function assertHtmlContains(string $expected): self
return $this;
}

/**
* @return static
*/
final public function assertTextContains(string $expected): self
{
Assert::that($this->email->getTextBody())
Expand All @@ -184,6 +213,9 @@ final public function assertTextContains(string $expected): self
return $this;
}

/**
* @return static
*/
final public function assertHasFile(string $expectedFilename, string $expectedContentType, string $expectedContents): self
{
foreach ($this->email->getAttachments() as $attachment) {
Expand All @@ -202,6 +234,9 @@ final public function assertHasFile(string $expectedFilename, string $expectedCo
Assert::fail("Message does not include file with filename [{$expectedFilename}]");
}

/**
* @return static
*/
final public function assertHasTag(string $expected): self
{
Assert::that($this->tags())
Expand All @@ -212,6 +247,9 @@ final public function assertHasTag(string $expected): self
return $this;
}

/**
* @return static
*/
final public function assertHasMetadata(string $expectedKey, ?string $expectedValue = null): self
{
Assert::that($metadata = $this->metadata())->isNotEmpty('No metadata found.');
Expand All @@ -226,6 +264,9 @@ final public function assertHasMetadata(string $expectedKey, ?string $expectedVa
return $this;
}

/**
* @return static
*/
final public function dump(): self
{
\call_user_func(\function_exists('dump') ? 'dump' : 'var_dump', $this->email);
Expand Down

0 comments on commit bedd52a

Please sign in to comment.