Skip to content

Commit

Permalink
Merge pull request #11 from kirschbaum-development/assertable-message…
Browse files Browse the repository at this point in the history
…-updates

Assertable message updates
  • Loading branch information
brandonferens authored May 20, 2022
2 parents 3fac474 + 793ec4d commit a1ead8c
Show file tree
Hide file tree
Showing 27 changed files with 937 additions and 128 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `mail-intercept` will be documented in this file

## 0.3.1 - 2022-05-20

- Better type-hinting for `AssertableMessage` class in assertions. Thank you [@amsoel](https://github.com/amsoell).

## 0.3.0 - 2022-03-08

- Upgraded for Laravel 9
Expand Down
4 changes: 2 additions & 2 deletions src/AssertableMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public function __construct(Email $email)
/**
* Dynamically pass missing methods to the Symfony instance.
*
* @param string $method
* @param array $parameters
* @param string $method
* @param array $parameters
*
* @return mixed
*/
Expand Down
9 changes: 5 additions & 4 deletions src/Assertions/BccAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

use Illuminate\Support\Arr;
use Symfony\Component\Mime\Email;
use KirschbaumDevelopment\MailIntercept\AssertableMessage;

trait BccAssertions
{
/**
* Assert mail was BCC'd to address.
*
* @param array|string $expected
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailBcc(array|string $expected, Email $mail)
public function assertMailBcc(array|string $expected, AssertableMessage | Email $mail): void
{
$expectedAddresses = Arr::wrap($expected);
$actualAddresses = $this->gatherEmailData('getBcc', $mail);
Expand All @@ -31,9 +32,9 @@ public function assertMailBcc(array|string $expected, Email $mail)
* Assert mail was not BCC'd to address.
*
* @param array|string $expected
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailNotBcc(array|string $expected, Email $mail)
public function assertMailNotBcc(array|string $expected, AssertableMessage | Email $mail): void
{
$addresses = Arr::wrap($expected);
$actualAddresses = $this->gatherEmailData('getBcc', $mail);
Expand Down
9 changes: 5 additions & 4 deletions src/Assertions/CcAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

use Illuminate\Support\Arr;
use Symfony\Component\Mime\Email;
use KirschbaumDevelopment\MailIntercept\AssertableMessage;

trait CcAssertions
{
/**
* Assert mail was CC'd to address.
*
* @param array|string $expected
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailCc(array|string $expected, Email $mail)
public function assertMailCc(array|string $expected, AssertableMessage | Email $mail): void
{
$expectedAddresses = Arr::wrap($expected);
$actualAddresses = $this->gatherEmailData('getCc', $mail);
Expand All @@ -31,9 +32,9 @@ public function assertMailCc(array|string $expected, Email $mail)
* Assert mail was not CC'd to address.
*
* @param array|string $expected
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailNotCc(array|string $expected, Email $mail)
public function assertMailNotCc(array|string $expected, AssertableMessage | Email $mail): void
{
$expectedAddresses = Arr::wrap($expected);
$actualAddresses = $this->gatherEmailData('getCc', $mail);
Expand Down
9 changes: 5 additions & 4 deletions src/Assertions/ContentAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
namespace KirschbaumDevelopment\MailIntercept\Assertions;

use Symfony\Component\Mime\Email;
use KirschbaumDevelopment\MailIntercept\AssertableMessage;

trait ContentAssertions
{
/**
* Assert mail body contains string.
*
* @param string $needle
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailBodyContainsString(string $needle, Email $mail)
public function assertMailBodyContainsString(string $needle, AssertableMessage | Email $mail): void
{
$method = method_exists($this, 'assertStringContainsString')
? 'assertStringContainsString'
Expand All @@ -29,9 +30,9 @@ public function assertMailBodyContainsString(string $needle, Email $mail)
* Assert mail body does not contain string.
*
* @param string $needle
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailBodyNotContainsString(string $needle, Email $mail)
public function assertMailBodyNotContainsString(string $needle, AssertableMessage | Email $mail): void
{
$method = method_exists($this, 'assertStringNotContainsString')
? 'assertStringNotContainsString'
Expand Down
49 changes: 25 additions & 24 deletions src/Assertions/ContentTypeAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Part\AbstractMultipartPart;
use KirschbaumDevelopment\MailIntercept\AssertableMessage;

trait ContentTypeAssertions
{
/**
* Assert mail content type is text/plain.
*
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailIsPlain(Email $mail)
public function assertMailIsPlain(AssertableMessage | Email $mail): void
{
$this->assertEquals(
'plain',
Expand All @@ -24,9 +25,9 @@ public function assertMailIsPlain(Email $mail)
/**
* Assert mail content type is not text/plain.
*
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailIsNotPlain(Email $mail)
public function assertMailIsNotPlain(AssertableMessage | Email $mail): void
{
$this->assertNotEquals(
'plain',
Expand All @@ -38,9 +39,9 @@ public function assertMailIsNotPlain(Email $mail)
/**
* Assert multipart email has text/plain content type.
*
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailHasPlainContent(Email $mail)
public function assertMailHasPlainContent(AssertableMessage | Email $mail): void
{
if ($mail->getBody() instanceof AbstractMultipartPart) {
$hasPlainContent = collect($mail->getBody()->getParts())
Expand All @@ -56,9 +57,9 @@ public function assertMailHasPlainContent(Email $mail)
/**
* Assert multipart email does not have text/plain content type.
*
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailDoesNotHavePlainContent(Email $mail)
public function assertMailDoesNotHavePlainContent(AssertableMessage | Email $mail): void
{
if ($mail->getBody() instanceof AbstractMultipartPart) {
$hasPlainContent = collect($mail->getBody()->getParts())
Expand All @@ -74,9 +75,9 @@ public function assertMailDoesNotHavePlainContent(Email $mail)
/**
* Assert mail content type is text/html.
*
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailIsHtml(Email $mail)
public function assertMailIsHtml(AssertableMessage | Email $mail): void
{
$this->assertEquals(
'html',
Expand All @@ -88,9 +89,9 @@ public function assertMailIsHtml(Email $mail)
/**
* Assert mail content type is not text/html.
*
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailIsNotHtml(Email $mail)
public function assertMailIsNotHtml(AssertableMessage | Email $mail): void
{
$this->assertNotEquals(
'html',
Expand All @@ -102,9 +103,9 @@ public function assertMailIsNotHtml(Email $mail)
/**
* Assert multipart email has text/html content type.
*
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailHasHtmlContent(Email $mail)
public function assertMailHasHtmlContent(AssertableMessage | Email $mail): void
{
if ($mail->getBody() instanceof AbstractMultipartPart) {
$hasHtmlContent = collect($mail->getBody()->getParts())
Expand All @@ -120,9 +121,9 @@ public function assertMailHasHtmlContent(Email $mail)
/**
* Assert multipart email does not have text/html content type.
*
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailDoesNotHaveHtmlContent(Email $mail)
public function assertMailDoesNotHaveHtmlContent(AssertableMessage | Email $mail): void
{
if ($mail->getBody() instanceof AbstractMultipartPart) {
$hasHtmlContent = collect($mail->getBody()->getParts())
Expand All @@ -138,9 +139,9 @@ public function assertMailDoesNotHaveHtmlContent(Email $mail)
/**
* Assert mail content type is multipart/alternative.
*
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailIsAlternative(Email $mail)
public function assertMailIsAlternative(AssertableMessage | Email $mail): void
{
$this->assertEquals(
'alternative',
Expand All @@ -152,9 +153,9 @@ public function assertMailIsAlternative(Email $mail)
/**
* Assert mail content type is not multipart/alternative.
*
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailIsNotAlternative(Email $mail)
public function assertMailIsNotAlternative(AssertableMessage | Email $mail): void
{
$this->assertNotEquals(
'alternative',
Expand All @@ -166,9 +167,9 @@ public function assertMailIsNotAlternative(Email $mail)
/**
* Assert mail content type is multipart/mixed.
*
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailIsMixed(Email $mail)
public function assertMailIsMixed(AssertableMessage | Email $mail): void
{
$this->assertEquals(
'mixed',
Expand All @@ -180,9 +181,9 @@ public function assertMailIsMixed(Email $mail)
/**
* Assert mail content type is not multipart/mixed.
*
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailIsNotMixed(Email $mail)
public function assertMailIsNotMixed(AssertableMessage | Email $mail): void
{
$this->assertNotEquals(
'mixed',
Expand Down
9 changes: 5 additions & 4 deletions src/Assertions/FromAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

use Illuminate\Support\Arr;
use Symfony\Component\Mime\Email;
use KirschbaumDevelopment\MailIntercept\AssertableMessage;

trait FromAssertions
{
/**
* Assert mail was sent from address.
*
* @param array|string $expected
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailSentFrom(array|string $expected, Email $mail)
public function assertMailSentFrom(array | string $expected, AssertableMessage | Email $mail): void
{
$expectedAddresses = Arr::wrap($expected);
$actualAddresses = $this->gatherEmailData('getFrom', $mail);
Expand All @@ -31,9 +32,9 @@ public function assertMailSentFrom(array|string $expected, Email $mail)
* Assert mail was not sent from address.
*
* @param array|string $expected
* @param Email $mail
* @param AssertableMessage|Email $mail
*/
public function assertMailNotSentFrom(array|string $expected, Email $mail)
public function assertMailNotSentFrom(array | string $expected, AssertableMessage | Email $mail): void
{
$expectedAddresses = Arr::wrap($expected);
$actualAddresses = $this->gatherEmailData('getFrom', $mail);
Expand Down
Loading

0 comments on commit a1ead8c

Please sign in to comment.