├── .github └── workflows │ └── run-tests.yml ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── composer.json ├── phpunit.xml.dist ├── pint.json ├── screenshots └── banner.jpg ├── src ├── AssertableMessage.php ├── Assertions │ ├── AttachmentAssertions.php │ ├── BccAssertions.php │ ├── CcAssertions.php │ ├── ContentAssertions.php │ ├── ContentTypeAssertions.php │ ├── FromAssertions.php │ ├── PriorityAssertions.php │ ├── ReplyToAssertions.php │ ├── ReturnPathAssertions.php │ ├── SenderAssertions.php │ ├── SubjectAssertions.php │ ├── ToAssertions.php │ └── UnstructuredHeaderAssertions.php └── WithMailInterceptor.php └── tests ├── Architecture ├── AssertableMessageTest.php ├── AssertionsTest.php ├── PresetTest.php └── TraitTest.php ├── AttachmentAssertionsTest.php ├── BccAssertionsTest.php ├── CcAssertionsTest.php ├── ContentAssertionsTest.php ├── ContentTypeAssertionsTest.php ├── EnableInterceptionTest.php ├── Fixtures └── f-18.jpg ├── Fluent ├── AttachmentAssertionsTest.php ├── BccAssertionsTest.php ├── CcAssertionsTest.php ├── ContentAssertionsTest.php ├── ContentTypeAssertionsTest.php ├── FromAssertionsTest.php ├── PriorityAssertionsTest.php ├── ReplyToAssertionsTest.php ├── ReturnPathAssertionsTest.php ├── SenderAssertionsTest.php ├── SubjectAssertionsTest.php ├── ToAssertionsTest.php └── UnstructuredHeaderAssertionsTest.php ├── FromAssertionsTest.php ├── PriorityAssertionsTest.php ├── ReplyToAssertionsTest.php ├── ReturnPathAssertionsTest.php ├── SenderAssertionsTest.php ├── SubjectAssertionsTest.php ├── TestCase.php ├── ToAssertionsTest.php └── UnstructuredHeaderAssertionsTest.php /.github/workflows/run-tests.yml: -------------------------------------------------------------------------------- 1 | on: push 2 | name: CI 3 | 4 | jobs: 5 | pest: 6 | runs-on: ubuntu-24.04 7 | timeout-minutes: 5 8 | 9 | strategy: 10 | fail-fast: true 11 | matrix: 12 | php: [ 8.1, 8.2, 8.3, 8.4 ] 13 | laravel: [ 10.*, 11.*, 12.* ] 14 | include: 15 | - php: 8.1 16 | laravel: 10.* 17 | pest: 2.* 18 | testbench: 8.* 19 | - php: 8.2 20 | laravel: 10.* 21 | pest: 2.* 22 | testbench: 8.* 23 | - php: 8.3 24 | laravel: 10.* 25 | pest: 2.* 26 | testbench: 8.* 27 | - php: 8.4 28 | laravel: 10.* 29 | pest: 2.* 30 | testbench: 8.* 31 | - php: 8.2 32 | laravel: 11.* 33 | pest: 3.* 34 | testbench: 9.* 35 | - php: 8.3 36 | laravel: 11.* 37 | pest: 3.* 38 | testbench: 9.* 39 | - php: 8.4 40 | laravel: 11.* 41 | pest: 3.* 42 | testbench: 9.* 43 | - php: 8.2 44 | laravel: 12.* 45 | pest: 3.* 46 | testbench: 10.* 47 | - php: 8.3 48 | laravel: 12.* 49 | pest: 3.* 50 | testbench: 10.* 51 | - php: 8.4 52 | laravel: 12.* 53 | pest: 3.* 54 | testbench: 10.* 55 | exclude: 56 | - php: 8.1 57 | laravel: 11.* 58 | - php: 8.1 59 | laravel: 12.* 60 | 61 | name: Mail Intercept Tests - PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} 62 | 63 | steps: 64 | - name: Checkout code 65 | uses: actions/checkout@v4 66 | 67 | - name: Cache dependencies 68 | uses: actions/cache@v4 69 | with: 70 | path: ~/.composer/cache/files 71 | key: dependencies-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} 72 | 73 | - name: Setup PHP 74 | uses: shivammathur/setup-php@v2 75 | with: 76 | php-version: ${{ matrix.php }} 77 | extensions: curl, mbstring, zip, pcntl, iconv 78 | coverage: none 79 | tools: composer:v2 80 | 81 | - name: Install dependencies 82 | run: | 83 | composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update 84 | composer require "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update 85 | composer require "pestphp/pest:${{ matrix.pest }}" "pestphp/pest-plugin-laravel:${{ matrix.pest }}" "pestphp/pest-plugin-type-coverage:${{ matrix.pest }}" --no-interaction --no-update 86 | composer update --prefer-dist --no-interaction 87 | composer dump 88 | 89 | - name: Execute tests 90 | run: composer pest 91 | 92 | pint: 93 | runs-on: ubuntu-24.04 94 | timeout-minutes: 5 95 | 96 | name: Pint Style Check 97 | steps: 98 | - name: Checkout code 99 | uses: actions/checkout@v4 100 | 101 | - name: Cache dependencies 102 | uses: actions/cache@v4 103 | with: 104 | path: ~/.composer/cache/files 105 | key: dependencies-composer-${{ hashFiles('composer.json') }} 106 | 107 | - name: Setup PHP 108 | uses: shivammathur/setup-php@v2 109 | with: 110 | php-version: 8.3 111 | tools: composer:v2 112 | 113 | - name: Install dependencies 114 | run: | 115 | composer install --no-interaction 116 | composer dump 117 | 118 | - name: Execute Pint 119 | run: composer pint-check -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /vendor 3 | composer.phar 4 | composer.lock 5 | phpunit.xml 6 | .phpunit.result.cache 7 | .phpunit.cache 8 | .DS_Store 9 | Thumbs.db 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `mail-intercept` will be documented in this file 4 | 5 | ## 1.0.0 - 2024-10-21 6 | 7 | - Bumped minimum requirement to Laravel 10 and PHP 8.1. 8 | - New attachment and embedded image assertions. 9 | - Pest architecture tests. 10 | - Replace PHP CS Fixer with Laravel Pint. 11 | 12 | ## 0.5.0 - 2024-03-18 13 | 14 | - Added Laravel 11 support. 15 | 16 | ## 0.4.0 - 2023-04-05 17 | 18 | - Added Laravel 10 support. Thank you [@cstriuli](https://github.com/cstriuli). 19 | - Added PHP 8.2 test runners. 20 | 21 | ## 0.3.2 - 2022-06-14 22 | 23 | - Fixed bug allowing email body to be asserted properly whether it is HTML or text. Thanks [@therobfonz](https://github.com/therobfonz). 24 | 25 | ## 0.3.1 - 2022-05-20 26 | 27 | - Better type-hinting for `AssertableMessage` class in assertions. Thank you [@amsoel](https://github.com/amsoell). 28 | 29 | ## 0.3.0 - 2022-03-08 30 | 31 | - Upgraded for Laravel 9 32 | - New fluent syntax for making assertions directly on each message. 33 | - Added new assertions methods: 34 | - `assertMailHasPlainContent` 35 | - `assertMailDoesNotHavePlainContent` 36 | - `assertMailHasHtmlContent` 37 | - `assertMailDoesNotHaveHtmlContent` 38 | - `assertMailIsAlternative` 39 | - `assertMailIsNotAlternative` 40 | - `assertMailIsMixed` 41 | - `assertMailIsNotMixed` 42 | - `assertMailPriority` 43 | - `assertMailNotPriority` 44 | - `assertMailPriorityIsHighest` 45 | - `assertMailPriorityNotHighest` 46 | - `assertMailPriorityIsHigh` 47 | - `assertMailPriorityNotHigh` 48 | - `assertMailPriorityIsNormal` 49 | - `assertMailPriorityNotNormal` 50 | - `assertMailPriorityIsLow` 51 | - `assertMailPriorityNotLow` 52 | - `assertMailPriorityIsLowest` 53 | - `assertMailPriorityNotLowest` 54 | - `assertMailReturnPath` 55 | - `assertMailNotReturnPath` 56 | 57 | ## 0.2.2 - 2020-03-11 58 | 59 | - Added coverage for string assertion deprecations if using PHPUnit < 8.0 60 | 61 | ## 0.2.1 - 2020-03-11 62 | 63 | - Fixed composer install command 64 | 65 | ## 0.2.0 - 2020-02-06 66 | 67 | - Added new assertions for sender, cc, bcc, content type, and reply to 68 | - Refactored to, from, and subject to use different getters 69 | - Update readme to include new assertions 70 | 71 | ## 0.1.0 - 2019-12-06 72 | 73 | - Initial release 74 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Kirschbaum Development Group, LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Mail Intercept banner](screenshots/banner.jpg) 2 | 3 | # Laravel Mail Intercept 4 | ### A testing package for intercepting mail sent from Laravel 5 | 6 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/kirschbaum-development/mail-intercept.svg)](https://packagist.org/packages/kirschbaum-development/mail-intercept) 7 | [![Total Downloads](https://img.shields.io/packagist/dt/kirschbaum-development/mail-intercept.svg)](https://packagist.org/packages/kirschbaum-development/mail-intercept) 8 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/cc0749987c38426ebc8b0059c1171e27)](https://www.codacy.com/manual/Kirschbaum/mail-intercept?utm_source=github.com&utm_medium=referral&utm_content=kirschbaum-development/mail-intercept&utm_campaign=Badge_Grade) 9 | [![Actions Status](https://github.com/kirschbaum-development/mail-intercept/workflows/CI/badge.svg)](https://github.com/kirschbaum-development/mail-intercept/actions) 10 | 11 | This testing suite intercepts Laravel Mail just before they are sent out, allowing all kinds of assertions to be made on the actual emails themselves. 12 | 13 | Mail isn't faked here. You get to inspect the actual mail ensuring you are sending exactly what you want! 14 | 15 | ## Requirements 16 | 17 | | Laravel Version | Mail Intercept Version | 18 | |:----------------|:-----------------------| 19 | | 10.x & 11.0 | 1.0.x | 20 | | 9.x | 0.3.x | 21 | | 8.x and lower | 0.2.x | 22 | 23 | Please note: If you are using `v0.2.x`, please refer to that version's [documentation](https://github.com/kirschbaum-development/mail-intercept/tree/v0.2.x). 24 | 25 | ## Installation 26 | 27 | ```bash 28 | composer require kirschbaum-development/mail-intercept --dev 29 | ``` 30 | 31 | ## Usage 32 | 33 | Next you can use the `KirschbaumDevelopment\MailIntercept\WithMailInterceptor` trait in your test class: 34 | 35 | ```php 36 | namespace Tests; 37 | 38 | use App\Mail\TestMail; 39 | use Illuminate\Support\Facades\Mail; 40 | use Illuminate\Foundation\Testing\WithFaker; 41 | use KirschbaumDevelopment\MailIntercept\WithMailInterceptor; 42 | 43 | class MailTest extends TestCase 44 | { 45 | use WithFaker; 46 | use WithMailInterceptor; 47 | 48 | public function testMail() 49 | { 50 | $this->interceptMail(); 51 | 52 | $email = $this->faker->email; 53 | 54 | Mail::to($email)->send(new TestMail()); 55 | 56 | $interceptedMail = $this->interceptedMail()->first(); 57 | 58 | $interceptedMail->assertSentTo($email); 59 | } 60 | } 61 | ``` 62 | 63 | That's it! Pretty simple, right?! 64 | 65 | There are two ways of accessing the assertions. First is the fluent syntax directly on each intercepted email. 66 | 67 | ```php 68 | $interceptedMail->assertSentTo($email); 69 | ``` 70 | 71 | The other way (the older way) is to use the assertions methods made available from the `WithMailInterceptor` trait. Using these methods are fine, but aren't as clean to write. 72 | 73 | ```php 74 | $this->assertMailSentTo($email, $interceptedEmail); 75 | ``` 76 | 77 | Both of these assertions do the exact same thing, the fluent one is just much cleaner. See all the available assertion methods below! 78 | 79 | ### Testing API 80 | 81 | ```php 82 | $this->interceptMail() 83 | ``` 84 | 85 | This method MUST be called first, similar to how `Mail::fake()` works. But unlike the mail fake, mail is not faked, it is intercepted. 86 | 87 | ```php 88 | $this->interceptedMail() 89 | ``` 90 | 91 | This should be called after `Mail` has been sent, but before your assertions, otherwise you won't have any emails to work with. It returns a `Collection` of emails so you are free to use any of the methods available to a collection. 92 | 93 | #### Fluent Assertion Methods 94 | 95 | | Assertions | Parameters | 96 | |:-------------------------------------------------------|:------------------------| 97 | | `$intercepted->assertSentTo($to);` | `$to` array, string | 98 | | `$intercepted->assertNotSentTo($to);` | `$to` array, string | 99 | | `$intercepted->assertSentFrom($from);` | `$from` array, string | 100 | | `$intercepted->assertNotSentFrom($from);` | `$from` array, string | 101 | | `$intercepted->assertSubject($subject);` | `$subject` string | 102 | | `$intercepted->assertNotSubject($subject);` | `$subject` string | 103 | | `$intercepted->assertBodyContainsString($content);` | `$content` string | 104 | | `$intercepted->assertBodyNotContainsString($content);` | `$content` string | 105 | | `$intercepted->assertRepliesTo($reply);` | `$reply` array, string | 106 | | `$intercepted->assertNotRepliesTo($reply);` | `$reply` array, string | 107 | | `$intercepted->assertCc($cc);` | `$cc` array, string | 108 | | `$intercepted->assertNotCc($cc);` | `$cc` array, string | 109 | | `$intercepted->assertBcc($cc);` | `$bcc` array, string | 110 | | `$intercepted->assertNotBcc($cc);` | `$bcc` array, string | 111 | | `$intercepted->assertSender($sender);` | `$sender` array, string | 112 | | `$intercepted->assertNotSender($sender);` | `$sender` array, string | 113 | | `$intercepted->assertReturnPath($returnPath);` | `$returnPath` string | 114 | | `$intercepted->assertNotReturnPath($returnPath);` | `$returnPath` string | 115 | 116 | | Content Type Assertions | 117 | |:-------------------------------------------------| 118 | | `$intercepted->assertIsPlain();` | 119 | | `$intercepted->assertIsNotPlain();` | 120 | | `$intercepted->assertHasPlainContent();` | 121 | | `$intercepted->assertDoesNotHavePlainContent();` | 122 | | `$intercepted->assertIsHtml();` | 123 | | `$intercepted->assertIsNotHtml();` | 124 | | `$intercepted->assertHasHtmlContent();` | 125 | | `$intercepted->assertDoesNotHaveHtmlContent();` | 126 | | `$intercepted->assertIsAlternative();` | 127 | | `$intercepted->assertIsNotAlternative();` | 128 | | `$intercepted->assertIsMixed();` | 129 | | `$intercepted->assertIsNotMixed();` | 130 | 131 | | Header Assertions | Parameters | 132 | |:----------------------------------------------------|:-------------------------------------| 133 | | `$intercepted->assertHasHeader($header);` | `$header` string | 134 | | `$intercepted->assertMissingHeader($header);` | `$header` string | 135 | | `$intercepted->assertHeaderIs($header, $value);` | `$header` string
`$value` string | 136 | | `$intercepted->assertHeaderIsNot($header, $value);` | `$header` string
`$value` string | 137 | 138 | | Priority Assertions | Parameters | 139 | |:----------------------------------------------|:----------------| 140 | | `$intercepted->assertPriority($priority);` | `$priority` int | 141 | | `$intercepted->assertNotPriority($priority);` | `$priority` int | 142 | | `$intercepted->assertPriorityIsHighest();` | | 143 | | `$intercepted->assertPriorityNotHighest();` | | 144 | | `$intercepted->assertPriorityIsHigh();` | | 145 | | `$intercepted->assertPriorityNotHigh();` | | 146 | | `$intercepted->assertPriorityIsNormal();` | | 147 | | `$intercepted->assertPriorityNotNormal();` | | 148 | | `$intercepted->assertPriorityIsLow();` | | 149 | | `$intercepted->assertPriorityNotLow();` | | 150 | | `$intercepted->assertPriorityIsLowest();` | | 151 | | `$intercepted->assertPriorityIsLowest();` | | 152 | 153 | | Attachment Assertions | Parameters | 154 | |:-------------------------------------------------------|:-------------------| 155 | | `$intercepted->assertHasAttachment($filename);` | `$filename` string | 156 | | `$intercepted->assertHasAttachments();` | | 157 | | `$intercepted->assertMissingAttachment($filename);` | `$filename` string | 158 | | `$intercepted->assertMissingAttachments();` | | 159 | | `$intercepted->assertHasEmbeddedImage($filename);` | `$filename` string | 160 | | `$intercepted->assertHasEmbeddedImages();` | | 161 | | `$intercepted->assertMissingEmbeddedImage($filename);` | `$filename` string | 162 | | `$intercepted->assertMissingEmbeddedImages();` | | 163 | 164 | #### Assertion Methods 165 | 166 | | Assertions | Parameters | 167 | |:-----------------------------------------------------------|:-------------------------------------------------------------| 168 | | `$this->assertMailSentTo($to, $mail);` | `$to` array, string
`$mail` AssertableMessage, Email | 169 | | `$this->assertMailNotSentTo($to, $mail);` | `$to` array, string
`$mail` AssertableMessage, Email | 170 | | `$this->assertMailSentFrom($from, $mail);` | `$from` array, string
`$mail` AssertableMessage, Email | 171 | | `$this->assertMailNotSentFrom($from, $mail);` | `$from` array, string
`$mail` AssertableMessage, Email | 172 | | `$this->assertMailSubject($subject, $mail);` | `$subject` string
`$mail` AssertableMessage, Email | 173 | | `$this->assertMailNotSubject($subject, $mail);` | `$subject` string
`$mail` AssertableMessage, Email | 174 | | `$this->assertMailBodyContainsString($content, $mail);` | `$content` string
`$mail` AssertableMessage, Email | 175 | | `$this->assertMailBodyNotContainsString($content, $mail);` | `$content` string
`$mail` AssertableMessage, Email | 176 | | `$this->assertMailRepliesTo($reply, $mail);` | `$reply` array, string
`$mail` AssertableMessage, Email | 177 | | `$this->assertMailNotRepliesTo($reply, $mail);` | `$reply` array, string
`$mail` AssertableMessage, Email | 178 | | `$this->assertMailCc($cc, $mail);` | `$cc` array, string
`$mail` AssertableMessage, Email | 179 | | `$this->assertMailNotCc($cc, $mail);` | `$cc` array, string
`$mail` AssertableMessage, Email | 180 | | `$this->assertMailBcc($cc, $mail);` | `$bcc` array, string
`$mail` AssertableMessage, Email | 181 | | `$this->assertMailNotBcc($cc, $mail);` | `$bcc` array, string
`$mail` AssertableMessage, Email | 182 | | `$this->assertMailSender($sender, $mail);` | `$sender` array, string
`$mail` AssertableMessage, Email | 183 | | `$this->assertMailNotSender($sender, $mail);` | `$sender` array, string
`$mail` AssertableMessage, Email | 184 | | `$this->assertMailReturnPath($returnPath, $mail);` | `$returnPath` string
`$mail` AssertableMessage, Email | 185 | | `$this->assertMailNotReturnPath($returnPath, $mail);` | `$returnPath` string
`$mail` AssertableMessage, Email | 186 | 187 | | Content Type Assertions | Parameters | 188 | |:---------------------------------------------------|:---------------------------------| 189 | | `$this->assertMailIsPlain($mail);` | `$mail` AssertableMessage, Email | 190 | | `$this->assertMailIsNotPlain($mail);` | `$mail` AssertableMessage, Email | 191 | | `$this->assertMailHasPlainContent($mail);` | `$mail` AssertableMessage, Email | 192 | | `$this->assertMailDoesNotHavePlainContent($mail);` | `$mail` AssertableMessage, Email | 193 | | `$this->assertMailIsHtml($mail);` | `$mail` AssertableMessage, Email | 194 | | `$this->assertMailIsNotHtml($mail);` | `$mail` AssertableMessage, Email | 195 | | `$this->assertMailHasHtmlContent($mail);` | `$mail` AssertableMessage, Email | 196 | | `$this->assertMailDoesNotHaveHtmlContent($mail);` | `$mail` AssertableMessage, Email | 197 | | `$this->assertMailIsAlternative($mail);` | `$mail` AssertableMessage, Email | 198 | | `$this->assertMailIsNotAlternative($mail);` | `$mail` AssertableMessage, Email | 199 | | `$this->assertMailIsMixed($mail);` | `$mail` AssertableMessage, Email | 200 | | `$this->assertMailIsNotMixed($mail);` | `$mail` AssertableMessage, Email | 201 | 202 | | Header Assertions | Parameters | 203 | |:--------------------------------------------------------|:--------------------------------------------------------------------------| 204 | | `$this->assertMailHasHeader($header, $mail);` | `$header` string
`$mail` AssertableMessage, Email | 205 | | `$this->assertMailMissingHeader($header, $mail);` | `$header` string
`$mail` AssertableMessage, Email | 206 | | `$this->assertMailHeaderIs($header, $value, $mail);` | `$header` string
`$value` string
`$mail` AssertableMessage, Email | 207 | | `$this->assertMailHeaderIsNot($header, $value, $mail);` | `$header` string
`$value` string
`$mail` AssertableMessage, Email | 208 | 209 | | Priority Assertions | Parameters | 210 | |:--------------------------------------------------|:-----------------------------------------------------| 211 | | `$this->assertMailPriority($priority, $mail);` | `$priority` int
`$mail` AssertableMessage, Email | 212 | | `$this->assertMailNotPriority($priority, $mail);` | `$priority` int
`$mail` AssertableMessage, Email | 213 | | `$this->assertMailPriorityIsHighest($mail);` | `$mail` AssertableMessage, Email | 214 | | `$this->assertMailPriorityNotHighest($mail);` | `$mail` AssertableMessage, Email | 215 | | `$this->assertMailPriorityIsHigh($mail);` | `$mail` AssertableMessage, Email | 216 | | `$this->assertMailPriorityNotHigh($mail);` | `$mail` AssertableMessage, Email | 217 | | `$this->assertMailPriorityIsNormal($mail);` | `$mail` AssertableMessage, Email | 218 | | `$this->assertMailPriorityNotNormal($mail);` | `$mail` AssertableMessage, Email | 219 | | `$this->assertMailPriorityIsLow($mail);` | `$mail` AssertableMessage, Email | 220 | | `$this->assertMailPriorityNotLow($mail);` | `$mail` AssertableMessage, Email | 221 | | `$this->assertMailPriorityIsLowest($mail);` | `$mail` AssertableMessage, Email | 222 | | `$this->assertMailPriorityIsLowest($mail);` | `$mail` AssertableMessage, Email | 223 | 224 | | Attachment Assertions | Parameters | 225 | |:---------------------------------------------------|:--------------------------------------------------------| 226 | | `this->assertMailHasAttachment($filename);` | `$filename` string
`$mail` AssertableMessage, Email | 227 | | `this->assertMailHasAttachments();` | `$mail` AssertableMessage, Email | 228 | | `this->assertMailMissingAttachment($filename);` | `$filename` string
`$mail` AssertableMessage, Email | 229 | | `this->assertMailMissingAttachments();` | `$mail` AssertableMessage, Email | 230 | | `this->assertMailHasEmbeddedImage($filename);` | `$filename` string
`$mail` AssertableMessage, Email | 231 | | `this->assertMailHasEmbeddedImages();` | `$mail` AssertableMessage, Email | 232 | | `this->assertMailMissingEmbeddedImage($filename);` | `$filename` string
`$mail` AssertableMessage, Email | 233 | | `this->assertMailMissingEmbeddedImages();` | `$mail` AssertableMessage, Email | 234 | 235 | You should use each item of the `interceptedMail()` collection as the mail object for all assertions. 236 | 237 | If you are injecting your own headers or need access to other headers in the email, use this assertion to verify they exist and are set properly. These assertions require the header name and the compiled email. 238 | 239 | ### Other assertions 240 | 241 | Since `$this->interceptedMail()` returns a collection of `AssertableMessage` objects. You are free to dissect and look into those objects using any methods available to Symfony's Email API. Head over to the [Symfony Email Docs](https://symfony.com/doc/current/mailer.html) for more detailed info. 242 | 243 | ## Changelog 244 | 245 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 246 | 247 | ## Contributing 248 | 249 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 250 | 251 | ### Security 252 | 253 | If you discover any security related issues, please email brandon@kirschbaumdevelopment.com or nathan@kirschbaumdevelopment.com instead of using the issue tracker. 254 | 255 | ## Credits 256 | 257 | - [Brandon Ferens](https://github.com/brandonferens) 258 | - [Michael Fox](https://github.com/michaelfox) 259 | 260 | ## Sponsorship 261 | 262 | Development of this package is sponsored by Kirschbaum Development Group, a developer driven company focused on problem solving, team building, and community. Learn more [about us](https://kirschbaumdevelopment.com) or [join us](https://careers.kirschbaumdevelopment.com)! 263 | 264 | ## License 265 | 266 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 267 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kirschbaum-development/mail-intercept", 3 | "description": "A test package for intercepting email sent from Laravel", 4 | "keywords": [ 5 | "laravel", 6 | "symfony mailer", 7 | "test", 8 | "email" 9 | ], 10 | "homepage": "https://github.com/kirschbaum-development/mail-intercept", 11 | "license": "MIT", 12 | "authors": [ 13 | { 14 | "name": "Brandon Ferens", 15 | "email": "brandon@kirschbaumdevelopment.com", 16 | "role": "Developer" 17 | } 18 | ], 19 | "require": { 20 | "php": "^8.1|^8.2", 21 | "illuminate/mail": "^10.0|^11.0|^12.0" 22 | }, 23 | "require-dev": { 24 | "laravel/pint": "^1.18", 25 | "orchestra/testbench": "^8.0|^9.0|^10.0", 26 | "pestphp/pest": "^2.36|^3.4", 27 | "phpunit/phpunit": "^10.1|^11.0", 28 | "spatie/ray": "^1.41.1" 29 | }, 30 | "autoload": { 31 | "psr-4": { 32 | "KirschbaumDevelopment\\MailIntercept\\": "src/" 33 | } 34 | }, 35 | "autoload-dev": { 36 | "psr-4": { 37 | "Tests\\": "tests/" 38 | } 39 | }, 40 | "scripts": { 41 | "pest": [ 42 | "./vendor/bin/pest" 43 | ], 44 | "pint": [ 45 | "./vendor/bin/pint" 46 | ], 47 | "pint-check": [ 48 | "./vendor/bin/pint --test" 49 | ], 50 | "test": [ 51 | "./vendor/bin/phpunit" 52 | ] 53 | }, 54 | "config": { 55 | "sort-packages": true, 56 | "allow-plugins": { 57 | "pestphp/pest-plugin": true 58 | } 59 | }, 60 | "minimum-stability": "dev", 61 | "prefer-stable": true 62 | } 63 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | tests 6 | 7 | 8 | 9 | 10 | 11 | src/ 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /pint.json: -------------------------------------------------------------------------------- 1 | { 2 | "preset": "laravel", 3 | "rules": { 4 | "blank_line_before_statement": { 5 | "statements": [ 6 | "break", 7 | "case", 8 | "continue", 9 | "declare", 10 | "default", 11 | "do", 12 | "exit", 13 | "for", 14 | "foreach", 15 | "if", 16 | "include", 17 | "include_once", 18 | "require", 19 | "require_once", 20 | "return", 21 | "switch", 22 | "throw", 23 | "try", 24 | "while", 25 | "yield" 26 | ] 27 | }, 28 | "class_definition": { 29 | "multi_line_extends_each_single_line": true, 30 | "single_item_single_line": true, 31 | "single_line": false 32 | }, 33 | "concat_space": { 34 | "spacing": "one" 35 | }, 36 | "explicit_string_variable": true, 37 | "method_chaining_indentation": true, 38 | "new_with_braces": true, 39 | "nullable_type_declaration_for_default_null_value": true, 40 | "ordered_traits": true, 41 | "php_unit_method_casing": { 42 | "case": "camel_case" 43 | }, 44 | "php_unit_test_annotation": { 45 | "style": "prefix" 46 | }, 47 | "phpdoc_separation": true, 48 | "single_line_empty_body": true 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /screenshots/banner.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirschbaum-development/mail-intercept/51af94ec03ed8ea29ded55b469ca3bfebac323db/screenshots/banner.jpg -------------------------------------------------------------------------------- /src/AssertableMessage.php: -------------------------------------------------------------------------------- 1 | email = $email; 82 | } 83 | 84 | /** 85 | * Dynamically pass missing methods to the Symfony instance. 86 | * 87 | * 88 | * @return mixed 89 | */ 90 | public function __call(string $method, array $parameters) 91 | { 92 | if (Str::startsWith($method, 'assert')) { 93 | $assertion = 'assertMail' . Str::after($method, 'assert'); 94 | $parameters[] = $this->email; 95 | 96 | return $this->$assertion(...$parameters); 97 | } 98 | 99 | return $this->forwardCallTo($this->email, $method, $parameters); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/Assertions/AttachmentAssertions.php: -------------------------------------------------------------------------------- 1 | assertNotEmpty( 24 | $mail->getAttachments(), 25 | 'Mail missing expected attachments.' 26 | ); 27 | } 28 | 29 | /** 30 | * Assert mail missing attachments. 31 | */ 32 | public function assertMailMissingAttachments(AssertableMessage|Email $mail): void 33 | { 34 | $this->assertEmpty( 35 | $mail->getAttachments(), 36 | 'Mail has expected attachments.' 37 | ); 38 | } 39 | 40 | /** 41 | * Assert mail has attachment. 42 | */ 43 | public function assertMailHasAttachment(string $expected, AssertableMessage|Email $mail): void 44 | { 45 | $hasAttachment = collect($mail->getAttachments()) 46 | ->contains(fn (DataPart $attachment) => $expected === $attachment->getFilename()); 47 | 48 | $this->assertTrue( 49 | $hasAttachment, 50 | 'Mail missing expected attachment.' 51 | ); 52 | } 53 | 54 | /** 55 | * Assert mail missing attachment. 56 | */ 57 | public function assertMailMissingAttachment(string $expected, AssertableMessage|Email $mail): void 58 | { 59 | $missingAttachment = ! collect($mail->getAttachments()) 60 | ->contains(fn (DataPart $attachment) => $expected === $attachment->getFilename()); 61 | 62 | $this->assertTrue( 63 | $missingAttachment, 64 | 'Mail has expected attachment.' 65 | ); 66 | } 67 | 68 | /* 69 | |-------------------------------------------------------------------------- 70 | | Embedded Images 71 | |-------------------------------------------------------------------------- 72 | */ 73 | 74 | /** 75 | * Assert mail has attachments. 76 | */ 77 | public function assertMailHasEmbeddedImages(AssertableMessage|Email $mail): void 78 | { 79 | $hasEmbedded = collect($mail->getAttachments()) 80 | ->contains(fn (DataPart $attachment) => $attachment->getDisposition() === 'inline'); 81 | 82 | $this->assertTrue( 83 | $hasEmbedded, 84 | 'Mail missing embedded images.' 85 | ); 86 | } 87 | 88 | /** 89 | * Assert mail missing attachments. 90 | */ 91 | public function assertMailMissingEmbeddedImages(AssertableMessage|Email $mail): void 92 | { 93 | $missingEmbedded = ! collect($mail->getAttachments()) 94 | ->contains(fn (DataPart $attachment) => $attachment->getDisposition() === 'inline'); 95 | 96 | $this->assertTrue( 97 | $missingEmbedded, 98 | 'Mail has embedded images.' 99 | ); 100 | } 101 | 102 | /** 103 | * Assert mail has attachment. 104 | */ 105 | public function assertMailHasEmbeddedImage(string $expected, AssertableMessage|Email $mail): void 106 | { 107 | /** 108 | * @var DataPart|null $embed 109 | */ 110 | $embed = collect($mail->getAttachments()) 111 | ->firstWhere(fn (DataPart $attachment) => $expected === $attachment->getFilename()); 112 | 113 | if ($embed) { 114 | $this->assertTrue( 115 | $embed->getDisposition() === 'inline', 116 | 'Mail has expected attachment but is not embedded.' 117 | ); 118 | 119 | return; 120 | } 121 | 122 | throw new ExpectationFailedException('Mail missing expected embedded image.'); 123 | } 124 | 125 | /** 126 | * Assert mail missing attachment. 127 | */ 128 | public function assertMailMissingEmbeddedImage(string $expected, AssertableMessage|Email $mail): void 129 | { 130 | /** 131 | * @var DataPart|null $embed 132 | */ 133 | $embed = collect($mail->getAttachments()) 134 | ->firstWhere(fn (DataPart $attachment) => $expected === $attachment->getFilename()); 135 | 136 | if (! $embed) { 137 | $this->assertNull($embed); 138 | 139 | return; 140 | } 141 | 142 | $this->assertTrue( 143 | $embed->getDisposition() !== 'inline', 144 | 'Mail has expected embedded image.' 145 | ); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/Assertions/BccAssertions.php: -------------------------------------------------------------------------------- 1 | gatherEmailData('getBcc', $mail); 18 | 19 | foreach ($expectedAddresses as $address) { 20 | $this->assertContains( 21 | $address, 22 | $actualAddresses, 23 | "Mail was not BCC'd to the expected address [{$address}]." 24 | ); 25 | } 26 | } 27 | 28 | /** 29 | * Assert mail was not BCC'd to address. 30 | */ 31 | public function assertMailNotBcc(array|string $expected, AssertableMessage|Email $mail): void 32 | { 33 | $addresses = Arr::wrap($expected); 34 | $actualAddresses = $this->gatherEmailData('getBcc', $mail); 35 | 36 | foreach ($addresses as $address) { 37 | $this->assertNotContains( 38 | $address, 39 | $actualAddresses, 40 | "Mail was BCC'd to the expected address [{$address}]." 41 | ); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Assertions/CcAssertions.php: -------------------------------------------------------------------------------- 1 | gatherEmailData('getCc', $mail); 18 | 19 | foreach ($expectedAddresses as $address) { 20 | $this->assertContains( 21 | $address, 22 | $actualAddresses, 23 | "Mail was not CC'd to the expected address [{$address}]." 24 | ); 25 | } 26 | } 27 | 28 | /** 29 | * Assert mail was not CC'd to address. 30 | */ 31 | public function assertMailNotCc(array|string $expected, AssertableMessage|Email $mail): void 32 | { 33 | $expectedAddresses = Arr::wrap($expected); 34 | $actualAddresses = $this->gatherEmailData('getCc', $mail); 35 | 36 | foreach ($expectedAddresses as $address) { 37 | $this->assertNotContains( 38 | $address, 39 | $actualAddresses, 40 | "Mail was CC'd to the expected address [{$address}]." 41 | ); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Assertions/ContentAssertions.php: -------------------------------------------------------------------------------- 1 | {$method}( 20 | $needle, 21 | $mail->getHtmlBody() ?: $mail->getBody()->bodyToString(), 22 | "The expected [{$needle}] string was not found in the body." 23 | ); 24 | } 25 | 26 | /** 27 | * Assert mail body does not contain string. 28 | */ 29 | public function assertMailBodyNotContainsString(string $needle, AssertableMessage|Email $mail): void 30 | { 31 | $method = method_exists($this, 'assertStringNotContainsString') 32 | ? 'assertStringNotContainsString' 33 | : 'assertNotContains'; 34 | 35 | $this->{$method}( 36 | $needle, 37 | $mail->getHtmlBody() ?: $mail->getBody()->bodyToString(), 38 | "The expected [{$needle}] string was found in the body." 39 | ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Assertions/ContentTypeAssertions.php: -------------------------------------------------------------------------------- 1 | assertEquals( 17 | 'plain', 18 | $mail->getBody()->getMediaSubtype(), 19 | 'The mail is not [text/plain].' 20 | ); 21 | } 22 | 23 | /** 24 | * Assert mail content type is not text/plain. 25 | */ 26 | public function assertMailIsNotPlain(AssertableMessage|Email $mail): void 27 | { 28 | $this->assertNotEquals( 29 | 'plain', 30 | $mail->getBody()->getMediaSubtype(), 31 | 'The mail is [text/plain].' 32 | ); 33 | } 34 | 35 | /** 36 | * Assert multipart email has text/plain content type. 37 | */ 38 | public function assertMailHasPlainContent(AssertableMessage|Email $mail): void 39 | { 40 | if ($mail->getBody() instanceof AbstractMultipartPart) { 41 | $hasPlainContent = collect($mail->getBody()->getParts()) 42 | ->contains(fn ($part) => $part->getMediaSubtype() === 'plain'); 43 | } 44 | 45 | $this->assertTrue( 46 | $hasPlainContent ?? false, 47 | 'The mail does not have [text/plain] content.' 48 | ); 49 | } 50 | 51 | /** 52 | * Assert multipart email does not have text/plain content type. 53 | */ 54 | public function assertMailDoesNotHavePlainContent(AssertableMessage|Email $mail): void 55 | { 56 | if ($mail->getBody() instanceof AbstractMultipartPart) { 57 | $hasPlainContent = collect($mail->getBody()->getParts()) 58 | ->contains(fn ($part) => $part->getMediaSubtype() === 'plain'); 59 | } 60 | 61 | $this->assertFalse( 62 | $hasPlainContent ?? true, 63 | 'The mail does have [text/plain] content.' 64 | ); 65 | } 66 | 67 | /** 68 | * Assert mail content type is text/html. 69 | */ 70 | public function assertMailIsHtml(AssertableMessage|Email $mail): void 71 | { 72 | $this->assertEquals( 73 | 'html', 74 | $mail->getBody()->getMediaSubtype(), 75 | 'The mail is not [text/html].' 76 | ); 77 | } 78 | 79 | /** 80 | * Assert mail content type is not text/html. 81 | */ 82 | public function assertMailIsNotHtml(AssertableMessage|Email $mail): void 83 | { 84 | $this->assertNotEquals( 85 | 'html', 86 | $mail->getBody()->getMediaSubtype(), 87 | 'The mail is [text/html].' 88 | ); 89 | } 90 | 91 | /** 92 | * Assert multipart email has text/html content type. 93 | */ 94 | public function assertMailHasHtmlContent(AssertableMessage|Email $mail): void 95 | { 96 | if ($mail->getBody() instanceof AbstractMultipartPart) { 97 | $hasHtmlContent = collect($mail->getBody()->getParts()) 98 | ->contains(fn ($part) => $part->getMediaSubtype() === 'html'); 99 | } 100 | 101 | $this->assertTrue( 102 | $hasHtmlContent ?? false, 103 | 'The mail does not have [text/html] content.' 104 | ); 105 | } 106 | 107 | /** 108 | * Assert multipart email does not have text/html content type. 109 | */ 110 | public function assertMailDoesNotHaveHtmlContent(AssertableMessage|Email $mail): void 111 | { 112 | if ($mail->getBody() instanceof AbstractMultipartPart) { 113 | $hasHtmlContent = collect($mail->getBody()->getParts()) 114 | ->contains(fn ($part) => $part->getMediaSubtype() === 'html'); 115 | } 116 | 117 | $this->assertFalse( 118 | $hasHtmlContent ?? true, 119 | 'The mail does have [text/html] content.' 120 | ); 121 | } 122 | 123 | /** 124 | * Assert mail content type is multipart/alternative. 125 | */ 126 | public function assertMailIsAlternative(AssertableMessage|Email $mail): void 127 | { 128 | $this->assertEquals( 129 | 'alternative', 130 | $mail->getBody()->getMediaSubtype(), 131 | 'The mail is not [multipart/alternative].' 132 | ); 133 | } 134 | 135 | /** 136 | * Assert mail content type is not multipart/alternative. 137 | */ 138 | public function assertMailIsNotAlternative(AssertableMessage|Email $mail): void 139 | { 140 | $this->assertNotEquals( 141 | 'alternative', 142 | $mail->getBody()->getMediaSubtype(), 143 | 'The mail is [multipart/alternative].' 144 | ); 145 | } 146 | 147 | /** 148 | * Assert mail content type is multipart/mixed. 149 | */ 150 | public function assertMailIsMixed(AssertableMessage|Email $mail): void 151 | { 152 | $this->assertEquals( 153 | 'mixed', 154 | $mail->getBody()->getMediaSubtype(), 155 | 'The mail is not [multipart/mixed].' 156 | ); 157 | } 158 | 159 | /** 160 | * Assert mail content type is not multipart/mixed. 161 | */ 162 | public function assertMailIsNotMixed(AssertableMessage|Email $mail): void 163 | { 164 | $this->assertNotEquals( 165 | 'mixed', 166 | $mail->getBody()->getMediaSubtype(), 167 | 'The mail is [multipart/mixed].' 168 | ); 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/Assertions/FromAssertions.php: -------------------------------------------------------------------------------- 1 | gatherEmailData('getFrom', $mail); 18 | 19 | foreach ($expectedAddresses as $address) { 20 | $this->assertContains( 21 | $address, 22 | $actualAddresses, 23 | "Mail was not sent from the expected address [{$address}]." 24 | ); 25 | } 26 | } 27 | 28 | /** 29 | * Assert mail was not sent from address. 30 | */ 31 | public function assertMailNotSentFrom(array|string $expected, AssertableMessage|Email $mail): void 32 | { 33 | $expectedAddresses = Arr::wrap($expected); 34 | $actualAddresses = $this->gatherEmailData('getFrom', $mail); 35 | 36 | foreach ($expectedAddresses as $address) { 37 | $this->assertNotContains( 38 | $address, 39 | $actualAddresses, 40 | "Mail was sent from the expected address [{$address}]." 41 | ); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Assertions/PriorityAssertions.php: -------------------------------------------------------------------------------- 1 | assertEquals( 16 | $expected, 17 | $mail->getPriority(), 18 | "The expected priority was not [{$expected}]." 19 | ); 20 | } 21 | 22 | /** 23 | * Assert mail does not have priority. 24 | */ 25 | public function assertMailNotPriority(int $expected, AssertableMessage|Email $mail): void 26 | { 27 | $this->assertNotEquals( 28 | $expected, 29 | $mail->getPriority(), 30 | "The expected priority was [{$expected}]." 31 | ); 32 | } 33 | 34 | /** 35 | * Assert mail has the highest priority. 36 | */ 37 | public function assertMailPriorityIsHighest(AssertableMessage|Email $mail): void 38 | { 39 | $this->assertEquals( 40 | Email::PRIORITY_HIGHEST, 41 | $mail->getPriority(), 42 | 'The expected priority was not [highest].' 43 | ); 44 | } 45 | 46 | /** 47 | * Assert mail does not have the highest priority. 48 | */ 49 | public function assertMailPriorityNotHighest(AssertableMessage|Email $mail): void 50 | { 51 | $this->assertNotEquals( 52 | Email::PRIORITY_HIGHEST, 53 | $mail->getPriority(), 54 | 'The expected priority was [highest].' 55 | ); 56 | } 57 | 58 | /** 59 | * Assert mail has high priority. 60 | */ 61 | public function assertMailPriorityIsHigh(AssertableMessage|Email $mail): void 62 | { 63 | $this->assertEquals( 64 | Email::PRIORITY_HIGH, 65 | $mail->getPriority(), 66 | 'The expected priority was not [high].' 67 | ); 68 | } 69 | 70 | /** 71 | * Assert mail does not have high priority. 72 | */ 73 | public function assertMailPriorityNotHigh(AssertableMessage|Email $mail): void 74 | { 75 | $this->assertNotEquals( 76 | Email::PRIORITY_HIGH, 77 | $mail->getPriority(), 78 | 'The expected priority was [high].' 79 | ); 80 | } 81 | 82 | /** 83 | * Assert mail has normal priority. 84 | */ 85 | public function assertMailPriorityIsNormal(AssertableMessage|Email $mail): void 86 | { 87 | $this->assertEquals( 88 | Email::PRIORITY_NORMAL, 89 | $mail->getPriority(), 90 | 'The expected priority was not [normal].' 91 | ); 92 | } 93 | 94 | /** 95 | * Assert mail does not have normal priority. 96 | */ 97 | public function assertMailPriorityNotNormal(AssertableMessage|Email $mail): void 98 | { 99 | $this->assertNotEquals( 100 | Email::PRIORITY_NORMAL, 101 | $mail->getPriority(), 102 | 'The expected priority was [normal].' 103 | ); 104 | } 105 | 106 | /** 107 | * Assert mail has low priority. 108 | */ 109 | public function assertMailPriorityIsLow(AssertableMessage|Email $mail): void 110 | { 111 | $this->assertEquals( 112 | Email::PRIORITY_LOW, 113 | $mail->getPriority(), 114 | 'The expected priority was not [low].' 115 | ); 116 | } 117 | 118 | /** 119 | * Assert mail does not have low priority. 120 | */ 121 | public function assertMailPriorityNotLow(AssertableMessage|Email $mail): void 122 | { 123 | $this->assertNotEquals( 124 | Email::PRIORITY_LOW, 125 | $mail->getPriority(), 126 | 'The expected priority was [low].' 127 | ); 128 | } 129 | 130 | /** 131 | * Assert mail has the lowest priority. 132 | */ 133 | public function assertMailPriorityIsLowest(AssertableMessage|Email $mail): void 134 | { 135 | $this->assertEquals( 136 | Email::PRIORITY_LOWEST, 137 | $mail->getPriority(), 138 | 'The expected priority was not [lowest].' 139 | ); 140 | } 141 | 142 | /** 143 | * Assert mail does not have the lowest priority. 144 | */ 145 | public function assertMailPriorityNotLowest(AssertableMessage|Email $mail): void 146 | { 147 | $this->assertNotEquals( 148 | Email::PRIORITY_LOWEST, 149 | $mail->getPriority(), 150 | 'The expected priority was [lowest].' 151 | ); 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/Assertions/ReplyToAssertions.php: -------------------------------------------------------------------------------- 1 | gatherEmailData('getReplyTo', $mail); 18 | 19 | foreach ($expectedAddresses as $address) { 20 | $this->assertContains( 21 | $address, 22 | $actualAddresses, 23 | "Mail does not reply to the expected address [{$address}]." 24 | ); 25 | } 26 | } 27 | 28 | /** 29 | * Assert mail does not reply to address. 30 | */ 31 | public function assertMailNotRepliesTo(array|string $expected, AssertableMessage|Email $mail): void 32 | { 33 | $expectedAddresses = Arr::wrap($expected); 34 | $actualAddresses = $this->gatherEmailData('getReplyTo', $mail); 35 | 36 | foreach ($expectedAddresses as $address) { 37 | $this->assertNotContains( 38 | $address, 39 | $actualAddresses, 40 | "Mail replied to the expected address [{$address}]." 41 | ); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Assertions/ReturnPathAssertions.php: -------------------------------------------------------------------------------- 1 | assertEquals( 16 | $expected, 17 | $mail->getReturnPath()->getAddress(), 18 | "The expected return path was not [{$expected}]." 19 | ); 20 | } 21 | 22 | /** 23 | * Assert mail does not have return path. 24 | */ 25 | public function assertMailNotReturnPath(string $expected, AssertableMessage|Email $mail): void 26 | { 27 | $this->assertNotEquals( 28 | $expected, 29 | $mail->getReturnPath()->getAddress(), 30 | "The expected return path was [{$expected}]." 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Assertions/SenderAssertions.php: -------------------------------------------------------------------------------- 1 | assertEquals( 16 | $expected, 17 | $mail->getSender()->getAddress(), 18 | "Mail sender was not from the expected address [{$expected}]." 19 | ); 20 | } 21 | 22 | /** 23 | * Assert mail was not sender address. 24 | */ 25 | public function assertMailNotSender(string $expected, AssertableMessage|Email $mail): void 26 | { 27 | $this->assertNotEquals( 28 | $expected, 29 | $mail->getSender()->getAddress(), 30 | "Mail sender was from the expected address [{$expected}]." 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Assertions/SubjectAssertions.php: -------------------------------------------------------------------------------- 1 | assertEquals( 16 | $expected, 17 | $mail->getSubject(), 18 | "The expected subject was not [{$expected}]." 19 | ); 20 | } 21 | 22 | /** 23 | * Assert mail does not have subject. 24 | */ 25 | public function assertMailNotSubject(string $expected, AssertableMessage|Email $mail): void 26 | { 27 | $this->assertNotEquals( 28 | $expected, 29 | $mail->getSubject(), 30 | "The expected subject was [{$expected}]." 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Assertions/ToAssertions.php: -------------------------------------------------------------------------------- 1 | gatherEmailData('getTo', $mail); 18 | 19 | foreach ($expectedAddresses as $address) { 20 | $this->assertContains( 21 | $address, 22 | $actualAddresses, 23 | "Mail was not sent to the expected address [{$address}]." 24 | ); 25 | } 26 | } 27 | 28 | /** 29 | * Assert mail was not sent to address. 30 | */ 31 | public function assertMailNotSentTo(array|string $expected, AssertableMessage|Email $mail): void 32 | { 33 | $expectedAddresses = Arr::wrap($expected); 34 | $actualAddresses = $this->gatherEmailData('getTo', $mail); 35 | 36 | foreach ($expectedAddresses as $address) { 37 | $this->assertNotContains( 38 | $address, 39 | $actualAddresses, 40 | "Mail was sent to the expected address [{$address}]." 41 | ); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Assertions/UnstructuredHeaderAssertions.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf( 17 | UnstructuredHeader::class, 18 | $mail->getHeaders()->get($expected), 19 | "The expected [{$expected}] header did not exist." 20 | ); 21 | } 22 | 23 | /** 24 | * Assert unstructured header exists. 25 | */ 26 | public function assertMailMissingHeader(string $expected, AssertableMessage|Email $mail): void 27 | { 28 | $this->assertNull( 29 | $mail->getHeaders()->get($expected), 30 | "The expected [{$expected}] header did exist." 31 | ); 32 | } 33 | 34 | /** 35 | * Assert unstructured header is expected value. 36 | */ 37 | public function assertMailHeaderIs(string $expected, string $expectedValue, AssertableMessage|Email $mail): void 38 | { 39 | $this->assertEquals( 40 | $expectedValue, 41 | $mail->getHeaders()->get($expected)->getValue(), 42 | "The expected [{$expected}] was not set to [{$expectedValue}]." 43 | ); 44 | } 45 | 46 | /** 47 | * Assert unstructured header is not expected value. 48 | */ 49 | public function assertMailHeaderIsNot(string $expected, string $expectedValue, AssertableMessage|Email $mail): void 50 | { 51 | $this->assertNotEquals( 52 | $expectedValue, 53 | $mail->getHeaders()->get($expected)->getValue(), 54 | "The expected [{$expected}] was set to [{$expectedValue}]." 55 | ); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/WithMailInterceptor.php: -------------------------------------------------------------------------------- 1 | getSymfonyTransport() 53 | ->messages() 54 | ->map(function (SentMessage $message) { 55 | return new AssertableMessage($message->getOriginalMessage()); 56 | }); 57 | } 58 | 59 | /** 60 | * Gather email addresses from specific field method. 61 | */ 62 | protected function gatherEmailData(string $method, AssertableMessage|Email $mail): array 63 | { 64 | return collect($mail->$method()) 65 | ->map(fn ($address) => $address->getAddress()) 66 | ->toArray(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/Architecture/AssertableMessageTest.php: -------------------------------------------------------------------------------- 1 | expect(AssertableMessage::class) 9 | ->toExtend(Assert::class); 10 | 11 | // Pest Presets are available beginning in version 3. 12 | exec('composer show pestphp/pest', $output); 13 | 14 | if ($output[3] === 'versions : * v3') { 15 | arch('AssertableMessage uses traits')->expect(AssertableMessage::class) 16 | ->toUseTraits([ 17 | ForwardsCalls::class, 18 | WithMailInterceptor::class, 19 | ]); 20 | } 21 | -------------------------------------------------------------------------------- /tests/Architecture/AssertionsTest.php: -------------------------------------------------------------------------------- 1 | expect('KirschbaumDevelopment\MailIntercept\Assertions') 4 | ->toBeTraits(); 5 | 6 | arch('assertions have correct suffix')->expect('KirschbaumDevelopment\MailIntercept\Assertions') 7 | ->traits() 8 | ->toHaveSuffix('Assertions'); 9 | 10 | // Pest Presets are available beginning in version 3. 11 | exec('composer show pestphp/pest', $output); 12 | 13 | if ($output[3] === 'versions : * v3') { 14 | arch('assertions do not have private methods')->expect('KirschbaumDevelopment\MailIntercept\Assertions') 15 | ->not->toHavePrivateMethods(); 16 | 17 | arch('assertions do not have protected methods')->expect('KirschbaumDevelopment\MailIntercept\Assertions') 18 | ->not->toHaveProtectedMethods(); 19 | } 20 | -------------------------------------------------------------------------------- /tests/Architecture/PresetTest.php: -------------------------------------------------------------------------------- 1 | preset()->laravel(); 8 | 9 | arch('php preset')->preset()->php(); 10 | 11 | arch('security preset')->preset()->security(); 12 | } 13 | -------------------------------------------------------------------------------- /tests/Architecture/TraitTest.php: -------------------------------------------------------------------------------- 1 | expect('KirschbaumDevelopment\MailIntercept\WithMailInterceptor') 17 | ->toBeTrait(); 18 | 19 | // Pest Presets are available beginning in version 3. 20 | exec('composer show pestphp/pest', $output); 21 | 22 | if ($output[3] === 'versions : * v3') { 23 | arch('WithMailInterceptor uses traits')->expect('KirschbaumDevelopment\MailIntercept\WithMailInterceptor') 24 | ->toUseTraits([ 25 | BccAssertions::class, 26 | CcAssertions::class, 27 | ContentAssertions::class, 28 | ContentTypeAssertions::class, 29 | FromAssertions::class, 30 | PriorityAssertions::class, 31 | ReplyToAssertions::class, 32 | ReturnPathAssertions::class, 33 | SenderAssertions::class, 34 | SubjectAssertions::class, 35 | ToAssertions::class, 36 | UnstructuredHeaderAssertions::class, 37 | ]); 38 | } 39 | -------------------------------------------------------------------------------- /tests/AttachmentAssertionsTest.php: -------------------------------------------------------------------------------- 1 | addPart(new DataPart(new File(__DIR__ . '/../Fixtures/f-18.jpg'))); 21 | 22 | $this->assertMailHasAttachments($mail); 23 | } 24 | 25 | public function testMailHasAttachmentsThrowsProperExpectationFailedException() 26 | { 27 | $mail = (new Email()); 28 | 29 | $this->expectException(ExpectationFailedException::class); 30 | $this->expectExceptionMessage('Mail missing expected attachments.'); 31 | 32 | $this->assertMailHasAttachments($mail); 33 | } 34 | 35 | /* 36 | |-------------------------------------------------------------------------- 37 | | assertMailMissingAttachments 38 | |-------------------------------------------------------------------------- 39 | */ 40 | 41 | public function testMailMissingAttachments() 42 | { 43 | $mail = (new Email()); 44 | 45 | $this->assertMailMissingAttachments($mail); 46 | } 47 | 48 | public function testMailMissingAttachmentsThrowsProperExpectationFailedException() 49 | { 50 | $mail = (new Email())->addPart(new DataPart(new File(__DIR__ . '/../Fixtures/f-18.jpg'))); 51 | 52 | $this->expectException(ExpectationFailedException::class); 53 | $this->expectExceptionMessage('Mail has expected attachments.'); 54 | 55 | $this->assertMailMissingAttachments($mail); 56 | } 57 | 58 | /* 59 | |-------------------------------------------------------------------------- 60 | | testMailHasAttachment 61 | |-------------------------------------------------------------------------- 62 | */ 63 | 64 | public function testMailHasAttachment() 65 | { 66 | $mail = (new Email())->addPart(new DataPart(new File(__DIR__ . '/../Fixtures/f-18.jpg'))); 67 | 68 | $this->assertMailHasAttachment('f-18.jpg', $mail); 69 | } 70 | 71 | public function testMailHasAttachmentThrowsProperExpectationFailedException() 72 | { 73 | $mail = (new Email()); 74 | 75 | $this->expectException(ExpectationFailedException::class); 76 | $this->expectExceptionMessage('Mail missing expected attachment.'); 77 | 78 | $this->assertMailHasAttachment('f-18.jpg', $mail); 79 | } 80 | 81 | /* 82 | |-------------------------------------------------------------------------- 83 | | testMailMissingAttachment 84 | |-------------------------------------------------------------------------- 85 | */ 86 | 87 | public function testMailMissingAttachment() 88 | { 89 | $mail = (new Email()); 90 | 91 | $this->assertMailMissingAttachment('f-18.jpg', $mail); 92 | } 93 | 94 | public function testMailMissingAttachmentThrowsProperExpectationFailedException() 95 | { 96 | $mail = (new Email())->addPart(new DataPart(new File(__DIR__ . '/../Fixtures/f-18.jpg'))); 97 | 98 | $this->expectException(ExpectationFailedException::class); 99 | $this->expectExceptionMessage('Mail has expected attachment.'); 100 | 101 | $this->assertMailMissingAttachment('f-18.jpg', $mail); 102 | } 103 | 104 | /* 105 | |-------------------------------------------------------------------------- 106 | | assertMailHasEmbeddedImages 107 | |-------------------------------------------------------------------------- 108 | */ 109 | 110 | public function testMailHasEmbeddedImages() 111 | { 112 | $mail = (new Email())->addPart((new DataPart(new File(__DIR__ . '/../Fixtures/f-18.jpg')))->asInline()); 113 | 114 | $this->assertMailHasEmbeddedImages($mail); 115 | } 116 | 117 | public function testMailHasEmbeddedImagesThrowsProperExpectationFailedException() 118 | { 119 | $mail = (new Email()); 120 | 121 | $this->expectException(ExpectationFailedException::class); 122 | $this->expectExceptionMessage('Mail missing embedded images.'); 123 | 124 | $this->assertMailHasEmbeddedImages($mail); 125 | } 126 | 127 | /* 128 | |-------------------------------------------------------------------------- 129 | | assertMailMissingEmbeddedImages 130 | |-------------------------------------------------------------------------- 131 | */ 132 | 133 | public function testMailMissingEmbeddedImages() 134 | { 135 | $mail = (new Email()); 136 | 137 | $this->assertMailMissingEmbeddedImages($mail); 138 | } 139 | 140 | public function testMailMissingEmbeddedImagesThrowsProperExpectationFailedException() 141 | { 142 | $mail = (new Email())->addPart((new DataPart(new File(__DIR__ . '/../Fixtures/f-18.jpg')))->asInline()); 143 | 144 | $this->expectException(ExpectationFailedException::class); 145 | $this->expectExceptionMessage('Mail has embedded images.'); 146 | 147 | $this->assertMailMissingEmbeddedImages($mail); 148 | } 149 | 150 | /* 151 | |-------------------------------------------------------------------------- 152 | | testMailHasEmbeddedImage 153 | |-------------------------------------------------------------------------- 154 | */ 155 | 156 | public function testMailHasEmbeddedImage() 157 | { 158 | $mail = (new Email())->addPart((new DataPart(new File(__DIR__ . '/../Fixtures/f-18.jpg')))->asInline()); 159 | 160 | $this->assertMailHasEmbeddedImage('f-18.jpg', $mail); 161 | } 162 | 163 | public function testMailHasEmbeddedImageThrowsProperExpectationFailedException() 164 | { 165 | $mail = (new Email()); 166 | 167 | $this->expectException(ExpectationFailedException::class); 168 | $this->expectExceptionMessage('Mail missing expected embedded image.'); 169 | 170 | $this->assertMailHasEmbeddedImage('f-18.jpg', $mail); 171 | } 172 | 173 | public function testMailHasEmbeddedImageButCheckingForWrongImageThrowsProperExpectationFailedException() 174 | { 175 | $mail = (new Email()); 176 | 177 | $this->expectException(ExpectationFailedException::class); 178 | $this->expectExceptionMessage('Mail missing expected embedded image.'); 179 | 180 | $this->assertMailHasEmbeddedImage('f-22.jpg', $mail); 181 | } 182 | 183 | /* 184 | |-------------------------------------------------------------------------- 185 | | testMailMissingEmbeddedImage 186 | |-------------------------------------------------------------------------- 187 | */ 188 | 189 | public function testMailMissingEmbeddedImage() 190 | { 191 | $mail = (new Email()); 192 | 193 | $this->assertMailMissingEmbeddedImage('f-18.jpg', $mail); 194 | } 195 | 196 | public function testMailMissingEmbeddedImageThrowsProperExpectationFailedException() 197 | { 198 | $mail = (new Email())->addPart((new DataPart(new File(__DIR__ . '/../Fixtures/f-18.jpg')))->asInline()); 199 | 200 | $this->expectException(ExpectationFailedException::class); 201 | $this->expectExceptionMessage('Mail has expected embedded image.'); 202 | 203 | $this->assertMailMissingEmbeddedImage('f-18.jpg', $mail); 204 | } 205 | 206 | public function testMailHasEmbeddedImageButCheckingForDifferentImage() 207 | { 208 | $mail = (new Email())->addPart((new DataPart(new File(__DIR__ . '/../Fixtures/f-18.jpg')))->asInline()); 209 | 210 | $this->assertMailMissingEmbeddedImage('f-22.jpg', $mail); 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /tests/BccAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->email; 20 | 21 | $mail = (new Email())->bcc($email); 22 | 23 | $this->assertMailBcc($email, $mail); 24 | } 25 | 26 | public function testMailBccSingleEmailViaAssertableMessage() 27 | { 28 | $email = $this->faker->email; 29 | 30 | $mail = new AssertableMessage( 31 | (new Email())->bcc($email) 32 | ); 33 | 34 | $this->assertMailBcc($email, $mail); 35 | } 36 | 37 | public function testMailBccThrowsProperExpectationFailedException() 38 | { 39 | $email = $this->faker->unique()->email; 40 | 41 | $mail = (new Email())->bcc($this->faker->unique()->email); 42 | 43 | $this->expectException(ExpectationFailedException::class); 44 | $this->expectExceptionMessage("Mail was not BCC'd to the expected address [{$email}]."); 45 | 46 | $this->assertMailBcc($email, $mail); 47 | } 48 | 49 | public function testMailSentToMultipleEmails() 50 | { 51 | $emails = [ 52 | $this->faker->email, 53 | $this->faker->email, 54 | ]; 55 | 56 | $mail = (new Email())->bcc(...$emails); 57 | 58 | $this->assertMailBcc($emails, $mail); 59 | } 60 | 61 | /* 62 | |-------------------------------------------------------------------------- 63 | | assertMailNotBcc 64 | |-------------------------------------------------------------------------- 65 | */ 66 | 67 | public function testMailNotSentToSingleEmail() 68 | { 69 | $email = $this->faker->unique()->email; 70 | 71 | $mail = (new Email())->bcc($this->faker->unique()->email); 72 | 73 | $this->assertMailNotBcc($email, $mail); 74 | } 75 | 76 | public function testMailNotSentToSingleEmailViaAssertableMessage() 77 | { 78 | $email = $this->faker->unique()->email; 79 | 80 | $mail = new AssertableMessage( 81 | (new Email())->bcc($this->faker->unique()->email) 82 | ); 83 | 84 | $this->assertMailNotBcc($email, $mail); 85 | } 86 | 87 | public function testMailNotSentToThrowsProperExpectationFailedException() 88 | { 89 | $email = $this->faker->unique()->email; 90 | 91 | $mail = (new Email())->bcc($email); 92 | 93 | $this->expectException(ExpectationFailedException::class); 94 | $this->expectExceptionMessage("Mail was BCC'd to the expected address [{$email}]."); 95 | 96 | $this->assertMailNotBcc($email, $mail); 97 | } 98 | 99 | public function testMailNotSentToMultipleEmails() 100 | { 101 | $emails = [ 102 | $this->faker->unique()->email, 103 | $this->faker->unique()->email, 104 | ]; 105 | 106 | $mail = (new Email())->bcc( 107 | $this->faker->unique()->email, 108 | $this->faker->unique()->email 109 | ); 110 | 111 | $this->assertMailNotBcc($emails, $mail); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /tests/CcAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->email; 20 | 21 | $mail = (new Email())->cc($email); 22 | 23 | $this->assertMailCc($email, $mail); 24 | } 25 | 26 | public function testMailCcSingleEmailViaAssertableMessage() 27 | { 28 | $email = $this->faker->email; 29 | 30 | $mail = new AssertableMessage( 31 | (new Email())->cc($email) 32 | ); 33 | 34 | $this->assertMailCc($email, $mail); 35 | } 36 | 37 | public function testMailCcThrowsProperExpectationFailedException() 38 | { 39 | $email = $this->faker->unique()->email; 40 | 41 | $mail = (new Email())->cc($this->faker->unique()->email); 42 | 43 | $this->expectException(ExpectationFailedException::class); 44 | $this->expectExceptionMessage("Mail was not CC'd to the expected address [{$email}]."); 45 | 46 | $this->assertMailCc($email, $mail); 47 | } 48 | 49 | public function testMailSentToMultipleEmails() 50 | { 51 | $emails = [ 52 | $this->faker->email, 53 | $this->faker->email, 54 | ]; 55 | 56 | $mail = (new Email())->cc(...$emails); 57 | 58 | $this->assertMailCc($emails, $mail); 59 | } 60 | 61 | /* 62 | |-------------------------------------------------------------------------- 63 | | assertMailNotCc 64 | |-------------------------------------------------------------------------- 65 | */ 66 | 67 | public function testMailNotSentToSingleEmail() 68 | { 69 | $email = $this->faker->unique()->email; 70 | 71 | $mail = (new Email())->cc($this->faker->unique()->email); 72 | 73 | $this->assertMailNotCc($email, $mail); 74 | } 75 | 76 | public function testMailNotSentToSingleEmailViaAssertableMessage() 77 | { 78 | $email = $this->faker->unique()->email; 79 | 80 | $mail = new AssertableMessage( 81 | (new Email())->cc($this->faker->unique()->email) 82 | ); 83 | 84 | $this->assertMailNotCc($email, $mail); 85 | } 86 | 87 | public function testMailNotSentToThrowsProperExpectationFailedException() 88 | { 89 | $email = $this->faker->unique()->email; 90 | 91 | $mail = (new Email())->cc($email); 92 | 93 | $this->expectException(ExpectationFailedException::class); 94 | $this->expectExceptionMessage("Mail was CC'd to the expected address [{$email}]."); 95 | 96 | $this->assertMailNotCc($email, $mail); 97 | } 98 | 99 | public function testMailNotSentToMultipleEmails() 100 | { 101 | $emails = [ 102 | $this->faker->unique()->email, 103 | $this->faker->unique()->email, 104 | ]; 105 | 106 | $mail = (new Email())->cc( 107 | $this->faker->unique()->email, 108 | $this->faker->unique()->email 109 | ); 110 | 111 | $this->assertMailNotCc($emails, $mail); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /tests/ContentAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->sentence; 21 | 22 | $mail = (new Email()) 23 | ->to($this->faker->email) 24 | ->from($this->faker->email) 25 | ->text($content); 26 | 27 | $this->assertMailBodyContainsString($content, $mail); 28 | } 29 | 30 | public function testMailBodyContentsAsTextViaAssertableMessage() 31 | { 32 | $content = $this->faker->sentence; 33 | 34 | $mail = new AssertableMessage( 35 | (new Email()) 36 | ->to($this->faker->email) 37 | ->from($this->faker->email) 38 | ->text($content) 39 | ); 40 | 41 | $this->assertMailBodyContainsString($content, $mail); 42 | } 43 | 44 | public function testMailBodyContentsAsTextThrowsProperExpectationFailedException() 45 | { 46 | $content = $this->faker->unique()->sentence; 47 | 48 | $mail = (new Email()) 49 | ->to($this->faker->email) 50 | ->from($this->faker->email) 51 | ->text($this->faker->unique()->sentence); 52 | 53 | $this->expectException(ExpectationFailedException::class); 54 | $this->expectExceptionMessage("The expected [{$content}] string was not found in the body."); 55 | 56 | $this->assertMailBodyContainsString($content, $mail); 57 | } 58 | 59 | public function testMailBodyContentsAsHtml() 60 | { 61 | $content = $this->faker->sentence; 62 | 63 | $mail = (new Email()) 64 | ->to($this->faker->email) 65 | ->from($this->faker->email) 66 | ->html($content); 67 | 68 | $this->assertMailBodyContainsString($content, $mail); 69 | } 70 | 71 | public function testMailBodyContentsAsHtmlThrowsProperExpectationFailedException() 72 | { 73 | $content = $this->faker->unique()->sentence; 74 | 75 | $mail = (new Email()) 76 | ->to($this->faker->email) 77 | ->from($this->faker->email) 78 | ->html($this->faker->unique()->sentence); 79 | 80 | $this->expectException(ExpectationFailedException::class); 81 | $this->expectExceptionMessage("The expected [{$content}] string was not found in the body."); 82 | 83 | $this->assertMailBodyContainsString($content, $mail); 84 | } 85 | 86 | public function testMailBodyContentsAsAbstractPart() 87 | { 88 | $content = $this->faker->sentence; 89 | $textPart = new TextPart($content); 90 | 91 | $mail = (new Email())->setBody($textPart); 92 | 93 | $this->assertMailBodyContainsString($content, $mail); 94 | } 95 | 96 | public function testMailBodyContentsAsAbstractPartThrowsProperExpectationFailedException() 97 | { 98 | $content = $this->faker->unique()->sentence; 99 | $textPart = new TextPart($this->faker->unique()->sentence); 100 | 101 | $mail = (new Email())->setBody($textPart); 102 | 103 | $this->expectException(ExpectationFailedException::class); 104 | $this->expectExceptionMessage("The expected [{$content}] string was not found in the body."); 105 | 106 | $this->assertMailBodyContainsString($content, $mail); 107 | } 108 | 109 | /* 110 | |-------------------------------------------------------------------------- 111 | | assertMailBodyNotContainsString 112 | |-------------------------------------------------------------------------- 113 | */ 114 | 115 | public function testMailBodyAsTextDoesNotHaveContents() 116 | { 117 | $content = $this->faker->unique()->sentence; 118 | 119 | $mail = (new Email()) 120 | ->to($this->faker->email) 121 | ->from($this->faker->email) 122 | ->text($this->faker->unique()->sentence); 123 | 124 | $this->assertMailBodyNotContainsString($content, $mail); 125 | } 126 | 127 | public function testMailBodyAsTextDoesNotHaveContentsViaAssertableMessage() 128 | { 129 | $content = $this->faker->unique()->sentence; 130 | 131 | $mail = new AssertableMessage( 132 | (new Email()) 133 | ->to($this->faker->email) 134 | ->from($this->faker->email) 135 | ->text($this->faker->unique()->sentence) 136 | ); 137 | 138 | $this->assertMailBodyNotContainsString($content, $mail); 139 | } 140 | 141 | public function testMailBodyAsTextDoesNotHaveContentsThrowsProperExpectationFailedException() 142 | { 143 | $content = $this->faker->sentence; 144 | 145 | $mail = (new Email()) 146 | ->to($this->faker->email) 147 | ->from($this->faker->email) 148 | ->text($content); 149 | 150 | $this->expectException(ExpectationFailedException::class); 151 | $this->expectExceptionMessage("The expected [{$content}] string was found in the body."); 152 | 153 | $this->assertMailBodyNotContainsString($content, $mail); 154 | } 155 | 156 | public function testMailBodyAsHtmlDoesNotHaveContents() 157 | { 158 | $content = $this->faker->unique()->sentence; 159 | 160 | $mail = (new Email()) 161 | ->to($this->faker->email) 162 | ->from($this->faker->email) 163 | ->html($this->faker->unique()->sentence); 164 | 165 | $this->assertMailBodyNotContainsString($content, $mail); 166 | } 167 | 168 | public function testMailBodyAsHtmlDoesNotHaveContentsThrowsProperExpectationFailedException() 169 | { 170 | $content = $this->faker->sentence; 171 | 172 | $mail = (new Email()) 173 | ->to($this->faker->email) 174 | ->from($this->faker->email) 175 | ->html($content); 176 | 177 | $this->expectException(ExpectationFailedException::class); 178 | $this->expectExceptionMessage("The expected [{$content}] string was found in the body."); 179 | 180 | $this->assertMailBodyNotContainsString($content, $mail); 181 | } 182 | 183 | public function testMailBodyAsAbstractPartDoesNotHaveContents() 184 | { 185 | $content = $this->faker->unique()->sentence; 186 | $textPart = new TextPart($this->faker->unique()->sentence); 187 | 188 | $mail = (new Email())->setBody($textPart); 189 | 190 | $this->assertMailBodyNotContainsString($content, $mail); 191 | } 192 | 193 | public function testMailBodyAsAbstractPartDoesNotHaveContentsThrowsProperExpectationFailedException() 194 | { 195 | $content = $this->faker->sentence; 196 | $textPart = new TextPart($content); 197 | 198 | $mail = (new Email())->setBody($textPart); 199 | 200 | $this->expectException(ExpectationFailedException::class); 201 | $this->expectExceptionMessage("The expected [{$content}] string was found in the body."); 202 | 203 | $this->assertMailBodyNotContainsString($content, $mail); 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /tests/ContentTypeAssertionsTest.php: -------------------------------------------------------------------------------- 1 | to($this->faker->email) 22 | ->from($this->faker->email) 23 | ->text($this->faker->sentence); 24 | 25 | $this->assertMailIsPlain($mail); 26 | } 27 | 28 | public function testMailContentTypePlainViaAssertableMessage() 29 | { 30 | $mail = new AssertableMessage( 31 | (new Email()) 32 | ->to($this->faker->email) 33 | ->from($this->faker->email) 34 | ->text($this->faker->sentence) 35 | ); 36 | 37 | $this->assertMailIsPlain($mail); 38 | } 39 | 40 | public function testMailContentTypePlainThrowsException() 41 | { 42 | $part = new TextPart('body', subtype: 'bad'); 43 | $mail = (new Email())->setBody($part); 44 | 45 | $this->expectException(ExpectationFailedException::class); 46 | $this->expectExceptionMessage('The mail is not [text/plain].'); 47 | 48 | $this->assertMailIsPlain($mail); 49 | } 50 | 51 | /* 52 | |-------------------------------------------------------------------------- 53 | | assertMailIsNotPlain 54 | |-------------------------------------------------------------------------- 55 | */ 56 | 57 | public function testMailContentTypeNotPlain() 58 | { 59 | $part = new TextPart('body', subtype: 'not-plain'); 60 | $mail = (new Email())->setBody($part); 61 | 62 | $this->assertMailIsNotPlain($mail); 63 | } 64 | 65 | public function testMailContentTypeNotPlainViaAssertableMessage() 66 | { 67 | $part = new TextPart('body', subtype: 'not-plain'); 68 | $mail = new AssertableMessage( 69 | (new Email())->setBody($part) 70 | ); 71 | 72 | $this->assertMailIsNotPlain($mail); 73 | } 74 | 75 | public function testMailContentTypeNotPlainThrowsException() 76 | { 77 | $mail = (new Email()) 78 | ->to($this->faker->email) 79 | ->from($this->faker->email) 80 | ->text($this->faker->sentence); 81 | 82 | $this->expectException(ExpectationFailedException::class); 83 | $this->expectExceptionMessage('The mail is [text/plain].'); 84 | 85 | $this->assertMailIsNotPlain($mail); 86 | } 87 | 88 | /* 89 | |-------------------------------------------------------------------------- 90 | | assertMailHasPlainContent 91 | |-------------------------------------------------------------------------- 92 | */ 93 | 94 | public function testMailHasPlainContent() 95 | { 96 | $mail = (new Email()) 97 | ->to($this->faker->email) 98 | ->from($this->faker->email) 99 | ->text($this->faker->sentence) 100 | ->html($this->faker->sentence); 101 | 102 | $this->assertMailHasPlainContent($mail); 103 | } 104 | 105 | public function testMailHasPlainContentViaAssertableMessage() 106 | { 107 | $mail = new AssertableMessage( 108 | (new Email()) 109 | ->to($this->faker->email) 110 | ->from($this->faker->email) 111 | ->text($this->faker->sentence) 112 | ->html($this->faker->sentence) 113 | ); 114 | 115 | $this->assertMailHasPlainContent($mail); 116 | } 117 | 118 | public function testMailHasPlainContentThrowsException() 119 | { 120 | $mail = (new Email()) 121 | ->to($this->faker->email) 122 | ->from($this->faker->email) 123 | ->attach('attachment') 124 | ->html($this->faker->sentence); 125 | 126 | $this->expectException(ExpectationFailedException::class); 127 | $this->expectExceptionMessage('The mail does not have [text/plain] content.'); 128 | 129 | $this->assertMailHasPlainContent($mail); 130 | } 131 | 132 | /* 133 | |-------------------------------------------------------------------------- 134 | | assertMailDoesNotHavePlainContent 135 | |-------------------------------------------------------------------------- 136 | */ 137 | 138 | public function testMailDoesNotHavePlainContent() 139 | { 140 | $mail = (new Email()) 141 | ->to($this->faker->email) 142 | ->from($this->faker->email) 143 | ->attach('attachment') 144 | ->html($this->faker->sentence); 145 | 146 | $this->assertMailDoesNotHavePlainContent($mail); 147 | } 148 | 149 | public function testMailDoesNotHavePlainContentViaAssertableMessage() 150 | { 151 | $mail = new AssertableMessage( 152 | (new Email()) 153 | ->to($this->faker->email) 154 | ->from($this->faker->email) 155 | ->attach('attachment') 156 | ->html($this->faker->sentence) 157 | ); 158 | 159 | $this->assertMailDoesNotHavePlainContent($mail); 160 | } 161 | 162 | public function testMailDoesNotHavePlainContentThrowsException() 163 | { 164 | $mail = (new Email()) 165 | ->to($this->faker->email) 166 | ->from($this->faker->email) 167 | ->text($this->faker->sentence) 168 | ->html($this->faker->sentence); 169 | 170 | $this->expectException(ExpectationFailedException::class); 171 | $this->expectExceptionMessage('The mail does have [text/plain] content.'); 172 | 173 | $this->assertMailDoesNotHavePlainContent($mail); 174 | } 175 | 176 | /* 177 | |-------------------------------------------------------------------------- 178 | | assertMailIsHtml 179 | |-------------------------------------------------------------------------- 180 | */ 181 | 182 | public function testMailContentTypeHtml() 183 | { 184 | $mail = (new Email()) 185 | ->to($this->faker->email) 186 | ->from($this->faker->email) 187 | ->html($this->faker->sentence); 188 | 189 | $this->assertMailIsHtml($mail); 190 | } 191 | 192 | public function testMailContentTypeHtmlViaAssertableMessage() 193 | { 194 | $mail = new AssertableMessage( 195 | (new Email()) 196 | ->to($this->faker->email) 197 | ->from($this->faker->email) 198 | ->html($this->faker->sentence) 199 | ); 200 | 201 | $this->assertMailIsHtml($mail); 202 | } 203 | 204 | public function testMailContentTypeHtmlThrowsException() 205 | { 206 | $part = new TextPart('body', subtype: 'bad'); 207 | $mail = (new Email())->setBody($part); 208 | 209 | $this->expectException(ExpectationFailedException::class); 210 | $this->expectExceptionMessage('The mail is not [text/html].'); 211 | 212 | $this->assertMailIsHtml($mail); 213 | } 214 | 215 | /* 216 | |-------------------------------------------------------------------------- 217 | | assertMailIsNotHtml 218 | |-------------------------------------------------------------------------- 219 | */ 220 | 221 | public function testMailContentTypeNotHtml() 222 | { 223 | $part = new TextPart('body', subtype: 'not-html'); 224 | $mail = (new Email())->setBody($part); 225 | 226 | $this->assertMailIsNotHtml($mail); 227 | } 228 | 229 | public function testMailContentTypeNotHtmlViaAssertableMessage() 230 | { 231 | $part = new TextPart('body', subtype: 'not-html'); 232 | $mail = new AssertableMessage( 233 | (new Email())->setBody($part) 234 | ); 235 | 236 | $this->assertMailIsNotHtml($mail); 237 | } 238 | 239 | public function testMailContentTypeNotHtmlThrowsException() 240 | { 241 | $mail = (new Email()) 242 | ->to($this->faker->email) 243 | ->from($this->faker->email) 244 | ->html($this->faker->sentence); 245 | 246 | $this->expectException(ExpectationFailedException::class); 247 | $this->expectExceptionMessage('The mail is [text/html].'); 248 | 249 | $this->assertMailIsNotHtml($mail); 250 | } 251 | 252 | /* 253 | |-------------------------------------------------------------------------- 254 | | assertMailHasHtmlContent 255 | |-------------------------------------------------------------------------- 256 | */ 257 | 258 | public function testMailHasHtmlContent() 259 | { 260 | $mail = (new Email()) 261 | ->to($this->faker->email) 262 | ->from($this->faker->email) 263 | ->text($this->faker->sentence) 264 | ->html($this->faker->sentence); 265 | 266 | $this->assertMailHasHtmlContent($mail); 267 | } 268 | 269 | public function testMailHasHtmlContentViaAssertableMessage() 270 | { 271 | $mail = new AssertableMessage( 272 | (new Email()) 273 | ->to($this->faker->email) 274 | ->from($this->faker->email) 275 | ->text($this->faker->sentence) 276 | ->html($this->faker->sentence) 277 | ); 278 | 279 | $this->assertMailHasHtmlContent($mail); 280 | } 281 | 282 | public function testMailHasHtmlContentThrowsException() 283 | { 284 | $mail = (new Email()) 285 | ->to($this->faker->email) 286 | ->from($this->faker->email) 287 | ->attach('attachment') 288 | ->text($this->faker->sentence); 289 | 290 | $this->expectException(ExpectationFailedException::class); 291 | $this->expectExceptionMessage('The mail does not have [text/html] content.'); 292 | 293 | $this->assertMailHasHtmlContent($mail); 294 | } 295 | 296 | /* 297 | |-------------------------------------------------------------------------- 298 | | assertMailDoesNotHaveHtmlContent 299 | |-------------------------------------------------------------------------- 300 | */ 301 | 302 | public function testMailDoesNotHaveHtmlContent() 303 | { 304 | $mail = (new Email()) 305 | ->to($this->faker->email) 306 | ->from($this->faker->email) 307 | ->attach('attachment') 308 | ->text($this->faker->sentence); 309 | 310 | $this->assertMailDoesNotHaveHtmlContent($mail); 311 | } 312 | 313 | public function testMailDoesNotHaveHtmlContentViaAssertableMessage() 314 | { 315 | $mail = new AssertableMessage( 316 | (new Email()) 317 | ->to($this->faker->email) 318 | ->from($this->faker->email) 319 | ->attach('attachment') 320 | ->text($this->faker->sentence) 321 | ); 322 | 323 | $this->assertMailDoesNotHaveHtmlContent($mail); 324 | } 325 | 326 | public function testMailDoesNotHaveHtmlContentThrowsException() 327 | { 328 | $mail = (new Email()) 329 | ->to($this->faker->email) 330 | ->from($this->faker->email) 331 | ->text($this->faker->sentence) 332 | ->html($this->faker->sentence); 333 | 334 | $this->expectException(ExpectationFailedException::class); 335 | $this->expectExceptionMessage('The mail does have [text/html] content.'); 336 | 337 | $this->assertMailDoesNotHaveHtmlContent($mail); 338 | } 339 | 340 | /* 341 | |-------------------------------------------------------------------------- 342 | | assertMailIsAlternative 343 | |-------------------------------------------------------------------------- 344 | */ 345 | 346 | public function testMailContentTypeAlternative() 347 | { 348 | $mail = (new Email()) 349 | ->to($this->faker->email) 350 | ->from($this->faker->email) 351 | ->text($this->faker->sentence) 352 | ->html($this->faker->sentence); 353 | 354 | $this->assertMailIsAlternative($mail); 355 | } 356 | 357 | public function testMailContentTypeAlternativeViaAssertableMessage() 358 | { 359 | $mail = new AssertableMessage( 360 | (new Email()) 361 | ->to($this->faker->email) 362 | ->from($this->faker->email) 363 | ->text($this->faker->sentence) 364 | ->html($this->faker->sentence) 365 | ); 366 | 367 | $this->assertMailIsAlternative($mail); 368 | } 369 | 370 | public function testMailContentTypeAlternativeThrowsException() 371 | { 372 | $part = new TextPart('body', subtype: 'not-alternative'); 373 | $mail = (new Email())->setBody($part); 374 | 375 | $this->expectException(ExpectationFailedException::class); 376 | $this->expectExceptionMessage('The mail is not [multipart/alternative].'); 377 | 378 | $this->assertMailIsAlternative($mail); 379 | } 380 | 381 | /* 382 | |-------------------------------------------------------------------------- 383 | | assertMailIsNotAlternative 384 | |-------------------------------------------------------------------------- 385 | */ 386 | 387 | public function testMailContentTypeNotAlternative() 388 | { 389 | $part = new TextPart('body', subtype: 'not-alternative'); 390 | $mail = (new Email())->setBody($part); 391 | 392 | $this->assertMailIsNotAlternative($mail); 393 | } 394 | 395 | public function testMailContentTypeNotAlternativeViaAssertableMessage() 396 | { 397 | $part = new TextPart('body', subtype: 'not-alternative'); 398 | $mail = new AssertableMessage( 399 | (new Email())->setBody($part) 400 | ); 401 | 402 | $this->assertMailIsNotAlternative($mail); 403 | } 404 | 405 | public function testMailContentTypeNotAlternativeThrowsException() 406 | { 407 | $mail = (new Email()) 408 | ->to($this->faker->email) 409 | ->from($this->faker->email) 410 | ->text($this->faker->sentence) 411 | ->html($this->faker->sentence); 412 | 413 | $this->expectException(ExpectationFailedException::class); 414 | $this->expectExceptionMessage('The mail is [multipart/alternative].'); 415 | 416 | $this->assertMailIsNotAlternative($mail); 417 | } 418 | 419 | /* 420 | |-------------------------------------------------------------------------- 421 | | assertMailIsMixed 422 | |-------------------------------------------------------------------------- 423 | */ 424 | 425 | public function testMailContentTypeMixed() 426 | { 427 | $mail = (new Email()) 428 | ->to($this->faker->email) 429 | ->from($this->faker->email) 430 | ->attach('attachment') 431 | ->text($this->faker->sentence); 432 | 433 | $this->assertMailIsMixed($mail); 434 | } 435 | 436 | public function testMailContentTypeMixedViaAssertableMessage() 437 | { 438 | $mail = new AssertableMessage( 439 | (new Email()) 440 | ->to($this->faker->email) 441 | ->from($this->faker->email) 442 | ->attach('attachment') 443 | ->text($this->faker->sentence) 444 | ); 445 | 446 | $this->assertMailIsMixed($mail); 447 | } 448 | 449 | public function testMailContentTypeMixedThrowsException() 450 | { 451 | $part = new TextPart('body', subtype: 'not-mixed'); 452 | $mail = (new Email())->setBody($part); 453 | 454 | $this->expectException(ExpectationFailedException::class); 455 | $this->expectExceptionMessage('The mail is not [multipart/mixed].'); 456 | 457 | $this->assertMailIsMixed($mail); 458 | } 459 | 460 | /* 461 | |-------------------------------------------------------------------------- 462 | | assertMailIsNotMixed 463 | |-------------------------------------------------------------------------- 464 | */ 465 | 466 | public function testMailContentTypeNotMixed() 467 | { 468 | $part = new TextPart('body', subtype: 'not-mixed'); 469 | $mail = (new Email())->setBody($part); 470 | 471 | $this->assertMailIsNotMixed($mail); 472 | } 473 | 474 | public function testMailContentTypeNotMixedViaAssertableMessage() 475 | { 476 | $part = new TextPart('body', subtype: 'not-mixed'); 477 | $mail = new AssertableMessage( 478 | (new Email())->setBody($part) 479 | ); 480 | 481 | $this->assertMailIsNotMixed($mail); 482 | } 483 | 484 | public function testMailContentTypeNotMixedThrowsException() 485 | { 486 | $mail = (new Email()) 487 | ->to($this->faker->email) 488 | ->from($this->faker->email) 489 | ->attach('attachment') 490 | ->text($this->faker->sentence); 491 | 492 | $this->expectException(ExpectationFailedException::class); 493 | $this->expectExceptionMessage('The mail is [multipart/mixed].'); 494 | 495 | $this->assertMailIsNotMixed($mail); 496 | } 497 | } 498 | -------------------------------------------------------------------------------- /tests/EnableInterceptionTest.php: -------------------------------------------------------------------------------- 1 | interceptMail(); 15 | 16 | $this->assertTrue(Config::has('mail.driver')); 17 | $this->assertEquals('array', Config::get('mail.driver')); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/Fixtures/f-18.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirschbaum-development/mail-intercept/51af94ec03ed8ea29ded55b469ca3bfebac323db/tests/Fixtures/f-18.jpg -------------------------------------------------------------------------------- /tests/Fluent/AttachmentAssertionsTest.php: -------------------------------------------------------------------------------- 1 | addPart(new DataPart(new File(__DIR__ . '/../Fixtures/f-18.jpg'))) 24 | ); 25 | 26 | $mail->assertHasAttachments($mail); 27 | } 28 | 29 | public function testMailHasAttachmentsThrowsProperExpectationFailedException() 30 | { 31 | $mail = new AssertableMessage( 32 | new Email() 33 | ); 34 | 35 | $this->expectException(ExpectationFailedException::class); 36 | $this->expectExceptionMessage('Mail missing expected attachments.'); 37 | 38 | $mail->assertHasAttachments($mail); 39 | } 40 | 41 | /* 42 | |-------------------------------------------------------------------------- 43 | | assertMailMissingAttachments 44 | |-------------------------------------------------------------------------- 45 | */ 46 | 47 | public function testMailMissingAttachments() 48 | { 49 | $mail = new AssertableMessage( 50 | new Email() 51 | ); 52 | 53 | $mail->assertMissingAttachments($mail); 54 | } 55 | 56 | public function testMailMissingAttachmentsThrowsProperExpectationFailedException() 57 | { 58 | $mail = new AssertableMessage( 59 | (new Email())->addPart(new DataPart(new File(__DIR__ . '/../Fixtures/f-18.jpg'))) 60 | ); 61 | 62 | $this->expectException(ExpectationFailedException::class); 63 | $this->expectExceptionMessage('Mail has expected attachments.'); 64 | 65 | $mail->assertMissingAttachments($mail); 66 | } 67 | 68 | /* 69 | |-------------------------------------------------------------------------- 70 | | testMailHasAttachment 71 | |-------------------------------------------------------------------------- 72 | */ 73 | 74 | public function testMailHasAttachment() 75 | { 76 | $mail = new AssertableMessage( 77 | (new Email())->addPart(new DataPart(new File(__DIR__ . '/../Fixtures/f-18.jpg'))) 78 | ); 79 | 80 | $mail->assertHasAttachment('f-18.jpg', $mail); 81 | } 82 | 83 | public function testMailHasAttachmentThrowsProperExpectationFailedException() 84 | { 85 | $mail = new AssertableMessage( 86 | new Email() 87 | ); 88 | 89 | $this->expectException(ExpectationFailedException::class); 90 | $this->expectExceptionMessage('Mail missing expected attachment.'); 91 | 92 | $mail->assertHasAttachment('f-18.jpg', $mail); 93 | } 94 | 95 | /* 96 | |-------------------------------------------------------------------------- 97 | | testMailMissingAttachment 98 | |-------------------------------------------------------------------------- 99 | */ 100 | 101 | public function testMailMissingAttachment() 102 | { 103 | $mail = new AssertableMessage( 104 | new Email() 105 | ); 106 | 107 | $mail->assertMissingAttachment('f-18.jpg', $mail); 108 | } 109 | 110 | public function testMailMissingAttachmentThrowsProperExpectationFailedException() 111 | { 112 | $mail = new AssertableMessage( 113 | (new Email())->addPart(new DataPart(new File(__DIR__ . '/../Fixtures/f-18.jpg'))) 114 | ); 115 | 116 | $this->expectException(ExpectationFailedException::class); 117 | $this->expectExceptionMessage('Mail has expected attachment.'); 118 | 119 | $mail->assertMissingAttachment('f-18.jpg', $mail); 120 | } 121 | 122 | /* 123 | |-------------------------------------------------------------------------- 124 | | assertMailHasEmbeddedImages 125 | |-------------------------------------------------------------------------- 126 | */ 127 | 128 | public function testMailHasEmbeddedImages() 129 | { 130 | $mail = new AssertableMessage( 131 | (new Email())->addPart((new DataPart(new File(__DIR__ . '/../Fixtures/f-18.jpg')))->asInline()) 132 | ); 133 | 134 | $mail->assertHasEmbeddedImages($mail); 135 | } 136 | 137 | public function testMailHasEmbeddedImagesThrowsProperExpectationFailedException() 138 | { 139 | $mail = new AssertableMessage( 140 | new Email() 141 | ); 142 | 143 | $this->expectException(ExpectationFailedException::class); 144 | $this->expectExceptionMessage('Mail missing embedded images.'); 145 | 146 | $mail->assertHasEmbeddedImages($mail); 147 | } 148 | 149 | /* 150 | |-------------------------------------------------------------------------- 151 | | assertMailMissingEmbeddedImages 152 | |-------------------------------------------------------------------------- 153 | */ 154 | 155 | public function testMailMissingEmbeddedImages() 156 | { 157 | $mail = new AssertableMessage( 158 | new Email() 159 | ); 160 | 161 | $mail->assertMissingEmbeddedImages($mail); 162 | } 163 | 164 | public function testMailMissingEmbeddedImagesThrowsProperExpectationFailedException() 165 | { 166 | $mail = new AssertableMessage( 167 | (new Email())->addPart((new DataPart(new File(__DIR__ . '/../Fixtures/f-18.jpg')))->asInline()) 168 | ); 169 | 170 | $this->expectException(ExpectationFailedException::class); 171 | $this->expectExceptionMessage('Mail has embedded images.'); 172 | 173 | $mail->assertMissingEmbeddedImages($mail); 174 | } 175 | 176 | /* 177 | |-------------------------------------------------------------------------- 178 | | testMailHasEmbeddedImage 179 | |-------------------------------------------------------------------------- 180 | */ 181 | 182 | public function testMailHasEmbeddedImage() 183 | { 184 | $mail = new AssertableMessage( 185 | (new Email())->addPart((new DataPart(new File(__DIR__ . '/../Fixtures/f-18.jpg')))->asInline()) 186 | ); 187 | 188 | $mail->assertHasEmbeddedImage('f-18.jpg', $mail); 189 | } 190 | 191 | public function testMailHasEmbeddedImageThrowsProperExpectationFailedException() 192 | { 193 | $mail = new AssertableMessage( 194 | new Email() 195 | ); 196 | 197 | $this->expectException(ExpectationFailedException::class); 198 | $this->expectExceptionMessage('Mail missing expected embedded image.'); 199 | 200 | $mail->assertHasEmbeddedImage('f-18.jpg', $mail); 201 | } 202 | 203 | public function testMailHasEmbeddedImageButCheckingForWrongImageThrowsProperExpectationFailedException() 204 | { 205 | $mail = new AssertableMessage( 206 | new Email() 207 | ); 208 | 209 | $this->expectException(ExpectationFailedException::class); 210 | $this->expectExceptionMessage('Mail missing expected embedded image.'); 211 | 212 | $mail->assertHasEmbeddedImage('f-22.jpg', $mail); 213 | } 214 | 215 | /* 216 | |-------------------------------------------------------------------------- 217 | | testMailMissingEmbeddedImage 218 | |-------------------------------------------------------------------------- 219 | */ 220 | 221 | public function testMailMissingEmbeddedImage() 222 | { 223 | $mail = new AssertableMessage( 224 | new Email() 225 | ); 226 | 227 | $mail->assertMissingEmbeddedImage('f-18.jpg', $mail); 228 | } 229 | 230 | public function testMailMissingEmbeddedImageThrowsProperExpectationFailedException() 231 | { 232 | $mail = new AssertableMessage( 233 | (new Email())->addPart((new DataPart(new File(__DIR__ . '/../Fixtures/f-18.jpg')))->asInline()) 234 | ); 235 | 236 | $this->expectException(ExpectationFailedException::class); 237 | $this->expectExceptionMessage('Mail has expected embedded image.'); 238 | 239 | $mail->assertMissingEmbeddedImage('f-18.jpg', $mail); 240 | } 241 | 242 | public function testMailHasEmbeddedImageButCheckingForDifferentImage() 243 | { 244 | $mail = new AssertableMessage( 245 | (new Email())->addPart((new DataPart(new File(__DIR__ . '/../Fixtures/f-18.jpg')))->asInline()) 246 | ); 247 | 248 | $mail->assertMissingEmbeddedImage('f-22.jpg', $mail); 249 | } 250 | } 251 | -------------------------------------------------------------------------------- /tests/Fluent/BccAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->email; 15 | 16 | $mail = new AssertableMessage( 17 | (new Email())->bcc($email) 18 | ); 19 | 20 | $mail->assertBcc($email); 21 | } 22 | 23 | public function testMailBccThrowsProperExpectationFailedException() 24 | { 25 | $email = $this->faker->unique()->email; 26 | 27 | $mail = new AssertableMessage( 28 | (new Email())->bcc($this->faker->unique()->email) 29 | ); 30 | 31 | $this->expectException(ExpectationFailedException::class); 32 | $this->expectExceptionMessage("Mail was not BCC'd to the expected address [{$email}]."); 33 | 34 | $mail->assertBcc($email); 35 | } 36 | 37 | public function testMailSentToMultipleEmails() 38 | { 39 | $emails = [ 40 | $this->faker->email, 41 | $this->faker->email, 42 | ]; 43 | 44 | $mail = new AssertableMessage( 45 | (new Email())->bcc(...$emails) 46 | ); 47 | 48 | $mail->assertBcc($emails); 49 | } 50 | 51 | public function testMailNotSentToSingleEmail() 52 | { 53 | $email = $this->faker->unique()->email; 54 | 55 | $mail = new AssertableMessage( 56 | (new Email())->bcc($this->faker->unique()->email) 57 | ); 58 | 59 | $mail->assertNotBcc($email); 60 | } 61 | 62 | public function testMailNotSentToThrowsProperExpectationFailedException() 63 | { 64 | $email = $this->faker->unique()->email; 65 | 66 | $mail = new AssertableMessage( 67 | (new Email())->bcc($email) 68 | ); 69 | 70 | $this->expectException(ExpectationFailedException::class); 71 | $this->expectExceptionMessage("Mail was BCC'd to the expected address [{$email}]."); 72 | 73 | $mail->assertNotBcc($email); 74 | } 75 | 76 | public function testMailNotSentToMultipleEmails() 77 | { 78 | $emails = [ 79 | $this->faker->unique()->email, 80 | $this->faker->unique()->email, 81 | ]; 82 | 83 | $mail = new AssertableMessage( 84 | (new Email())->bcc( 85 | $this->faker->unique()->email, 86 | $this->faker->unique()->email 87 | ) 88 | ); 89 | 90 | $mail->assertNotBcc($emails); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /tests/Fluent/CcAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->email; 15 | 16 | $mail = new AssertableMessage( 17 | (new Email())->cc($email) 18 | ); 19 | 20 | $mail->assertCc($email); 21 | } 22 | 23 | public function testMailCcThrowsProperExpectationFailedException() 24 | { 25 | $email = $this->faker->unique()->email; 26 | 27 | $mail = new AssertableMessage( 28 | (new Email())->cc($this->faker->unique()->email) 29 | ); 30 | 31 | $this->expectException(ExpectationFailedException::class); 32 | $this->expectExceptionMessage("Mail was not CC'd to the expected address [{$email}]."); 33 | 34 | $mail->assertCc($email); 35 | } 36 | 37 | public function testMailSentToMultipleEmails() 38 | { 39 | $emails = [ 40 | $this->faker->email, 41 | $this->faker->email, 42 | ]; 43 | 44 | $mail = new AssertableMessage( 45 | (new Email())->cc(...$emails) 46 | ); 47 | 48 | $mail->assertCc($emails); 49 | } 50 | 51 | public function testMailNotSentToSingleEmail() 52 | { 53 | $email = $this->faker->unique()->email; 54 | 55 | $mail = new AssertableMessage( 56 | (new Email())->cc($this->faker->unique()->email) 57 | ); 58 | 59 | $mail->assertNotCc($email); 60 | } 61 | 62 | public function testMailNotSentToThrowsProperExpectationFailedException() 63 | { 64 | $email = $this->faker->unique()->email; 65 | 66 | $mail = new AssertableMessage( 67 | (new Email())->cc($email) 68 | ); 69 | 70 | $this->expectException(ExpectationFailedException::class); 71 | $this->expectExceptionMessage("Mail was CC'd to the expected address [{$email}]."); 72 | 73 | $mail->assertNotCc($email); 74 | } 75 | 76 | public function testMailNotSentToMultipleEmails() 77 | { 78 | $emails = [ 79 | $this->faker->unique()->email, 80 | $this->faker->unique()->email, 81 | ]; 82 | 83 | $mail = new AssertableMessage( 84 | (new Email())->cc( 85 | $this->faker->unique()->email, 86 | $this->faker->unique()->email 87 | ) 88 | ); 89 | 90 | $mail->assertNotCc($emails); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /tests/Fluent/ContentAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->sentence; 16 | 17 | $mail = new AssertableMessage( 18 | (new Email()) 19 | ->to($this->faker->email) 20 | ->from($this->faker->email) 21 | ->text($content) 22 | ); 23 | 24 | $mail->assertBodyContainsString($content); 25 | } 26 | 27 | public function testMailBodyContentsAsTextThrowsProperExpectationFailedException() 28 | { 29 | $content = $this->faker->unique()->sentence; 30 | 31 | $mail = new AssertableMessage( 32 | (new Email()) 33 | ->to($this->faker->email) 34 | ->from($this->faker->email) 35 | ->text($this->faker->unique()->sentence) 36 | ); 37 | 38 | $this->expectException(ExpectationFailedException::class); 39 | $this->expectExceptionMessage("The expected [{$content}] string was not found in the body."); 40 | 41 | $mail->assertBodyContainsString($content); 42 | } 43 | 44 | public function testMailBodyAsTextDoesNotHaveContents() 45 | { 46 | $content = $this->faker->unique()->sentence; 47 | 48 | $mail = new AssertableMessage( 49 | (new Email()) 50 | ->to($this->faker->email) 51 | ->from($this->faker->email) 52 | ->text($this->faker->unique()->sentence) 53 | ); 54 | 55 | $mail->assertBodyNotContainsString($content); 56 | } 57 | 58 | public function testMailBodyAsTextDoesNotHaveContentsThrowsProperExpectationFailedException() 59 | { 60 | $content = $this->faker->sentence; 61 | 62 | $mail = new AssertableMessage( 63 | (new Email()) 64 | ->to($this->faker->email) 65 | ->from($this->faker->email) 66 | ->text($content) 67 | ); 68 | 69 | $this->expectException(ExpectationFailedException::class); 70 | $this->expectExceptionMessage("The expected [{$content}] string was found in the body."); 71 | 72 | $mail->assertBodyNotContainsString($content); 73 | } 74 | 75 | public function testMailBodyContentsAsHtml() 76 | { 77 | $content = $this->faker->sentence; 78 | 79 | $mail = new AssertableMessage( 80 | (new Email()) 81 | ->to($this->faker->email) 82 | ->from($this->faker->email) 83 | ->html($content) 84 | ); 85 | 86 | $mail->assertBodyContainsString($content); 87 | } 88 | 89 | public function testMailBodyContentsAsHtmlThrowsProperExpectationFailedException() 90 | { 91 | $content = $this->faker->unique()->sentence; 92 | 93 | $mail = new AssertableMessage( 94 | (new Email()) 95 | ->to($this->faker->email) 96 | ->from($this->faker->email) 97 | ->html($this->faker->unique()->sentence) 98 | ); 99 | 100 | $this->expectException(ExpectationFailedException::class); 101 | $this->expectExceptionMessage("The expected [{$content}] string was not found in the body."); 102 | 103 | $mail->assertBodyContainsString($content); 104 | } 105 | 106 | public function testMailBodyAsHtmlDoesNotHaveContents() 107 | { 108 | $content = $this->faker->unique()->sentence; 109 | 110 | $mail = new AssertableMessage( 111 | (new Email()) 112 | ->to($this->faker->email) 113 | ->from($this->faker->email) 114 | ->html($this->faker->unique()->sentence) 115 | ); 116 | 117 | $mail->assertBodyNotContainsString($content); 118 | } 119 | 120 | public function testMailBodyAsHtmlDoesNotHaveContentsThrowsProperExpectationFailedException() 121 | { 122 | $content = $this->faker->sentence; 123 | 124 | $mail = new AssertableMessage( 125 | (new Email()) 126 | ->to($this->faker->email) 127 | ->from($this->faker->email) 128 | ->html($content) 129 | ); 130 | 131 | $this->expectException(ExpectationFailedException::class); 132 | $this->expectExceptionMessage("The expected [{$content}] string was found in the body."); 133 | 134 | $mail->assertBodyNotContainsString($content); 135 | } 136 | 137 | public function testMailBodyContentsAsAbstractPart() 138 | { 139 | $content = $this->faker->sentence; 140 | $textPart = new TextPart($content); 141 | 142 | $mail = new AssertableMessage( 143 | (new Email())->setBody($textPart) 144 | ); 145 | 146 | $mail->assertBodyContainsString($content); 147 | } 148 | 149 | public function testMailBodyContentsAsAbstractPartThrowsProperExpectationFailedException() 150 | { 151 | $content = $this->faker->unique()->sentence; 152 | $textPart = new TextPart($this->faker->unique()->sentence); 153 | 154 | $mail = new AssertableMessage( 155 | (new Email())->setBody($textPart) 156 | ); 157 | 158 | $this->expectException(ExpectationFailedException::class); 159 | $this->expectExceptionMessage("The expected [{$content}] string was not found in the body."); 160 | 161 | $mail->assertBodyContainsString($content); 162 | } 163 | 164 | public function testMailBodyAsAbstractPartDoesNotHaveContents() 165 | { 166 | $content = $this->faker->unique()->sentence; 167 | $textPart = new TextPart($this->faker->unique()->sentence); 168 | 169 | $mail = new AssertableMessage( 170 | (new Email())->setBody($textPart) 171 | ); 172 | 173 | $mail->assertBodyNotContainsString($content); 174 | } 175 | 176 | public function testMailBodyAsAbstractPartDoesNotHaveContentsThrowsProperExpectationFailedException() 177 | { 178 | $content = $this->faker->sentence; 179 | $textPart = new TextPart($content); 180 | 181 | $mail = new AssertableMessage( 182 | (new Email())->setBody($textPart) 183 | ); 184 | 185 | $this->expectException(ExpectationFailedException::class); 186 | $this->expectExceptionMessage("The expected [{$content}] string was found in the body."); 187 | 188 | $mail->assertBodyNotContainsString($content); 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /tests/Fluent/ContentTypeAssertionsTest.php: -------------------------------------------------------------------------------- 1 | to($this->faker->email) 18 | ->from($this->faker->email) 19 | ->text($this->faker->sentence) 20 | ); 21 | 22 | $mail->assertIsPlain(); 23 | } 24 | 25 | public function testMailContentTypePlainThrowsException() 26 | { 27 | $part = new TextPart('body', subtype: 'bad'); 28 | $mail = new AssertableMessage( 29 | (new Email())->setBody($part) 30 | ); 31 | 32 | $this->expectException(ExpectationFailedException::class); 33 | $this->expectExceptionMessage('The mail is not [text/plain].'); 34 | 35 | $mail->assertIsPlain(); 36 | } 37 | 38 | public function testMailContentTypeNotPlain() 39 | { 40 | $part = new TextPart('body', subtype: 'not-plain'); 41 | $mail = new AssertableMessage( 42 | (new Email())->setBody($part) 43 | ); 44 | 45 | $mail->assertIsNotPlain(); 46 | } 47 | 48 | public function testMailContentTypeNotPlainThrowsException() 49 | { 50 | $mail = new AssertableMessage( 51 | (new Email()) 52 | ->to($this->faker->email) 53 | ->from($this->faker->email) 54 | ->text($this->faker->sentence) 55 | ); 56 | 57 | $this->expectException(ExpectationFailedException::class); 58 | $this->expectExceptionMessage('The mail is [text/plain].'); 59 | 60 | $mail->assertIsNotPlain(); 61 | } 62 | 63 | public function testMailHasPlainContent() 64 | { 65 | $mail = new AssertableMessage( 66 | (new Email()) 67 | ->to($this->faker->email) 68 | ->from($this->faker->email) 69 | ->text($this->faker->sentence) 70 | ->html($this->faker->sentence) 71 | ); 72 | 73 | $mail->assertHasPlainContent(); 74 | } 75 | 76 | public function testMailHasPlainContentThrowsException() 77 | { 78 | $mail = new AssertableMessage( 79 | (new Email()) 80 | ->to($this->faker->email) 81 | ->from($this->faker->email) 82 | ->attach('attachment') 83 | ->html($this->faker->sentence) 84 | ); 85 | 86 | $this->expectException(ExpectationFailedException::class); 87 | $this->expectExceptionMessage('The mail does not have [text/plain] content.'); 88 | 89 | $mail->assertHasPlainContent(); 90 | } 91 | 92 | public function testMailDoesNotHavePlainContent() 93 | { 94 | $mail = new AssertableMessage( 95 | (new Email()) 96 | ->to($this->faker->email) 97 | ->from($this->faker->email) 98 | ->attach('attachment') 99 | ->html($this->faker->sentence) 100 | ); 101 | 102 | $mail->assertDoesNotHavePlainContent(); 103 | } 104 | 105 | public function testMailDoesNotHavePlainContentThrowsException() 106 | { 107 | $mail = new AssertableMessage( 108 | (new Email()) 109 | ->to($this->faker->email) 110 | ->from($this->faker->email) 111 | ->text($this->faker->sentence) 112 | ->html($this->faker->sentence) 113 | ); 114 | 115 | $this->expectException(ExpectationFailedException::class); 116 | $this->expectExceptionMessage('The mail does have [text/plain] content.'); 117 | 118 | $mail->assertDoesNotHavePlainContent(); 119 | } 120 | 121 | public function testMailContentTypeHtml() 122 | { 123 | $mail = new AssertableMessage( 124 | (new Email()) 125 | ->to($this->faker->email) 126 | ->from($this->faker->email) 127 | ->html($this->faker->sentence) 128 | ); 129 | 130 | $mail->assertIsHtml(); 131 | } 132 | 133 | public function testMailContentTypeHtmlThrowsException() 134 | { 135 | $part = new TextPart('body', subtype: 'bad'); 136 | $mail = new AssertableMessage( 137 | (new Email())->setBody($part) 138 | ); 139 | 140 | $this->expectException(ExpectationFailedException::class); 141 | $this->expectExceptionMessage('The mail is not [text/html].'); 142 | 143 | $mail->assertIsHtml(); 144 | } 145 | 146 | public function testMailContentTypeNotHtml() 147 | { 148 | $part = new TextPart('body', subtype: 'not-html'); 149 | $mail = new AssertableMessage( 150 | (new Email())->setBody($part) 151 | ); 152 | 153 | $mail->assertIsNotHtml(); 154 | } 155 | 156 | public function testMailContentTypeNotHtmlThrowsException() 157 | { 158 | $mail = new AssertableMessage( 159 | (new Email()) 160 | ->to($this->faker->email) 161 | ->from($this->faker->email) 162 | ->html($this->faker->sentence) 163 | ); 164 | 165 | $this->expectException(ExpectationFailedException::class); 166 | $this->expectExceptionMessage('The mail is [text/html].'); 167 | 168 | $mail->assertIsNotHtml(); 169 | } 170 | 171 | public function testMailHasHtmlContent() 172 | { 173 | $mail = new AssertableMessage( 174 | (new Email()) 175 | ->to($this->faker->email) 176 | ->from($this->faker->email) 177 | ->text($this->faker->sentence) 178 | ->html($this->faker->sentence) 179 | ); 180 | 181 | $mail->assertHasHtmlContent(); 182 | } 183 | 184 | public function testMailHasHtmlContentThrowsException() 185 | { 186 | $mail = new AssertableMessage( 187 | (new Email()) 188 | ->to($this->faker->email) 189 | ->from($this->faker->email) 190 | ->attach('attachment') 191 | ->text($this->faker->sentence) 192 | ); 193 | 194 | $this->expectException(ExpectationFailedException::class); 195 | $this->expectExceptionMessage('The mail does not have [text/html] content.'); 196 | 197 | $mail->assertHasHtmlContent(); 198 | } 199 | 200 | public function testMailDoesNotHaveHtmlContent() 201 | { 202 | $mail = new AssertableMessage( 203 | (new Email()) 204 | ->to($this->faker->email) 205 | ->from($this->faker->email) 206 | ->attach('attachment') 207 | ->text($this->faker->sentence) 208 | ); 209 | 210 | $mail->assertDoesNotHaveHtmlContent(); 211 | } 212 | 213 | public function testMailDoesNotHaveHtmlContentThrowsException() 214 | { 215 | $mail = new AssertableMessage( 216 | (new Email()) 217 | ->to($this->faker->email) 218 | ->from($this->faker->email) 219 | ->text($this->faker->sentence) 220 | ->html($this->faker->sentence) 221 | ); 222 | 223 | $this->expectException(ExpectationFailedException::class); 224 | $this->expectExceptionMessage('The mail does have [text/html] content.'); 225 | 226 | $mail->assertDoesNotHaveHtmlContent(); 227 | } 228 | 229 | public function testMailContentTypeAlternative() 230 | { 231 | $mail = new AssertableMessage( 232 | (new Email()) 233 | ->to($this->faker->email) 234 | ->from($this->faker->email) 235 | ->text($this->faker->sentence) 236 | ->html($this->faker->sentence) 237 | ); 238 | 239 | $mail->assertIsAlternative(); 240 | } 241 | 242 | public function testMailContentTypeAlternativeThrowsException() 243 | { 244 | $part = new TextPart('body', subtype: 'not-alternative'); 245 | $mail = new AssertableMessage( 246 | (new Email())->setBody($part) 247 | ); 248 | 249 | $this->expectException(ExpectationFailedException::class); 250 | $this->expectExceptionMessage('The mail is not [multipart/alternative].'); 251 | 252 | $mail->assertIsAlternative(); 253 | } 254 | 255 | public function testMailContentTypeNotAlternative() 256 | { 257 | $part = new TextPart('body', subtype: 'not-alternative'); 258 | $mail = new AssertableMessage( 259 | (new Email())->setBody($part) 260 | ); 261 | 262 | $mail->assertIsNotAlternative(); 263 | } 264 | 265 | public function testMailContentTypeNotAlternativeThrowsException() 266 | { 267 | $mail = new AssertableMessage( 268 | (new Email()) 269 | ->to($this->faker->email) 270 | ->from($this->faker->email) 271 | ->text($this->faker->sentence) 272 | ->html($this->faker->sentence) 273 | ); 274 | 275 | $this->expectException(ExpectationFailedException::class); 276 | $this->expectExceptionMessage('The mail is [multipart/alternative].'); 277 | 278 | $mail->assertIsNotAlternative(); 279 | } 280 | 281 | public function testMailContentTypeMixed() 282 | { 283 | $mail = new AssertableMessage( 284 | (new Email()) 285 | ->to($this->faker->email) 286 | ->from($this->faker->email) 287 | ->attach('attachment') 288 | ->text($this->faker->sentence) 289 | ); 290 | 291 | $mail->assertIsMixed(); 292 | } 293 | 294 | public function testMailContentTypeMixedThrowsException() 295 | { 296 | $part = new TextPart('body', subtype: 'not-mixed'); 297 | $mail = new AssertableMessage( 298 | (new Email())->setBody($part) 299 | ); 300 | 301 | $this->expectException(ExpectationFailedException::class); 302 | $this->expectExceptionMessage('The mail is not [multipart/mixed].'); 303 | 304 | $mail->assertIsMixed(); 305 | } 306 | 307 | public function testMailContentTypeNotMixed() 308 | { 309 | $part = new TextPart('body', subtype: 'not-mixed'); 310 | $mail = new AssertableMessage( 311 | (new Email())->setBody($part) 312 | ); 313 | 314 | $mail->assertIsNotMixed(); 315 | } 316 | 317 | public function testMailContentTypeNotMixedThrowsException() 318 | { 319 | $mail = new AssertableMessage( 320 | (new Email()) 321 | ->to($this->faker->email) 322 | ->from($this->faker->email) 323 | ->attach('attachment') 324 | ->text($this->faker->sentence) 325 | ); 326 | 327 | $this->expectException(ExpectationFailedException::class); 328 | $this->expectExceptionMessage('The mail is [multipart/mixed].'); 329 | 330 | $mail->assertIsNotMixed(); 331 | } 332 | } 333 | -------------------------------------------------------------------------------- /tests/Fluent/FromAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->email; 15 | 16 | $mail = new AssertableMessage( 17 | (new Email())->from($email) 18 | ); 19 | 20 | $mail->assertSentFrom($email); 21 | } 22 | 23 | public function testMailSentFromThrowsProperExpectationFailedException() 24 | { 25 | $email = $this->faker->unique()->email; 26 | 27 | $mail = new AssertableMessage( 28 | (new Email())->from($this->faker->unique()->email) 29 | ); 30 | 31 | $this->expectException(ExpectationFailedException::class); 32 | $this->expectExceptionMessage("Mail was not sent from the expected address [{$email}]."); 33 | 34 | $mail->assertSentFrom($email); 35 | } 36 | 37 | public function testMailSentFromMultipleEmails() 38 | { 39 | $emails = [ 40 | $this->faker->email, 41 | $this->faker->email, 42 | ]; 43 | 44 | $mail = new AssertableMessage( 45 | (new Email())->from(...$emails) 46 | ); 47 | 48 | $mail->assertSentFrom($emails); 49 | } 50 | 51 | public function testMailNotSentFromSingleEmail() 52 | { 53 | $email = $this->faker->unique()->email; 54 | 55 | $mail = new AssertableMessage( 56 | (new Email())->from($this->faker->unique()->email) 57 | ); 58 | 59 | $mail->assertNotSentFrom($email); 60 | } 61 | 62 | public function testMailNotSentFromThrowsProperExpectationFailedException() 63 | { 64 | $email = $this->faker->email; 65 | 66 | $mail = new AssertableMessage( 67 | (new Email())->from($email) 68 | ); 69 | 70 | $this->expectException(ExpectationFailedException::class); 71 | $this->expectExceptionMessage("Mail was sent from the expected address [{$email}]."); 72 | 73 | $mail->assertNotSentFrom($email); 74 | } 75 | 76 | public function testMailNotSentFromMultipleEmails() 77 | { 78 | $emails = [ 79 | $this->faker->unique()->email, 80 | $this->faker->unique()->email, 81 | ]; 82 | 83 | $mail = new AssertableMessage( 84 | (new Email())->from( 85 | $this->faker->unique()->email, 86 | $this->faker->unique()->email 87 | ) 88 | ); 89 | 90 | $mail->assertNotSentFrom($emails); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /tests/Fluent/PriorityAssertionsTest.php: -------------------------------------------------------------------------------- 1 | priority($priority) 18 | ); 19 | 20 | $mail->assertPriority($priority); 21 | } 22 | 23 | public function testMailPriorityThrowsProperExpectationFailedException() 24 | { 25 | $priorities = collect(range(1, 5))->shuffle(); 26 | $actualPriority = $priorities->pop(); 27 | $expectedPriority = $priorities->random(); 28 | 29 | $mail = new AssertableMessage( 30 | (new Email())->priority($actualPriority) 31 | ); 32 | 33 | $this->expectException(ExpectationFailedException::class); 34 | $this->expectExceptionMessage("The expected priority was not [{$expectedPriority}]."); 35 | 36 | $mail->assertPriority($expectedPriority); 37 | } 38 | 39 | public function testMailNotPrioritySingleEmail() 40 | { 41 | $priorities = collect(range(1, 5))->shuffle(); 42 | $actualPriority = $priorities->pop(); 43 | $expectedPriority = $priorities->random(); 44 | 45 | $mail = new AssertableMessage( 46 | (new Email())->priority($actualPriority) 47 | ); 48 | 49 | $mail->assertNotPriority($expectedPriority); 50 | } 51 | 52 | public function testMailNotPriorityThrowsProperExpectationFailedException() 53 | { 54 | $priority = mt_rand(1, 5); 55 | 56 | $mail = new AssertableMessage( 57 | (new Email())->priority($priority) 58 | ); 59 | 60 | $this->expectException(ExpectationFailedException::class); 61 | $this->expectExceptionMessage("The expected priority was [{$priority}]."); 62 | 63 | $mail->assertNotPriority($priority); 64 | } 65 | 66 | public function testMailPriorityHighest() 67 | { 68 | $mail = new AssertableMessage( 69 | (new Email())->priority(Email::PRIORITY_HIGHEST) 70 | ); 71 | 72 | $mail->assertPriorityIsHighest(); 73 | } 74 | 75 | public function testMailPriorityHighestThrowsProperExpectationFailedException() 76 | { 77 | $mail = new AssertableMessage( 78 | (new Email())->priority(Email::PRIORITY_LOWEST) 79 | ); 80 | 81 | $this->expectException(ExpectationFailedException::class); 82 | $this->expectExceptionMessage('The expected priority was not [highest].'); 83 | 84 | $mail->assertPriorityIsHighest(); 85 | } 86 | 87 | public function testMailPriorityNotHighest() 88 | { 89 | $mail = new AssertableMessage( 90 | (new Email())->priority(Email::PRIORITY_LOWEST) 91 | ); 92 | 93 | $mail->assertPriorityNotHighest(); 94 | } 95 | 96 | public function testMailPriorityNotHighestThrowsProperExpectationFailedException() 97 | { 98 | $mail = new AssertableMessage( 99 | (new Email())->priority(Email::PRIORITY_HIGHEST) 100 | ); 101 | 102 | $this->expectException(ExpectationFailedException::class); 103 | $this->expectExceptionMessage('The expected priority was [highest].'); 104 | 105 | $mail->assertPriorityNotHighest(); 106 | } 107 | 108 | public function testMailPriorityHigh() 109 | { 110 | $mail = new AssertableMessage( 111 | (new Email())->priority(Email::PRIORITY_HIGH) 112 | ); 113 | 114 | $mail->assertPriorityIsHigh(); 115 | } 116 | 117 | public function testMailPriorityHighThrowsProperExpectationFailedException() 118 | { 119 | $mail = new AssertableMessage( 120 | (new Email())->priority(Email::PRIORITY_LOWEST) 121 | ); 122 | 123 | $this->expectException(ExpectationFailedException::class); 124 | $this->expectExceptionMessage('The expected priority was not [high].'); 125 | 126 | $mail->assertPriorityIsHigh(); 127 | } 128 | 129 | public function testMailPriorityNotHigh() 130 | { 131 | $mail = new AssertableMessage( 132 | (new Email())->priority(Email::PRIORITY_LOWEST) 133 | ); 134 | 135 | $mail->assertPriorityNotHigh(); 136 | } 137 | 138 | public function testMailPriorityNotHighThrowsProperExpectationFailedException() 139 | { 140 | $mail = new AssertableMessage( 141 | (new Email())->priority(Email::PRIORITY_HIGH) 142 | ); 143 | 144 | $this->expectException(ExpectationFailedException::class); 145 | $this->expectExceptionMessage('The expected priority was [high].'); 146 | 147 | $mail->assertPriorityNotHigh(); 148 | } 149 | 150 | public function testMailPriorityNormal() 151 | { 152 | $mail = new AssertableMessage( 153 | (new Email())->priority(Email::PRIORITY_NORMAL) 154 | ); 155 | 156 | $mail->assertPriorityIsNormal(); 157 | } 158 | 159 | public function testMailPriorityNormalThrowsProperExpectationFailedException() 160 | { 161 | $mail = new AssertableMessage( 162 | (new Email())->priority(Email::PRIORITY_LOWEST) 163 | ); 164 | 165 | $this->expectException(ExpectationFailedException::class); 166 | $this->expectExceptionMessage('The expected priority was not [normal].'); 167 | 168 | $mail->assertPriorityIsNormal(); 169 | } 170 | 171 | public function testMailPriorityNotNormal() 172 | { 173 | $mail = new AssertableMessage( 174 | (new Email())->priority(Email::PRIORITY_LOWEST) 175 | ); 176 | 177 | $mail->assertPriorityNotNormal(); 178 | } 179 | 180 | public function testMailPriorityNotNormalThrowsProperExpectationFailedException() 181 | { 182 | $mail = new AssertableMessage( 183 | (new Email())->priority(Email::PRIORITY_NORMAL) 184 | ); 185 | 186 | $this->expectException(ExpectationFailedException::class); 187 | $this->expectExceptionMessage('The expected priority was [normal].'); 188 | 189 | $mail->assertPriorityNotNormal(); 190 | } 191 | 192 | public function testMailPriorityLow() 193 | { 194 | $mail = new AssertableMessage( 195 | (new Email())->priority(Email::PRIORITY_LOW) 196 | ); 197 | 198 | $mail->assertPriorityIsLow(); 199 | } 200 | 201 | public function testMailPriorityLowThrowsProperExpectationFailedException() 202 | { 203 | $mail = new AssertableMessage( 204 | (new Email())->priority(Email::PRIORITY_LOWEST) 205 | ); 206 | 207 | $this->expectException(ExpectationFailedException::class); 208 | $this->expectExceptionMessage('The expected priority was not [low].'); 209 | 210 | $mail->assertPriorityIsLow(); 211 | } 212 | 213 | public function testMailPriorityNotLow() 214 | { 215 | $mail = new AssertableMessage( 216 | (new Email())->priority(Email::PRIORITY_LOWEST) 217 | ); 218 | 219 | $mail->assertPriorityNotLow(); 220 | } 221 | 222 | public function testMailPriorityNotLowThrowsProperExpectationFailedException() 223 | { 224 | $mail = new AssertableMessage( 225 | (new Email())->priority(Email::PRIORITY_LOW) 226 | ); 227 | 228 | $this->expectException(ExpectationFailedException::class); 229 | $this->expectExceptionMessage('The expected priority was [low].'); 230 | 231 | $mail->assertPriorityNotLow(); 232 | } 233 | 234 | public function testMailPriorityLowest() 235 | { 236 | $mail = new AssertableMessage( 237 | (new Email())->priority(Email::PRIORITY_LOWEST) 238 | ); 239 | 240 | $mail->assertPriorityIsLowest(); 241 | } 242 | 243 | public function testMailPriorityLowestThrowsProperExpectationFailedException() 244 | { 245 | $mail = new AssertableMessage( 246 | (new Email())->priority(Email::PRIORITY_LOW) 247 | ); 248 | 249 | $this->expectException(ExpectationFailedException::class); 250 | $this->expectExceptionMessage('The expected priority was not [lowest].'); 251 | 252 | $mail->assertPriorityIsLowest(); 253 | } 254 | 255 | public function testMailPriorityNotLowest() 256 | { 257 | $mail = new AssertableMessage( 258 | (new Email())->priority(Email::PRIORITY_LOW) 259 | ); 260 | 261 | $mail->assertPriorityNotLowest(); 262 | } 263 | 264 | public function testMailPriorityNotLowestThrowsProperExpectationFailedException() 265 | { 266 | $mail = new AssertableMessage( 267 | (new Email())->priority(Email::PRIORITY_LOWEST) 268 | ); 269 | 270 | $this->expectException(ExpectationFailedException::class); 271 | $this->expectExceptionMessage('The expected priority was [lowest].'); 272 | 273 | $mail->assertPriorityNotLowest(); 274 | } 275 | } 276 | -------------------------------------------------------------------------------- /tests/Fluent/ReplyToAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->email; 15 | 16 | $mail = new AssertableMessage( 17 | (new Email())->replyTo($email) 18 | ); 19 | 20 | $mail->assertRepliesTo($email); 21 | } 22 | 23 | public function testMailRepliesToThrowsProperExpectationFailedException() 24 | { 25 | $email = $this->faker->unique()->email; 26 | 27 | $mail = new AssertableMessage( 28 | (new Email())->replyTo($this->faker->unique()->email) 29 | ); 30 | 31 | $this->expectException(ExpectationFailedException::class); 32 | $this->expectExceptionMessage("Mail does not reply to the expected address [{$email}]."); 33 | 34 | $mail->assertRepliesTo($email); 35 | } 36 | 37 | public function testMailRepliesToMultipleEmails() 38 | { 39 | $emails = [ 40 | $this->faker->email, 41 | $this->faker->email, 42 | ]; 43 | 44 | $mail = new AssertableMessage( 45 | (new Email())->replyTo(...$emails) 46 | ); 47 | 48 | $mail->assertRepliesTo($emails); 49 | } 50 | 51 | public function testMailNotRepliesToSingleEmail() 52 | { 53 | $email = $this->faker->unique()->email; 54 | 55 | $mail = new AssertableMessage( 56 | (new Email())->replyTo($this->faker->unique()->email) 57 | ); 58 | 59 | $mail->assertNotRepliesTo($email); 60 | } 61 | 62 | public function testMailNotRepliesToThrowsProperExpectationFailedException() 63 | { 64 | $email = $this->faker->email; 65 | 66 | $mail = new AssertableMessage( 67 | (new Email())->replyTo($email) 68 | ); 69 | 70 | $this->expectException(ExpectationFailedException::class); 71 | $this->expectExceptionMessage("Mail replied to the expected address [{$email}]."); 72 | 73 | $mail->assertNotRepliesTo($email); 74 | } 75 | 76 | public function testMailNotRepliesToMultipleEmails() 77 | { 78 | $emails = [ 79 | $this->faker->unique()->email, 80 | $this->faker->unique()->email, 81 | ]; 82 | 83 | $mail = new AssertableMessage( 84 | (new Email())->replyTo( 85 | $this->faker->unique()->email, 86 | $this->faker->unique()->email 87 | ) 88 | ); 89 | 90 | $mail->assertNotRepliesTo($emails); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /tests/Fluent/ReturnPathAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->email; 15 | 16 | $mail = new AssertableMessage( 17 | (new Email())->returnPath($email) 18 | ); 19 | 20 | $mail->assertReturnPath($email); 21 | } 22 | 23 | public function testMailReturnPathThrowsProperExpectationFailedException() 24 | { 25 | $email = $this->faker->unique()->email; 26 | 27 | $mail = new AssertableMessage( 28 | (new Email())->returnPath($this->faker->unique()->email) 29 | ); 30 | 31 | $this->expectException(ExpectationFailedException::class); 32 | $this->expectExceptionMessage("The expected return path was not [{$email}]."); 33 | 34 | $mail->assertReturnPath($email); 35 | } 36 | 37 | public function testMailNotReturnPathSingleEmail() 38 | { 39 | $email = $this->faker->unique()->email; 40 | 41 | $mail = new AssertableMessage( 42 | (new Email())->returnPath($this->faker->unique()->email) 43 | ); 44 | 45 | $mail->assertNotReturnPath($email); 46 | } 47 | 48 | public function testMailNotReturnPathThrowsProperExpectationFailedException() 49 | { 50 | $email = $this->faker->email; 51 | 52 | $mail = new AssertableMessage( 53 | (new Email())->returnPath($email) 54 | ); 55 | 56 | $this->expectException(ExpectationFailedException::class); 57 | $this->expectExceptionMessage("The expected return path was [{$email}]."); 58 | 59 | $mail->assertNotReturnPath($email); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tests/Fluent/SenderAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->email; 15 | 16 | $mail = new AssertableMessage( 17 | (new Email())->sender($email) 18 | ); 19 | 20 | $mail->assertSender($email); 21 | } 22 | 23 | public function testMailSenderThrowsProperExpectationFailedException() 24 | { 25 | $email = $this->faker->unique()->email; 26 | 27 | $mail = new AssertableMessage( 28 | (new Email())->sender($this->faker->unique()->email) 29 | ); 30 | 31 | $this->expectException(ExpectationFailedException::class); 32 | $this->expectExceptionMessage("Mail sender was not from the expected address [{$email}]."); 33 | 34 | $mail->assertSender($email); 35 | } 36 | 37 | public function testMailNotSenderSingleEmail() 38 | { 39 | $email = $this->faker->unique()->email; 40 | 41 | $mail = new AssertableMessage( 42 | (new Email())->sender($this->faker->unique()->email) 43 | ); 44 | 45 | $mail->assertNotSender($email); 46 | } 47 | 48 | public function testMailNotSenderThrowsProperExpectationFailedException() 49 | { 50 | $email = $this->faker->email; 51 | 52 | $mail = new AssertableMessage( 53 | (new Email())->sender($email) 54 | ); 55 | 56 | $this->expectException(ExpectationFailedException::class); 57 | $this->expectExceptionMessage("Mail sender was from the expected address [{$email}]."); 58 | 59 | $mail->assertNotSender($email); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tests/Fluent/SubjectAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->sentence; 15 | 16 | $mail = new AssertableMessage( 17 | (new Email())->subject($subject) 18 | ); 19 | 20 | $mail->assertSubject($subject); 21 | } 22 | 23 | public function testMailSubjectThrowsProperExpectationFailedException() 24 | { 25 | $subject = $this->faker->unique()->sentence; 26 | 27 | $mail = new AssertableMessage( 28 | (new Email())->subject($this->faker->unique()->sentence) 29 | ); 30 | 31 | $this->expectException(ExpectationFailedException::class); 32 | $this->expectExceptionMessage("The expected subject was not [{$subject}]."); 33 | 34 | $mail->assertSubject($subject); 35 | } 36 | 37 | public function testMailNotSubject() 38 | { 39 | $subject = $this->faker->unique()->sentence; 40 | 41 | $mail = new AssertableMessage( 42 | (new Email())->subject($this->faker->unique()->sentence) 43 | ); 44 | 45 | $mail->assertNotSubject($subject); 46 | } 47 | 48 | public function testMailNotSubjectThrowsProperExpectationFailedException() 49 | { 50 | $subject = $this->faker->sentence; 51 | 52 | $mail = new AssertableMessage( 53 | (new Email())->subject($subject) 54 | ); 55 | 56 | $this->expectException(ExpectationFailedException::class); 57 | $this->expectExceptionMessage("The expected subject was [{$subject}]."); 58 | 59 | $mail->assertNotSubject($subject); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tests/Fluent/ToAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->email; 15 | 16 | $mail = new AssertableMessage( 17 | (new Email())->to($email) 18 | ); 19 | 20 | $mail->assertSentTo($email); 21 | } 22 | 23 | public function testMailSentToThrowsProperExpectationFailedException() 24 | { 25 | $email = $this->faker->unique()->email; 26 | 27 | $mail = new AssertableMessage( 28 | (new Email())->to($this->faker->unique()->email) 29 | ); 30 | 31 | $this->expectException(ExpectationFailedException::class); 32 | $this->expectExceptionMessage("Mail was not sent to the expected address [{$email}]."); 33 | 34 | $mail->assertSentTo($email); 35 | } 36 | 37 | public function testMailSentToMultipleEmails() 38 | { 39 | $emails = [ 40 | $this->faker->email, 41 | $this->faker->email, 42 | ]; 43 | 44 | $mail = new AssertableMessage( 45 | (new Email())->to(...$emails) 46 | ); 47 | 48 | $mail->assertSentTo($emails); 49 | } 50 | 51 | public function testMailNotSentToSingleEmail() 52 | { 53 | $email = $this->faker->unique()->email; 54 | 55 | $mail = new AssertableMessage( 56 | (new Email())->to($this->faker->unique()->email) 57 | ); 58 | 59 | $mail->assertNotSentTo($email); 60 | } 61 | 62 | public function testMailNotSentToThrowsProperExpectationFailedException() 63 | { 64 | $email = $this->faker->unique()->email; 65 | 66 | $mail = new AssertableMessage( 67 | (new Email())->to($email) 68 | ); 69 | 70 | $this->expectException(ExpectationFailedException::class); 71 | $this->expectExceptionMessage("Mail was sent to the expected address [{$email}]."); 72 | 73 | $mail->assertNotSentTo($email); 74 | } 75 | 76 | public function testMailNotSentToMultipleEmails() 77 | { 78 | $emails = [ 79 | $this->faker->unique()->email, 80 | $this->faker->unique()->email, 81 | ]; 82 | 83 | $mail = new AssertableMessage( 84 | (new Email())->to( 85 | $this->faker->unique()->email, 86 | $this->faker->unique()->email 87 | ) 88 | ); 89 | 90 | $mail->assertNotSentTo($emails); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /tests/Fluent/UnstructuredHeaderAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->slug; 15 | 16 | $mail = new Email(); 17 | $mail->getHeaders()->addTextHeader($header, $this->faker->word); 18 | 19 | $mail = new AssertableMessage($mail); 20 | 21 | $mail->assertHasHeader($header); 22 | } 23 | 24 | public function testMailHasHeaderThrowsProperExpectationFailedException() 25 | { 26 | $header = $this->faker->unique()->slug; 27 | 28 | $mail = new Email(); 29 | $mail->getHeaders()->addTextHeader($this->faker->unique()->slug, $this->faker->word); 30 | 31 | $mail = new AssertableMessage($mail); 32 | 33 | $this->expectException(ExpectationFailedException::class); 34 | $this->expectExceptionMessage("The expected [{$header}] header did not exist."); 35 | 36 | $mail->assertHasHeader($header); 37 | } 38 | 39 | public function testMailMissingHeader() 40 | { 41 | $header = $this->faker->unique()->slug; 42 | 43 | $mail = new Email(); 44 | $mail->getHeaders()->addTextHeader($this->faker->unique()->slug, $this->faker->word); 45 | 46 | $mail = new AssertableMessage($mail); 47 | 48 | $mail->assertMissingHeader($header); 49 | } 50 | 51 | public function testMailMissingHeaderThrowsProperExpectationFailedException() 52 | { 53 | $header = $this->faker->slug; 54 | 55 | $mail = new Email(); 56 | $mail->getHeaders()->addTextHeader($header, $this->faker->word); 57 | 58 | $mail = new AssertableMessage($mail); 59 | 60 | $this->expectException(ExpectationFailedException::class); 61 | $this->expectExceptionMessage("The expected [{$header}] header did exist."); 62 | 63 | $mail->assertMissingHeader($header); 64 | } 65 | 66 | public function testMailHeaderIs() 67 | { 68 | $header = $this->faker->slug; 69 | $value = $this->faker->word; 70 | 71 | $mail = new Email(); 72 | $mail->getHeaders()->addTextHeader($header, $value); 73 | 74 | $mail = new AssertableMessage($mail); 75 | 76 | $mail->assertHeaderIs($header, $value); 77 | } 78 | 79 | public function testMailHeaderIsThrowsProperExpectationFailedException() 80 | { 81 | $header = $this->faker->slug; 82 | $value = $this->faker->unique()->word; 83 | 84 | $mail = new Email(); 85 | $mail->getHeaders()->addTextHeader($header, $this->faker->unique()->word); 86 | 87 | $mail = new AssertableMessage($mail); 88 | 89 | $this->expectException(ExpectationFailedException::class); 90 | $this->expectExceptionMessage("The expected [{$header}] was not set to [{$value}]."); 91 | 92 | $mail->assertHeaderIs($header, $value); 93 | } 94 | 95 | public function testMailHeaderIsNot() 96 | { 97 | $header = $this->faker->slug; 98 | $value = $this->faker->unique()->word; 99 | 100 | $mail = new Email(); 101 | $mail->getHeaders()->addTextHeader($header, $this->faker->unique()->word); 102 | 103 | $mail = new AssertableMessage($mail); 104 | 105 | $mail->assertHeaderIsNot($header, $value); 106 | } 107 | 108 | public function testMailHeaderIsNotThrowsProperExpectationFailedException() 109 | { 110 | $header = $this->faker->slug; 111 | $value = $this->faker->word; 112 | 113 | $mail = new Email(); 114 | $mail->getHeaders()->addTextHeader($header, $value); 115 | 116 | $mail = new AssertableMessage($mail); 117 | 118 | $this->expectException(ExpectationFailedException::class); 119 | $this->expectExceptionMessage("The expected [{$header}] was set to [{$value}]."); 120 | 121 | $mail->assertHeaderIsNot($header, $value); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /tests/FromAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->email; 20 | 21 | $mail = (new Email())->from($email); 22 | 23 | $this->assertMailSentFrom($email, $mail); 24 | } 25 | 26 | public function testMailSentFromSingleEmailViaAssertableMessage() 27 | { 28 | $email = $this->faker->email; 29 | 30 | $mail = new AssertableMessage( 31 | (new Email())->from($email) 32 | ); 33 | 34 | $this->assertMailSentFrom($email, $mail); 35 | } 36 | 37 | public function testMailSentFromThrowsProperExpectationFailedException() 38 | { 39 | $email = $this->faker->unique()->email; 40 | 41 | $mail = (new Email())->from($this->faker->unique()->email); 42 | 43 | $this->expectException(ExpectationFailedException::class); 44 | $this->expectExceptionMessage("Mail was not sent from the expected address [{$email}]."); 45 | 46 | $this->assertMailSentFrom($email, $mail); 47 | } 48 | 49 | public function testMailSentFromMultipleEmails() 50 | { 51 | $emails = [ 52 | $this->faker->email, 53 | $this->faker->email, 54 | ]; 55 | 56 | $mail = (new Email())->from(...$emails); 57 | 58 | $this->assertMailSentFrom($emails, $mail); 59 | } 60 | 61 | /* 62 | |-------------------------------------------------------------------------- 63 | | assertMailNotSentFrom 64 | |-------------------------------------------------------------------------- 65 | */ 66 | 67 | public function testMailNotSentFromSingleEmail() 68 | { 69 | $email = $this->faker->unique()->email; 70 | 71 | $mail = (new Email())->from($this->faker->unique()->email); 72 | 73 | $this->assertMailNotSentFrom($email, $mail); 74 | } 75 | 76 | public function testMailNotSentFromSingleEmailViaAssertableMessage() 77 | { 78 | $email = $this->faker->unique()->email; 79 | 80 | $mail = new AssertableMessage( 81 | (new Email())->from($this->faker->unique()->email) 82 | ); 83 | 84 | $this->assertMailNotSentFrom($email, $mail); 85 | } 86 | 87 | public function testMailNotSentFromThrowsProperExpectationFailedException() 88 | { 89 | $email = $this->faker->email; 90 | 91 | $mail = (new Email())->from($email); 92 | 93 | $this->expectException(ExpectationFailedException::class); 94 | $this->expectExceptionMessage("Mail was sent from the expected address [{$email}]."); 95 | 96 | $this->assertMailNotSentFrom($email, $mail); 97 | } 98 | 99 | public function testMailNotSentFromMultipleEmails() 100 | { 101 | $emails = [ 102 | $this->faker->unique()->email, 103 | $this->faker->unique()->email, 104 | ]; 105 | 106 | $mail = (new Email())->from( 107 | $this->faker->unique()->email, 108 | $this->faker->unique()->email 109 | ); 110 | 111 | $this->assertMailNotSentFrom($emails, $mail); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /tests/PriorityAssertionsTest.php: -------------------------------------------------------------------------------- 1 | priority($priority); 22 | 23 | $this->assertMailPriority($priority, $mail); 24 | } 25 | 26 | public function testMailPrioritySingleEmailViaAssertableMessage() 27 | { 28 | $priority = mt_rand(1, 5); 29 | 30 | $mail = new AssertableMessage( 31 | (new Email())->priority($priority) 32 | ); 33 | 34 | $this->assertMailPriority($priority, $mail); 35 | } 36 | 37 | public function testMailPriorityThrowsProperExpectationFailedException() 38 | { 39 | $priorities = collect(range(1, 5))->shuffle(); 40 | $actualPriority = $priorities->pop(); 41 | $expectedPriority = $priorities->random(); 42 | 43 | $mail = (new Email())->priority($actualPriority); 44 | 45 | $this->expectException(ExpectationFailedException::class); 46 | $this->expectExceptionMessage("The expected priority was not [{$expectedPriority}]."); 47 | 48 | $this->assertMailPriority($expectedPriority, $mail); 49 | } 50 | 51 | /* 52 | |-------------------------------------------------------------------------- 53 | | assertMailNotPriority 54 | |-------------------------------------------------------------------------- 55 | */ 56 | 57 | public function testMailNotPrioritySingleEmail() 58 | { 59 | $priorities = collect(range(1, 5))->shuffle(); 60 | $actualPriority = $priorities->pop(); 61 | $expectedPriority = $priorities->random(); 62 | 63 | $mail = (new Email())->priority($actualPriority); 64 | 65 | $this->assertMailNotPriority($expectedPriority, $mail); 66 | } 67 | 68 | public function testMailNotPrioritySingleEmailViaAssertableMessage() 69 | { 70 | $priorities = collect(range(1, 5))->shuffle(); 71 | $actualPriority = $priorities->pop(); 72 | $expectedPriority = $priorities->random(); 73 | 74 | $mail = new AssertableMessage( 75 | (new Email())->priority($actualPriority) 76 | ); 77 | 78 | $this->assertMailNotPriority($expectedPriority, $mail); 79 | } 80 | 81 | public function testMailNotPriorityThrowsProperExpectationFailedException() 82 | { 83 | $priority = mt_rand(1, 5); 84 | 85 | $mail = (new Email())->priority($priority); 86 | 87 | $this->expectException(ExpectationFailedException::class); 88 | $this->expectExceptionMessage("The expected priority was [{$priority}]."); 89 | 90 | $this->assertMailNotPriority($priority, $mail); 91 | } 92 | 93 | /* 94 | |-------------------------------------------------------------------------- 95 | | assertMailPriorityIsHighest 96 | |-------------------------------------------------------------------------- 97 | */ 98 | 99 | public function testMailPriorityHighest() 100 | { 101 | $mail = (new Email())->priority(Email::PRIORITY_HIGHEST); 102 | 103 | $this->assertMailPriorityIsHighest($mail); 104 | } 105 | 106 | public function testMailPriorityHighestViaAssertableMessage() 107 | { 108 | $mail = new AssertableMessage( 109 | (new Email())->priority(Email::PRIORITY_HIGHEST) 110 | ); 111 | 112 | $this->assertMailPriorityIsHighest($mail); 113 | } 114 | 115 | public function testMailPriorityHighestThrowsProperExpectationFailedException() 116 | { 117 | $mail = (new Email())->priority(Email::PRIORITY_LOWEST); 118 | 119 | $this->expectException(ExpectationFailedException::class); 120 | $this->expectExceptionMessage('The expected priority was not [highest].'); 121 | 122 | $this->assertMailPriorityIsHighest($mail); 123 | } 124 | 125 | /* 126 | |-------------------------------------------------------------------------- 127 | | assertMailPriorityNotHighest 128 | |-------------------------------------------------------------------------- 129 | */ 130 | 131 | public function testMailPriorityNotHighest() 132 | { 133 | $mail = (new Email())->priority(Email::PRIORITY_LOWEST); 134 | 135 | $this->assertMailPriorityNotHighest($mail); 136 | } 137 | 138 | public function testMailPriorityNotHighestViaAssertableMessage() 139 | { 140 | $mail = new AssertableMessage( 141 | (new Email())->priority(Email::PRIORITY_LOWEST) 142 | ); 143 | 144 | $this->assertMailPriorityNotHighest($mail); 145 | } 146 | 147 | public function testMailPriorityNotHighestThrowsProperExpectationFailedException() 148 | { 149 | $mail = (new Email())->priority(Email::PRIORITY_HIGHEST); 150 | 151 | $this->expectException(ExpectationFailedException::class); 152 | $this->expectExceptionMessage('The expected priority was [highest].'); 153 | 154 | $this->assertMailPriorityNotHighest($mail); 155 | } 156 | 157 | /* 158 | |-------------------------------------------------------------------------- 159 | | assertMailPriorityIsHigh 160 | |-------------------------------------------------------------------------- 161 | */ 162 | 163 | public function testMailPriorityHigh() 164 | { 165 | $mail = (new Email())->priority(Email::PRIORITY_HIGH); 166 | 167 | $this->assertMailPriorityIsHigh($mail); 168 | } 169 | 170 | public function testMailPriorityHighViaAssertableMessage() 171 | { 172 | $mail = new AssertableMessage( 173 | (new Email())->priority(Email::PRIORITY_HIGH) 174 | ); 175 | 176 | $this->assertMailPriorityIsHigh($mail); 177 | } 178 | 179 | public function testMailPriorityHighThrowsProperExpectationFailedException() 180 | { 181 | $mail = (new Email())->priority(Email::PRIORITY_LOWEST); 182 | 183 | $this->expectException(ExpectationFailedException::class); 184 | $this->expectExceptionMessage('The expected priority was not [high].'); 185 | 186 | $this->assertMailPriorityIsHigh($mail); 187 | } 188 | 189 | /* 190 | |-------------------------------------------------------------------------- 191 | | assertMailPriorityNotHigh 192 | |-------------------------------------------------------------------------- 193 | */ 194 | 195 | public function testMailPriorityNotHigh() 196 | { 197 | $mail = (new Email())->priority(Email::PRIORITY_LOWEST); 198 | 199 | $this->assertMailPriorityNotHigh($mail); 200 | } 201 | 202 | public function testMailPriorityNotHighViaAssertableMessage() 203 | { 204 | $mail = new AssertableMessage( 205 | (new Email())->priority(Email::PRIORITY_LOWEST) 206 | ); 207 | 208 | $this->assertMailPriorityNotHigh($mail); 209 | } 210 | 211 | public function testMailPriorityNotHighThrowsProperExpectationFailedException() 212 | { 213 | $mail = (new Email())->priority(Email::PRIORITY_HIGH); 214 | 215 | $this->expectException(ExpectationFailedException::class); 216 | $this->expectExceptionMessage('The expected priority was [high].'); 217 | 218 | $this->assertMailPriorityNotHigh($mail); 219 | } 220 | 221 | /* 222 | |-------------------------------------------------------------------------- 223 | | assertMailPriorityIsNormal 224 | |-------------------------------------------------------------------------- 225 | */ 226 | 227 | public function testMailPriorityNormal() 228 | { 229 | $mail = (new Email())->priority(Email::PRIORITY_NORMAL); 230 | 231 | $this->assertMailPriorityIsNormal($mail); 232 | } 233 | 234 | public function testMailPriorityNormalViaAssertableMessage() 235 | { 236 | $mail = new AssertableMessage( 237 | (new Email())->priority(Email::PRIORITY_NORMAL) 238 | ); 239 | 240 | $this->assertMailPriorityIsNormal($mail); 241 | } 242 | 243 | public function testMailPriorityNormalThrowsProperExpectationFailedException() 244 | { 245 | $mail = (new Email())->priority(Email::PRIORITY_LOWEST); 246 | 247 | $this->expectException(ExpectationFailedException::class); 248 | $this->expectExceptionMessage('The expected priority was not [normal].'); 249 | 250 | $this->assertMailPriorityIsNormal($mail); 251 | } 252 | 253 | /* 254 | |-------------------------------------------------------------------------- 255 | | assertMailPriorityNotNormal 256 | |-------------------------------------------------------------------------- 257 | */ 258 | 259 | public function testMailPriorityNotNormal() 260 | { 261 | $mail = (new Email())->priority(Email::PRIORITY_LOWEST); 262 | 263 | $this->assertMailPriorityNotNormal($mail); 264 | } 265 | 266 | public function testMailPriorityNotNormalViaAssertableMessage() 267 | { 268 | $mail = new AssertableMessage( 269 | (new Email())->priority(Email::PRIORITY_LOWEST) 270 | ); 271 | 272 | $this->assertMailPriorityNotNormal($mail); 273 | } 274 | 275 | public function testMailPriorityNotNormalThrowsProperExpectationFailedException() 276 | { 277 | $mail = (new Email())->priority(Email::PRIORITY_NORMAL); 278 | 279 | $this->expectException(ExpectationFailedException::class); 280 | $this->expectExceptionMessage('The expected priority was [normal].'); 281 | 282 | $this->assertMailPriorityNotNormal($mail); 283 | } 284 | 285 | /* 286 | |-------------------------------------------------------------------------- 287 | | assertMailPriorityIsLow 288 | |-------------------------------------------------------------------------- 289 | */ 290 | 291 | public function testMailPriorityLow() 292 | { 293 | $mail = (new Email())->priority(Email::PRIORITY_LOW); 294 | 295 | $this->assertMailPriorityIsLow($mail); 296 | } 297 | 298 | public function testMailPriorityLowViaAssertableMessage() 299 | { 300 | $mail = new AssertableMessage( 301 | (new Email())->priority(Email::PRIORITY_LOW) 302 | ); 303 | 304 | $this->assertMailPriorityIsLow($mail); 305 | } 306 | 307 | public function testMailPriorityLowThrowsProperExpectationFailedException() 308 | { 309 | $mail = (new Email())->priority(Email::PRIORITY_LOWEST); 310 | 311 | $this->expectException(ExpectationFailedException::class); 312 | $this->expectExceptionMessage('The expected priority was not [low].'); 313 | 314 | $this->assertMailPriorityIsLow($mail); 315 | } 316 | 317 | /* 318 | |-------------------------------------------------------------------------- 319 | | assertMailPriorityNotLow 320 | |-------------------------------------------------------------------------- 321 | */ 322 | 323 | public function testMailPriorityNotLow() 324 | { 325 | $mail = (new Email())->priority(Email::PRIORITY_LOWEST); 326 | 327 | $this->assertMailPriorityNotLow($mail); 328 | } 329 | 330 | public function testMailPriorityNotLowViaAssertableMessage() 331 | { 332 | $mail = new AssertableMessage( 333 | (new Email())->priority(Email::PRIORITY_LOWEST) 334 | ); 335 | 336 | $this->assertMailPriorityNotLow($mail); 337 | } 338 | 339 | public function testMailPriorityNotLowThrowsProperExpectationFailedException() 340 | { 341 | $mail = (new Email())->priority(Email::PRIORITY_LOW); 342 | 343 | $this->expectException(ExpectationFailedException::class); 344 | $this->expectExceptionMessage('The expected priority was [low].'); 345 | 346 | $this->assertMailPriorityNotLow($mail); 347 | } 348 | 349 | /* 350 | |-------------------------------------------------------------------------- 351 | | assertMailPriorityIsLowest 352 | |-------------------------------------------------------------------------- 353 | */ 354 | 355 | public function testMailPriorityLowest() 356 | { 357 | $mail = (new Email())->priority(Email::PRIORITY_LOWEST); 358 | 359 | $this->assertMailPriorityIsLowest($mail); 360 | } 361 | 362 | public function testMailPriorityLowestViaAssertableMessage() 363 | { 364 | $mail = new AssertableMessage( 365 | (new Email())->priority(Email::PRIORITY_LOWEST) 366 | ); 367 | 368 | $this->assertMailPriorityIsLowest($mail); 369 | } 370 | 371 | public function testMailPriorityLowestThrowsProperExpectationFailedException() 372 | { 373 | $mail = (new Email())->priority(Email::PRIORITY_LOW); 374 | 375 | $this->expectException(ExpectationFailedException::class); 376 | $this->expectExceptionMessage('The expected priority was not [lowest].'); 377 | 378 | $this->assertMailPriorityIsLowest($mail); 379 | } 380 | 381 | /* 382 | |-------------------------------------------------------------------------- 383 | | assertMailPriorityNotLowest 384 | |-------------------------------------------------------------------------- 385 | */ 386 | 387 | public function testMailPriorityNotLowest() 388 | { 389 | $mail = (new Email())->priority(Email::PRIORITY_LOW); 390 | 391 | $this->assertMailPriorityNotLowest($mail); 392 | } 393 | 394 | public function testMailPriorityNotLowestViaAssertableMessage() 395 | { 396 | $mail = new AssertableMessage( 397 | (new Email())->priority(Email::PRIORITY_LOW) 398 | ); 399 | 400 | $this->assertMailPriorityNotLowest($mail); 401 | } 402 | 403 | public function testMailPriorityNotLowestThrowsProperExpectationFailedException() 404 | { 405 | $mail = (new Email())->priority(Email::PRIORITY_LOWEST); 406 | 407 | $this->expectException(ExpectationFailedException::class); 408 | $this->expectExceptionMessage('The expected priority was [lowest].'); 409 | 410 | $this->assertMailPriorityNotLowest($mail); 411 | } 412 | } 413 | -------------------------------------------------------------------------------- /tests/ReplyToAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->email; 20 | 21 | $mail = (new Email())->replyTo($email); 22 | 23 | $this->assertMailRepliesTo($email, $mail); 24 | } 25 | 26 | public function testMailRepliesToSingleEmailViaAssertableMessage() 27 | { 28 | $email = $this->faker->email; 29 | 30 | $mail = new AssertableMessage( 31 | (new Email())->replyTo($email) 32 | ); 33 | 34 | $this->assertMailRepliesTo($email, $mail); 35 | } 36 | 37 | public function testMailRepliesToThrowsProperExpectationFailedException() 38 | { 39 | $email = $this->faker->unique()->email; 40 | 41 | $mail = (new Email())->replyTo($this->faker->unique()->email); 42 | 43 | $this->expectException(ExpectationFailedException::class); 44 | $this->expectExceptionMessage("Mail does not reply to the expected address [{$email}]."); 45 | 46 | $this->assertMailRepliesTo($email, $mail); 47 | } 48 | 49 | public function testMailRepliesToMultipleEmails() 50 | { 51 | $emails = [ 52 | $this->faker->email, 53 | $this->faker->email, 54 | ]; 55 | 56 | $mail = (new Email())->replyTo(...$emails); 57 | 58 | $this->assertMailRepliesTo($emails, $mail); 59 | } 60 | 61 | /* 62 | |-------------------------------------------------------------------------- 63 | | assertMailNotRepliesTo 64 | |-------------------------------------------------------------------------- 65 | */ 66 | 67 | public function testMailNotRepliesToSingleEmail() 68 | { 69 | $email = $this->faker->unique()->email; 70 | 71 | $mail = (new Email())->replyTo($this->faker->unique()->email); 72 | 73 | $this->assertMailNotRepliesTo($email, $mail); 74 | } 75 | 76 | public function testMailNotRepliesToSingleEmailViaAssertableMessage() 77 | { 78 | $email = $this->faker->unique()->email; 79 | 80 | $mail = new AssertableMessage( 81 | (new Email())->replyTo($this->faker->unique()->email) 82 | ); 83 | 84 | $this->assertMailNotRepliesTo($email, $mail); 85 | } 86 | 87 | public function testMailNotRepliesToThrowsProperExpectationFailedException() 88 | { 89 | $email = $this->faker->email; 90 | 91 | $mail = (new Email())->replyTo($email); 92 | 93 | $this->expectException(ExpectationFailedException::class); 94 | $this->expectExceptionMessage("Mail replied to the expected address [{$email}]."); 95 | 96 | $this->assertMailNotRepliesTo($email, $mail); 97 | } 98 | 99 | public function testMailNotRepliesToMultipleEmails() 100 | { 101 | $emails = [ 102 | $this->faker->unique()->email, 103 | $this->faker->unique()->email, 104 | ]; 105 | 106 | $mail = (new Email())->replyTo( 107 | $this->faker->unique()->email, 108 | $this->faker->unique()->email 109 | ); 110 | 111 | $this->assertMailNotRepliesTo($emails, $mail); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /tests/ReturnPathAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->email; 20 | 21 | $mail = (new Email())->returnPath($email); 22 | 23 | $this->assertMailReturnPath($email, $mail); 24 | } 25 | 26 | public function testMailReturnPathSingleEmailViaAssertableMessage() 27 | { 28 | $email = $this->faker->email; 29 | 30 | $mail = new AssertableMessage( 31 | (new Email())->returnPath($email) 32 | ); 33 | 34 | $this->assertMailReturnPath($email, $mail); 35 | } 36 | 37 | public function testMailReturnPathThrowsProperExpectationFailedException() 38 | { 39 | $email = $this->faker->unique()->email; 40 | 41 | $mail = (new Email())->returnPath($this->faker->unique()->email); 42 | 43 | $this->expectException(ExpectationFailedException::class); 44 | $this->expectExceptionMessage("The expected return path was not [{$email}]."); 45 | 46 | $this->assertMailReturnPath($email, $mail); 47 | } 48 | 49 | /* 50 | |-------------------------------------------------------------------------- 51 | | assertMailNotReturnPath 52 | |-------------------------------------------------------------------------- 53 | */ 54 | 55 | public function testMailNotReturnPathSingleEmail() 56 | { 57 | $email = $this->faker->unique()->email; 58 | 59 | $mail = (new Email())->returnPath($this->faker->unique()->email); 60 | 61 | $this->assertMailNotReturnPath($email, $mail); 62 | } 63 | 64 | public function testMailNotReturnPathSingleEmailViaAssertableMessage() 65 | { 66 | $email = $this->faker->unique()->email; 67 | 68 | $mail = new AssertableMessage( 69 | (new Email())->returnPath($this->faker->unique()->email) 70 | ); 71 | 72 | $this->assertMailNotReturnPath($email, $mail); 73 | } 74 | 75 | public function testMailNotReturnPathThrowsProperExpectationFailedException() 76 | { 77 | $email = $this->faker->email; 78 | 79 | $mail = (new Email())->returnPath($email); 80 | 81 | $this->expectException(ExpectationFailedException::class); 82 | $this->expectExceptionMessage("The expected return path was [{$email}]."); 83 | 84 | $this->assertMailNotReturnPath($email, $mail); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /tests/SenderAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->email; 20 | 21 | $mail = (new Email())->sender($email); 22 | 23 | $this->assertMailSender($email, $mail); 24 | } 25 | 26 | public function testMailSenderSingleEmailViaAssertableMessage() 27 | { 28 | $email = $this->faker->email; 29 | 30 | $mail = new AssertableMessage( 31 | (new Email())->sender($email) 32 | ); 33 | 34 | $this->assertMailSender($email, $mail); 35 | } 36 | 37 | public function testMailSenderThrowsProperExpectationFailedException() 38 | { 39 | $email = $this->faker->unique()->email; 40 | 41 | $mail = (new Email())->sender($this->faker->unique()->email); 42 | 43 | $this->expectException(ExpectationFailedException::class); 44 | $this->expectExceptionMessage("Mail sender was not from the expected address [{$email}]."); 45 | 46 | $this->assertMailSender($email, $mail); 47 | } 48 | 49 | /* 50 | |-------------------------------------------------------------------------- 51 | | assertMailNotSender 52 | |-------------------------------------------------------------------------- 53 | */ 54 | 55 | public function testMailNotSenderSingleEmail() 56 | { 57 | $email = $this->faker->unique()->email; 58 | 59 | $mail = (new Email())->sender($this->faker->unique()->email); 60 | 61 | $this->assertMailNotSender($email, $mail); 62 | } 63 | 64 | public function testMailNotSenderSingleEmailViaAssertableMessage() 65 | { 66 | $email = $this->faker->unique()->email; 67 | 68 | $mail = new AssertableMessage( 69 | (new Email())->sender($this->faker->unique()->email) 70 | ); 71 | 72 | $this->assertMailNotSender($email, $mail); 73 | } 74 | 75 | public function testMailNotSenderThrowsProperExpectationFailedException() 76 | { 77 | $email = $this->faker->email; 78 | 79 | $mail = (new Email())->sender($email); 80 | 81 | $this->expectException(ExpectationFailedException::class); 82 | $this->expectExceptionMessage("Mail sender was from the expected address [{$email}]."); 83 | 84 | $this->assertMailNotSender($email, $mail); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /tests/SubjectAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->sentence; 20 | 21 | $mail = (new Email())->subject($subject); 22 | 23 | $this->assertMailSubject($subject, $mail); 24 | } 25 | 26 | public function testMailSubjectViaAssertableMessage() 27 | { 28 | $subject = $this->faker->sentence; 29 | 30 | $mail = new AssertableMessage( 31 | (new Email())->subject($subject) 32 | ); 33 | 34 | $this->assertMailSubject($subject, $mail); 35 | } 36 | 37 | public function testMailSubjectThrowsProperExpectationFailedException() 38 | { 39 | $subject = $this->faker->unique()->sentence; 40 | 41 | $mail = (new Email())->subject($this->faker->unique()->sentence); 42 | 43 | $this->expectException(ExpectationFailedException::class); 44 | $this->expectExceptionMessage("The expected subject was not [{$subject}]."); 45 | 46 | $this->assertMailSubject($subject, $mail); 47 | } 48 | 49 | /* 50 | |-------------------------------------------------------------------------- 51 | | assertMailNotSubject 52 | |-------------------------------------------------------------------------- 53 | */ 54 | 55 | public function testMailNotSubject() 56 | { 57 | $subject = $this->faker->unique()->sentence; 58 | 59 | $mail = (new Email())->subject($this->faker->unique()->sentence); 60 | 61 | $this->assertMailNotSubject($subject, $mail); 62 | } 63 | 64 | public function testMailNotSubjectViaAssertableMessage() 65 | { 66 | $subject = $this->faker->unique()->sentence; 67 | 68 | $mail = new AssertableMessage( 69 | (new Email())->subject($this->faker->unique()->sentence) 70 | ); 71 | 72 | $this->assertMailNotSubject($subject, $mail); 73 | } 74 | 75 | public function testMailNotSubjectThrowsProperExpectationFailedException() 76 | { 77 | $subject = $this->faker->sentence; 78 | 79 | $mail = (new Email())->subject($subject); 80 | 81 | $this->expectException(ExpectationFailedException::class); 82 | $this->expectExceptionMessage("The expected subject was [{$subject}]."); 83 | 84 | $this->assertMailNotSubject($subject, $mail); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | faker->email; 20 | 21 | $mail = (new Email())->to($email); 22 | 23 | $this->assertMailSentTo($email, $mail); 24 | } 25 | 26 | public function testMailSentToSingleEmailViaAssertableMessage() 27 | { 28 | $email = $this->faker->email; 29 | 30 | $mail = new AssertableMessage( 31 | (new Email())->to($email) 32 | ); 33 | 34 | $this->assertMailSentTo($email, $mail); 35 | } 36 | 37 | public function testMailSentToThrowsProperExpectationFailedException() 38 | { 39 | $email = $this->faker->unique()->email; 40 | 41 | $mail = (new Email())->to($this->faker->unique()->email); 42 | 43 | $this->expectException(ExpectationFailedException::class); 44 | $this->expectExceptionMessage("Mail was not sent to the expected address [{$email}]."); 45 | 46 | $this->assertMailSentTo($email, $mail); 47 | } 48 | 49 | public function testMailSentToMultipleEmails() 50 | { 51 | $emails = [ 52 | $this->faker->email, 53 | $this->faker->email, 54 | ]; 55 | 56 | $mail = (new Email())->to(...$emails); 57 | 58 | $this->assertMailSentTo($emails, $mail); 59 | } 60 | 61 | /* 62 | |-------------------------------------------------------------------------- 63 | | assertMailNotSentTo 64 | |-------------------------------------------------------------------------- 65 | */ 66 | 67 | public function testMailNotSentToSingleEmail() 68 | { 69 | $email = $this->faker->unique()->email; 70 | 71 | $mail = (new Email())->to($this->faker->unique()->email); 72 | 73 | $this->assertMailNotSentTo($email, $mail); 74 | } 75 | 76 | public function testMailNotSentToSingleEmailViaAssertableMessage() 77 | { 78 | $email = $this->faker->unique()->email; 79 | 80 | $mail = new AssertableMessage( 81 | (new Email())->to($this->faker->unique()->email) 82 | ); 83 | 84 | $this->assertMailNotSentTo($email, $mail); 85 | } 86 | 87 | public function testMailNotSentToThrowsProperExpectationFailedException() 88 | { 89 | $email = $this->faker->unique()->email; 90 | 91 | $mail = (new Email())->to($email); 92 | 93 | $this->expectException(ExpectationFailedException::class); 94 | $this->expectExceptionMessage("Mail was sent to the expected address [{$email}]."); 95 | 96 | $this->assertMailNotSentTo($email, $mail); 97 | } 98 | 99 | public function testMailNotSentToMultipleEmails() 100 | { 101 | $emails = [ 102 | $this->faker->unique()->email, 103 | $this->faker->unique()->email, 104 | ]; 105 | 106 | $mail = (new Email())->to( 107 | $this->faker->unique()->email, 108 | $this->faker->unique()->email 109 | ); 110 | 111 | $this->assertMailNotSentTo($emails, $mail); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /tests/UnstructuredHeaderAssertionsTest.php: -------------------------------------------------------------------------------- 1 | faker->slug; 20 | 21 | $mail = new Email(); 22 | $mail->getHeaders()->addTextHeader($header, $this->faker->word); 23 | 24 | $this->assertMailHasHeader($header, $mail); 25 | } 26 | 27 | public function testMailHasHeaderViaAssertableMessage() 28 | { 29 | $header = $this->faker->slug; 30 | 31 | $mail = new Email(); 32 | $mail->getHeaders()->addTextHeader($header, $this->faker->word); 33 | $mail = new AssertableMessage($mail); 34 | 35 | $this->assertMailHasHeader($header, $mail); 36 | } 37 | 38 | public function testMailHasHeaderThrowsProperExpectationFailedException() 39 | { 40 | $header = $this->faker->unique()->slug; 41 | 42 | $mail = new Email(); 43 | $mail->getHeaders()->addTextHeader($this->faker->unique()->slug, $this->faker->word); 44 | 45 | $this->expectException(ExpectationFailedException::class); 46 | $this->expectExceptionMessage("The expected [{$header}] header did not exist."); 47 | 48 | $this->assertMailHasHeader($header, $mail); 49 | } 50 | 51 | /* 52 | |-------------------------------------------------------------------------- 53 | | assertMailMissingHeader 54 | |-------------------------------------------------------------------------- 55 | */ 56 | 57 | public function testMailMissingHeader() 58 | { 59 | $header = $this->faker->unique()->slug; 60 | 61 | $mail = new Email(); 62 | $mail->getHeaders()->addTextHeader($this->faker->unique()->slug, $this->faker->word); 63 | 64 | $this->assertMailMissingHeader($header, $mail); 65 | } 66 | 67 | public function testMailMissingHeaderViaAssertableMessage() 68 | { 69 | $header = $this->faker->unique()->slug; 70 | 71 | $mail = new Email(); 72 | $mail->getHeaders()->addTextHeader($this->faker->unique()->slug, $this->faker->word); 73 | $mail = new AssertableMessage($mail); 74 | 75 | $this->assertMailMissingHeader($header, $mail); 76 | } 77 | 78 | public function testMailMissingHeaderThrowsProperExpectationFailedException() 79 | { 80 | $header = $this->faker->slug; 81 | 82 | $mail = new Email(); 83 | $mail->getHeaders()->addTextHeader($header, $this->faker->word); 84 | 85 | $this->expectException(ExpectationFailedException::class); 86 | $this->expectExceptionMessage("The expected [{$header}] header did exist."); 87 | 88 | $this->assertMailMissingHeader($header, $mail); 89 | } 90 | 91 | /* 92 | |-------------------------------------------------------------------------- 93 | | assertMailHeaderIs 94 | |-------------------------------------------------------------------------- 95 | */ 96 | 97 | public function testMailHeaderIs() 98 | { 99 | $header = $this->faker->slug; 100 | $value = $this->faker->word; 101 | 102 | $mail = new Email(); 103 | $mail->getHeaders()->addTextHeader($header, $value); 104 | 105 | $this->assertMailHeaderIs($header, $value, $mail); 106 | } 107 | 108 | public function testMailHeaderIsViaAssertableMessage() 109 | { 110 | $header = $this->faker->slug; 111 | $value = $this->faker->word; 112 | 113 | $mail = new Email(); 114 | $mail->getHeaders()->addTextHeader($header, $value); 115 | $mail = new AssertableMessage($mail); 116 | 117 | $this->assertMailHeaderIs($header, $value, $mail); 118 | } 119 | 120 | public function testMailHeaderIsThrowsProperExpectationFailedException() 121 | { 122 | $header = $this->faker->slug; 123 | $value = $this->faker->unique()->word; 124 | 125 | $mail = new Email(); 126 | $mail->getHeaders()->addTextHeader($header, $this->faker->unique()->word); 127 | 128 | $this->expectException(ExpectationFailedException::class); 129 | $this->expectExceptionMessage("The expected [{$header}] was not set to [{$value}]."); 130 | 131 | $this->assertMailHeaderIs($header, $value, $mail); 132 | } 133 | 134 | /* 135 | |-------------------------------------------------------------------------- 136 | | assertMailHeaderIsNot 137 | |-------------------------------------------------------------------------- 138 | */ 139 | 140 | public function testMailHeaderIsNot() 141 | { 142 | $header = $this->faker->slug; 143 | $value = $this->faker->unique()->word; 144 | 145 | $mail = new Email(); 146 | $mail->getHeaders()->addTextHeader($header, $this->faker->unique()->word); 147 | 148 | $this->assertMailHeaderIsNot($header, $value, $mail); 149 | } 150 | 151 | public function testMailHeaderIsNotViaAssertableMessage() 152 | { 153 | $header = $this->faker->slug; 154 | $value = $this->faker->unique()->word; 155 | 156 | $mail = new Email(); 157 | $mail->getHeaders()->addTextHeader($header, $this->faker->unique()->word); 158 | $mail = new AssertableMessage($mail); 159 | 160 | $this->assertMailHeaderIsNot($header, $value, $mail); 161 | } 162 | 163 | public function testMailHeaderIsNotThrowsProperExpectationFailedException() 164 | { 165 | $header = $this->faker->slug; 166 | $value = $this->faker->word; 167 | 168 | $mail = new Email(); 169 | $mail->getHeaders()->addTextHeader($header, $value); 170 | 171 | $this->expectException(ExpectationFailedException::class); 172 | $this->expectExceptionMessage("The expected [{$header}] was set to [{$value}]."); 173 | 174 | $this->assertMailHeaderIsNot($header, $value, $mail); 175 | } 176 | } 177 | --------------------------------------------------------------------------------