From 1b4dc96a2cbf50222a4c4455660ee8d2858fa6d2 Mon Sep 17 00:00:00 2001 From: Shift Date: Mon, 23 Feb 2026 21:19:16 +0000 Subject: [PATCH 1/6] Bump dependencies for Laravel 13 --- composer.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 44a1f50..f35686e 100644 --- a/composer.json +++ b/composer.json @@ -17,19 +17,19 @@ ], "require": { "php": "^8.0", - "illuminate/container": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", - "illuminate/database": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", - "illuminate/log": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", - "illuminate/routing": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", - "illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", + "illuminate/container": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0", + "illuminate/database": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0", + "illuminate/log": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0", + "illuminate/routing": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0", + "illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0", "willdurand/email-reply-parser": "^2.8", - "zbateson/mail-mime-parser": "^1.1|^2.4|^3.0" + "zbateson/mail-mime-parser": "^1.1|^2.4|^3.0|^4.0" }, "require-dev": { "laminas/laminas-mail": "^2.13", "mockery/mockery": "^1.2", - "orchestra/testbench": "^4.0|^5.0|^7.0|^8.0|^9.0|^10.0", - "phpunit/phpunit": "^7.0|^8.0|^9.3|^10.5|^11.5.3" + "orchestra/testbench": "^4.0|^5.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "phpunit/phpunit": "^7.0|^8.0|^9.3|^10.5|^11.5.3|^12.5.12" }, "autoload": { "psr-4": { From 93df6bc57c4923d6606fe46c33d00eb298565021 Mon Sep 17 00:00:00 2001 From: Shift Date: Mon, 23 Feb 2026 21:19:16 +0000 Subject: [PATCH 2/6] Update GitHub Actions for Laravel 13 --- .github/workflows/run-tests.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 2680a49..2b1bca7 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,8 +13,8 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: [8.0, 8.1, 8.2] - laravel: ['8.*', '9.*', '10.*', '11.*', '12.*'] + php: ['8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] + laravel: ['8.*', '9.*', '10.*', '11.*', '12.*', '13.*'] stability: [prefer-stable] exclude: - php: 8.0 @@ -29,6 +29,12 @@ jobs: php: 8.0 - laravel: 12.* php: 8.1 + - laravel: 13.* + php: '8.0' + - laravel: 13.* + php: '8.1' + - laravel: 13.* + php: '8.2' include: - laravel: 10.* testbench: 8.* @@ -40,6 +46,8 @@ jobs: testbench: 9.* - laravel: 12.* testbench: 10.* + - laravel: 13.* + testbench: 11.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} From 63ea4f48a1ece892796def54bcb352443375c14d Mon Sep 17 00:00:00 2001 From: Diana Scharf Date: Fri, 20 Mar 2026 15:11:05 +0100 Subject: [PATCH 3/6] Clean up CI matrix: drop EOL Laravel 8/9, fix YAML quoting, bump checkout to v4 --- .github/workflows/run-tests.yml | 54 ++++++++++++++------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 2b1bca7..e1b6ddf 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,47 +13,39 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: ['8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] - laravel: ['8.*', '9.*', '10.*', '11.*', '12.*', '13.*'] + php: ['8.1', '8.2', '8.3', '8.4', '8.5'] + laravel: ['10.*', '11.*', '12.*', '13.*'] stability: [prefer-stable] exclude: - - php: 8.0 - laravel: 10.* - - php: 8.2 - laravel: 8.* - - laravel: 11.* - php: 8.0 - - laravel: 11.* - php: 8.1 - - laravel: 12.* - php: 8.0 - - laravel: 12.* - php: 8.1 - - laravel: 13.* - php: '8.0' - - laravel: 13.* + - laravel: '10.*' + php: '8.4' + - laravel: '10.*' + php: '8.5' + - laravel: '11.*' php: '8.1' - - laravel: 13.* + - laravel: '11.*' + php: '8.5' + - laravel: '12.*' + php: '8.1' + - laravel: '13.*' + php: '8.1' + - laravel: '13.*' php: '8.2' include: - - laravel: 10.* - testbench: 8.* - - laravel: 9.* - testbench: 7.* - - laravel: 8.* - testbench: 6.23 - - laravel: 11.* - testbench: 9.* - - laravel: 12.* - testbench: 10.* - - laravel: 13.* - testbench: 11.* + - laravel: '10.*' + testbench: '8.*' + - laravel: '11.*' + testbench: '9.*' + - laravel: '12.*' + testbench: '10.*' + - laravel: '13.*' + testbench: '11.*' name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 From fe99b8bae7ff9c856c764290f2c1f95d4f13ffff Mon Sep 17 00:00:00 2001 From: Diana Scharf Date: Fri, 20 Mar 2026 15:19:39 +0100 Subject: [PATCH 4/6] Drop Laravel 6-9 support, clean up composer.json for L10+ minimum --- composer.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index f35686e..d3fe760 100644 --- a/composer.json +++ b/composer.json @@ -16,20 +16,20 @@ } ], "require": { - "php": "^8.0", - "illuminate/container": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0", - "illuminate/database": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0", - "illuminate/log": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0", - "illuminate/routing": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0", - "illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0", + "php": "^8.1", + "illuminate/container": "^10.0|^11.0|^12.0|^13.0", + "illuminate/database": "^10.0|^11.0|^12.0|^13.0", + "illuminate/log": "^10.0|^11.0|^12.0|^13.0", + "illuminate/routing": "^10.0|^11.0|^12.0|^13.0", + "illuminate/support": "^10.0|^11.0|^12.0|^13.0", "willdurand/email-reply-parser": "^2.8", - "zbateson/mail-mime-parser": "^1.1|^2.4|^3.0|^4.0" + "zbateson/mail-mime-parser": "^2.4|^3.0|^4.0" }, "require-dev": { "laminas/laminas-mail": "^2.13", "mockery/mockery": "^1.2", - "orchestra/testbench": "^4.0|^5.0|^7.0|^8.0|^9.0|^10.0|^11.0", - "phpunit/phpunit": "^7.0|^8.0|^9.3|^10.5|^11.5.3|^12.5.12" + "orchestra/testbench": "^8.0|^9.0|^10.0|^11.0", + "phpunit/phpunit": "^10.5|^11.0|^12.0" }, "autoload": { "psr-4": { From 36aa7c70ce111c864187b4a68bb48a6e6316e1ae Mon Sep 17 00:00:00 2001 From: Diana Scharf Date: Fri, 20 Mar 2026 15:26:19 +0100 Subject: [PATCH 5/6] Migrate test annotations from @test/@dataProvider docblocks to PHPUnit attributes --- tests/Console/CleanEmailsTest.php | 5 +-- tests/Controllers/MailgunTest.php | 5 +-- tests/Controllers/PostmarkTest.php | 3 +- tests/Drivers/LogTest.php | 3 +- tests/InboundEmailTest.php | 21 +++++++------ tests/MailboxRouteCollectionTest.php | 3 +- tests/MailboxRouteTest.php | 47 ++++++++++------------------ 7 files changed, 40 insertions(+), 47 deletions(-) diff --git a/tests/Console/CleanEmailsTest.php b/tests/Console/CleanEmailsTest.php index 5f18272..4c994da 100644 --- a/tests/Console/CleanEmailsTest.php +++ b/tests/Console/CleanEmailsTest.php @@ -8,6 +8,7 @@ use Carbon\Carbon; use Illuminate\Support\Collection; use Illuminate\Support\Str; +use PHPUnit\Framework\Attributes\Test; class CleanEmailsTest extends TestCase { @@ -20,7 +21,7 @@ public function setUp(): void $this->app['config']->set('mailbox.store_incoming_emails_for_days', 31); } - /** @test */ + #[Test] public function it_can_clean_the_statistics() { Collection::times(200)->each(function (int $index) { @@ -41,7 +42,7 @@ public function it_can_clean_the_statistics() $this->assertCount(0, InboundEmail::where('created_at', '<', $cutOffDate)->get()); } - /** @test */ + #[Test] public function it_errors_if_max_age_inf() { $this->app['config']->set('mailbox.store_incoming_emails_for_days', INF); diff --git a/tests/Controllers/MailgunTest.php b/tests/Controllers/MailgunTest.php index af10733..0571b79 100644 --- a/tests/Controllers/MailgunTest.php +++ b/tests/Controllers/MailgunTest.php @@ -3,6 +3,7 @@ namespace BeyondCode\Mailbox\Tests\Controllers; use BeyondCode\Mailbox\Tests\TestCase; +use PHPUnit\Framework\Attributes\Test; class MailgunTest extends TestCase { @@ -13,7 +14,7 @@ protected function getEnvironmentSetUp($app) $app['config']['mailbox.driver'] = 'mailgun'; } - /** @test */ + #[Test] public function it_verifies_mailgun_signatures() { $this->post('/laravel-mailbox/mailgun/mime', [ @@ -38,7 +39,7 @@ public function it_verifies_mailgun_signatures() ])->assertStatus(200); } - /** @test */ + #[Test] public function it_verifies_fresh_timestamps() { $timestamp = now()->subMinutes(5)->timestamp; diff --git a/tests/Controllers/PostmarkTest.php b/tests/Controllers/PostmarkTest.php index 2e7d4f8..a0fa3fd 100644 --- a/tests/Controllers/PostmarkTest.php +++ b/tests/Controllers/PostmarkTest.php @@ -3,6 +3,7 @@ namespace BeyondCode\Mailbox\Tests\Controllers; use BeyondCode\Mailbox\Tests\TestCase; +use PHPUnit\Framework\Attributes\Test; class PostmarkTest extends TestCase { @@ -13,7 +14,7 @@ protected function getEnvironmentSetUp($app) $app['config']['mailbox.driver'] = 'postmark'; } - /** @test */ + #[Test] public function it_expects_to_receive_raw_email_field() { $this->withoutMiddleware(); diff --git a/tests/Drivers/LogTest.php b/tests/Drivers/LogTest.php index 4cdb5a2..b39f954 100644 --- a/tests/Drivers/LogTest.php +++ b/tests/Drivers/LogTest.php @@ -7,6 +7,7 @@ use BeyondCode\Mailbox\Tests\TestCase; use Illuminate\Mail\Mailable; use Illuminate\Support\Facades\Mail; +use PHPUnit\Framework\Attributes\Test; class LogTest extends TestCase { @@ -18,7 +19,7 @@ protected function getEnvironmentSetUp($app) $app['config']['mailbox.driver'] = 'log'; } - /** @test */ + #[Test] public function it_catches_logged_mails() { Mailbox::from('{name}@beyondco.de', function (InboundEmail $email, $name) { diff --git a/tests/InboundEmailTest.php b/tests/InboundEmailTest.php index 8a54b9a..ef8156b 100644 --- a/tests/InboundEmailTest.php +++ b/tests/InboundEmailTest.php @@ -6,6 +6,7 @@ use BeyondCode\Mailbox\InboundEmail; use Illuminate\Mail\Mailable; use Illuminate\Support\Facades\Mail; +use PHPUnit\Framework\Attributes\Test; class InboundEmailTest extends TestCase { @@ -17,7 +18,7 @@ protected function getEnvironmentSetUp($app) $app['config']['mailbox.driver'] = 'log'; } - /** @test */ + #[Test] public function it_stores_inbound_emails() { Mailbox::to('someone@beyondco.de', function ($email) { @@ -29,7 +30,7 @@ public function it_stores_inbound_emails() $this->assertSame(1, InboundEmail::query()->count()); } - /** @test */ + #[Test] public function it_stores_all_inbound_emails() { $this->app['config']['mailbox.only_store_matching_emails'] = false; @@ -43,7 +44,7 @@ public function it_stores_all_inbound_emails() $this->assertSame(2, InboundEmail::query()->count()); } - /** @test */ + #[Test] public function it_can_use_fallbacks() { Mailbox::fallback(function (InboundEmail $email) { @@ -57,7 +58,7 @@ public function it_can_use_fallbacks() Mail::assertSent(ReplyMail::class); } - /** @test */ + #[Test] public function it_can_use_catchall() { Mailbox::to('someone@beyondco.de', function ($email) { @@ -74,7 +75,7 @@ public function it_can_use_catchall() Mail::assertSent(ReplyMail::class); } - /** @test */ + #[Test] public function it_stores_inbound_emails_with_catchall() { Mailbox::catchAll(function ($email) { @@ -86,7 +87,7 @@ public function it_stores_inbound_emails_with_catchall() $this->assertSame(2, InboundEmail::query()->count()); } - /** @test */ + #[Test] public function it_stores_inbound_emails_with_fallback() { Mailbox::fallback(function ($email) { @@ -98,7 +99,7 @@ public function it_stores_inbound_emails_with_fallback() $this->assertSame(2, InboundEmail::query()->count()); } - /** @test */ + #[Test] public function it_stores_inbound_emails_with_fallback_and_catchall_only_once() { Mailbox::fallback(function ($email) { @@ -113,7 +114,7 @@ public function it_stores_inbound_emails_with_fallback_and_catchall_only_once() $this->assertSame(2, InboundEmail::query()->count()); } - /** @test */ + #[Test] public function it_does_not_store_inbound_emails_if_configured() { $this->app['config']['mailbox.store_incoming_emails_for_days'] = 0; @@ -127,7 +128,7 @@ public function it_does_not_store_inbound_emails_if_configured() $this->assertSame(0, InboundEmail::query()->count()); } - /** @test */ + #[Test] public function it_can_reply_to_mails() { Mailbox::from('example@beyondco.de', function (InboundEmail $email) { @@ -141,7 +142,7 @@ public function it_can_reply_to_mails() Mail::assertSent(ReplyMail::class); } - /** @test */ + #[Test] public function it_uses_the_configured_model() { $this->app['config']['mailbox.model'] = ExtendedInboundEmail::class; diff --git a/tests/MailboxRouteCollectionTest.php b/tests/MailboxRouteCollectionTest.php index fa3c027..2dc5992 100644 --- a/tests/MailboxRouteCollectionTest.php +++ b/tests/MailboxRouteCollectionTest.php @@ -6,10 +6,11 @@ use BeyondCode\Mailbox\Routing\Route; use BeyondCode\Mailbox\Routing\RouteCollection; use Laminas\Mail\Message as TestMail; +use PHPUnit\Framework\Attributes\Test; class MailboxRouteCollectionTest extends TestCase { - /** @test */ + #[Test] public function it_returns_all_matching_mailbox_routes() { $collection = new RouteCollection(); diff --git a/tests/MailboxRouteTest.php b/tests/MailboxRouteTest.php index 5adfcd0..c8b65c9 100644 --- a/tests/MailboxRouteTest.php +++ b/tests/MailboxRouteTest.php @@ -5,6 +5,8 @@ use BeyondCode\Mailbox\InboundEmail; use BeyondCode\Mailbox\Routing\Route; use Laminas\Mail\Message as TestMail; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class MailboxRouteTest extends TestCase { @@ -16,11 +18,8 @@ public static function emailDataProvider() ]; } - /** - * @test - * - * @dataProvider emailDataProvider - */ + #[Test] + #[DataProvider('emailDataProvider')] public function it_matches_from_mails($fromMail, $successfulPattern, $failingPattern) { $testMail = (new TestMail()) @@ -35,11 +34,8 @@ public function it_matches_from_mails($fromMail, $successfulPattern, $failingPat $this->assertFalse($route->matches($message)); } - /** - * @test - * - * @dataProvider emailDataProvider - */ + #[Test] + #[DataProvider('emailDataProvider')] public function it_matches_to_mails($toMail, $successfulPattern, $failingPattern) { $testMail = (new TestMail()) @@ -54,11 +50,8 @@ public function it_matches_to_mails($toMail, $successfulPattern, $failingPattern $this->assertFalse($route->matches($message)); } - /** - * @test - * - * @dataProvider emailDataProvider - */ + #[Test] + #[DataProvider('emailDataProvider')] public function it_matches_cc_mails($ccMail, $successfulPattern, $failingPattern) { $testMail = (new TestMail()) @@ -73,11 +66,8 @@ public function it_matches_cc_mails($ccMail, $successfulPattern, $failingPattern $this->assertFalse($route->matches($message)); } - /** - * @test - * - * @dataProvider emailDataProvider - */ + #[Test] + #[DataProvider('emailDataProvider')] public function it_matches_bcc_mails($bccMail, $successfulPattern, $failingPattern) { $testMail = (new TestMail()) @@ -92,11 +82,8 @@ public function it_matches_bcc_mails($bccMail, $successfulPattern, $failingPatte $this->assertFalse($route->matches($message)); } - /** - * @test - * - * @dataProvider subjectDataProvider - */ + #[Test] + #[DataProvider('subjectDataProvider')] public function it_matches_subjects($subject, $successfulPattern, $failingPattern) { $testMail = (new TestMail()) @@ -111,7 +98,7 @@ public function it_matches_subjects($subject, $successfulPattern, $failingPatter $this->assertFalse($route->matches($message)); } - /** @test */ + #[Test] public function it_matches_requirements() { $testMail = (new TestMail()) @@ -138,7 +125,7 @@ public static function subjectDataProvider() ]; } - /** @test */ + #[Test] public function it_returns_parameter_names() { $route = new Route(Route::FROM, 'someone@domain.com', 'SomeAction@handle'); @@ -160,7 +147,7 @@ public function it_returns_parameter_names() ], $route->parameterNames()); } - /** @test */ + #[Test] public function it_returns_parameter_values() { $testMail = (new TestMail()) @@ -200,7 +187,7 @@ public function it_returns_parameter_values() ], $route->parameters()); } - /** @test */ + #[Test] public function it_runs_callables() { $testMail = (new TestMail()) @@ -217,7 +204,7 @@ public function it_runs_callables() $route->run($message); } - /** @test */ + #[Test] public function it_passes_parameters_to_callables() { $testMail = (new TestMail()) From 1417d4ae888ed5df3215ccb428561dd97701719a Mon Sep 17 00:00:00 2001 From: Diana Scharf Date: Fri, 20 Mar 2026 16:52:30 +0100 Subject: [PATCH 6/6] fix: drop laminas-mail dev dep for PHP 8.4, clarify README testing - Replace Laminas test MIME builder with TestMimeMessage helper - Restructure README Testing/Changelog out from under Herd section - Note zbateson/mail-mime-parser as inbound parser in Testing section Made-with: Cursor --- README.md | 7 ++-- composer.json | 1 - tests/MailboxRouteCollectionTest.php | 3 +- tests/MailboxRouteTest.php | 19 ++++----- tests/TestMimeMessage.php | 61 ++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 16 deletions(-) create mode 100644 tests/TestMimeMessage.php diff --git a/README.md b/README.md index e50c4c4..0c29d89 100644 --- a/README.md +++ b/README.md @@ -36,14 +36,15 @@ The email service organizes emails into distinct inboxes for each application, e ![image](https://github.com/user-attachments/assets/6417907c-119d-43ac-9cf6-5638bafae24f) +## Testing -### Testing +Inbound messages are parsed with [zbateson/mail-mime-parser](https://mail-mime-parser.org) (see the docs on [handling inbound email](https://docs.beyondco.de/laravel-mailbox/basic-usage/handling)). Run the package test suite with: -``` bash +```bash composer test ``` -### Changelog +## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. diff --git a/composer.json b/composer.json index d3fe760..a904a75 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,6 @@ "zbateson/mail-mime-parser": "^2.4|^3.0|^4.0" }, "require-dev": { - "laminas/laminas-mail": "^2.13", "mockery/mockery": "^1.2", "orchestra/testbench": "^8.0|^9.0|^10.0|^11.0", "phpunit/phpunit": "^10.5|^11.0|^12.0" diff --git a/tests/MailboxRouteCollectionTest.php b/tests/MailboxRouteCollectionTest.php index 2dc5992..d8d5fde 100644 --- a/tests/MailboxRouteCollectionTest.php +++ b/tests/MailboxRouteCollectionTest.php @@ -5,7 +5,6 @@ use BeyondCode\Mailbox\InboundEmail; use BeyondCode\Mailbox\Routing\Route; use BeyondCode\Mailbox\Routing\RouteCollection; -use Laminas\Mail\Message as TestMail; use PHPUnit\Framework\Attributes\Test; class MailboxRouteCollectionTest extends TestCase @@ -19,7 +18,7 @@ public function it_returns_all_matching_mailbox_routes() $collection->add(new Route(Route::FROM, '{from}@beyondco.de', '')); $collection->add(new Route(Route::FROM, 'different@laravel.com', '')); - $testMail = (new TestMail()) + $testMail = (new TestMimeMessage()) ->setFrom('hello@beyondco.de'); $message = new InboundEmail(['message' => $testMail->toString()]); diff --git a/tests/MailboxRouteTest.php b/tests/MailboxRouteTest.php index c8b65c9..3d4b3c1 100644 --- a/tests/MailboxRouteTest.php +++ b/tests/MailboxRouteTest.php @@ -4,7 +4,6 @@ use BeyondCode\Mailbox\InboundEmail; use BeyondCode\Mailbox\Routing\Route; -use Laminas\Mail\Message as TestMail; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; @@ -22,7 +21,7 @@ public static function emailDataProvider() #[DataProvider('emailDataProvider')] public function it_matches_from_mails($fromMail, $successfulPattern, $failingPattern) { - $testMail = (new TestMail()) + $testMail = (new TestMimeMessage()) ->setFrom($fromMail); $message = new InboundEmail(['message' => $testMail->toString()]); @@ -38,7 +37,7 @@ public function it_matches_from_mails($fromMail, $successfulPattern, $failingPat #[DataProvider('emailDataProvider')] public function it_matches_to_mails($toMail, $successfulPattern, $failingPattern) { - $testMail = (new TestMail()) + $testMail = (new TestMimeMessage()) ->setTo($toMail); $message = new InboundEmail(['message' => $testMail->toString()]); @@ -54,7 +53,7 @@ public function it_matches_to_mails($toMail, $successfulPattern, $failingPattern #[DataProvider('emailDataProvider')] public function it_matches_cc_mails($ccMail, $successfulPattern, $failingPattern) { - $testMail = (new TestMail()) + $testMail = (new TestMimeMessage()) ->setCc($ccMail); $message = new InboundEmail(['message' => $testMail->toString()]); @@ -70,7 +69,7 @@ public function it_matches_cc_mails($ccMail, $successfulPattern, $failingPattern #[DataProvider('emailDataProvider')] public function it_matches_bcc_mails($bccMail, $successfulPattern, $failingPattern) { - $testMail = (new TestMail()) + $testMail = (new TestMimeMessage()) ->setBcc($bccMail); $message = new InboundEmail(['message' => $testMail->toString()]); @@ -86,7 +85,7 @@ public function it_matches_bcc_mails($bccMail, $successfulPattern, $failingPatte #[DataProvider('subjectDataProvider')] public function it_matches_subjects($subject, $successfulPattern, $failingPattern) { - $testMail = (new TestMail()) + $testMail = (new TestMimeMessage()) ->setSubject($subject); $message = new InboundEmail(['message' => $testMail->toString()]); @@ -101,7 +100,7 @@ public function it_matches_subjects($subject, $successfulPattern, $failingPatter #[Test] public function it_matches_requirements() { - $testMail = (new TestMail()) + $testMail = (new TestMimeMessage()) ->setFrom('abc@domain.com'); $message = new InboundEmail(['message' => $testMail->toString()]); @@ -150,7 +149,7 @@ public function it_returns_parameter_names() #[Test] public function it_returns_parameter_values() { - $testMail = (new TestMail()) + $testMail = (new TestMimeMessage()) ->setFrom('my-email@foo.com') ->setSubject('ABC/DEF/GEH'); @@ -190,7 +189,7 @@ public function it_returns_parameter_values() #[Test] public function it_runs_callables() { - $testMail = (new TestMail()) + $testMail = (new TestMimeMessage()) ->setFrom('marcel@beyondco.de'); $message = new InboundEmail(['message' => $testMail->toString()]); @@ -207,7 +206,7 @@ public function it_runs_callables() #[Test] public function it_passes_parameters_to_callables() { - $testMail = (new TestMail()) + $testMail = (new TestMimeMessage()) ->setFrom('marcel@beyondco.de'); $message = new InboundEmail(['message' => $testMail->toString()]); diff --git a/tests/TestMimeMessage.php b/tests/TestMimeMessage.php new file mode 100644 index 0000000..858ffdb --- /dev/null +++ b/tests/TestMimeMessage.php @@ -0,0 +1,61 @@ + */ + private array $headers = []; + + public function setFrom(string $email): self + { + $this->headers['From'] = $email; + + return $this; + } + + public function setTo(string $email): self + { + $this->headers['To'] = $email; + + return $this; + } + + public function setCc(string $email): self + { + $this->headers['Cc'] = $email; + + return $this; + } + + public function setBcc(string $email): self + { + $this->headers['Bcc'] = $email; + + return $this; + } + + public function setSubject(string $subject): self + { + $this->headers['Subject'] = $subject; + + return $this; + } + + public function toString(): string + { + $lines = []; + foreach (['From', 'To', 'Cc', 'Bcc', 'Subject'] as $name) { + if (isset($this->headers[$name])) { + $lines[] = $name.': '.$this->headers[$name]; + } + } + $lines[] = 'MIME-Version: 1.0'; + $lines[] = 'Content-Type: text/plain; charset=UTF-8'; + $lines[] = ''; + $lines[] = ''; + + return implode("\r\n", $lines); + } +}