From 6ce062df8624621f377ee31884cc425db2931a88 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Thu, 7 Apr 2022 10:28:16 -0400 Subject: [PATCH 1/2] [feature] require Symfony 5.4+ --- .github/workflows/ci.yml | 46 +++++++++++-------- composer.json | 12 ++--- phpstan-baseline.neon | 5 -- phpstan.neon | 1 - .../Zenstruck/Browser/MailerComponent.php | 6 +-- src/InteractsWithMailer.php | 6 +-- tests/ContainerBC.php | 24 ---------- tests/Fixture/Kernel.php | 16 +------ tests/InteractsWithMailerTest.php | 22 ++++----- tests/NonInteractsWithMailerTest.php | 10 ++-- 10 files changed, 55 insertions(+), 93 deletions(-) delete mode 100644 tests/ContainerBC.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be7a600..4ea1d0e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,8 +7,30 @@ on: - cron: '0 0 1,16 * *' jobs: - test: - uses: zenstruck/.github/.github/workflows/php-test-symfony.yml@main + tests: + name: PHP ${{ matrix.php }}, SF ${{ matrix.symfony }} - ${{ matrix.deps }} + runs-on: ubuntu-latest + strategy: + matrix: + php: [7.4, 8.0, 8.1] + deps: [hightest] + symfony: [5.4.*] + include: + - php: 7.4 + deps: lowest + symfony: '*' + - php: 8.0 + deps: highest + symfony: 6.0.* + - php: 8.1 + deps: highest + symfony: 6.0.* + steps: + - uses: zenstruck/.github@php-test-symfony + with: + php: ${{ matrix.php }} + symfony: ${{ matrix.symfony }} + deps: ${{ matrix.deps }} code-coverage: uses: zenstruck/.github/.github/workflows/php-coverage-codecov.yml@main @@ -22,20 +44,6 @@ jobs: uses: zenstruck/.github/.github/workflows/php-cs-fixer.yml@main sca: - name: Static Code Analysis - runs-on: ubuntu-latest - steps: - - name: Checkout Code - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.1 - coverage: none - - - name: Install Dependencies - uses: ramsey/composer-install@v1 - - - name: Run PHPStan - run: vendor/bin/phpstan --error-format=github + uses: zenstruck/.github/.github/workflows/php-stan.yml@main + with: + php: 8.1 diff --git a/composer.json b/composer.json index e0caf65..22759c8 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,8 @@ ], "require": { "php": ">=7.4", - "symfony/framework-bundle": "^4.4|^5.0|^6.0", - "symfony/mailer": "^4.4|^5.0|^6.0", + "symfony/framework-bundle": "^5.4|^6.0", + "symfony/mailer": "^5.4|^6.0", "symfony/polyfill-php80": "^1.23.1", "zenstruck/assert": "^1.0", "zenstruck/callback": "^1.1" @@ -22,10 +22,10 @@ "require-dev": { "phpstan/phpstan": "^1.4", "phpunit/phpunit": "^9.5.0", - "symfony/messenger": "^4.4|^5.0|^6.0", - "symfony/phpunit-bridge": "^5.3", - "symfony/var-dumper": "^4.4|^5.0|^6.0", - "symfony/yaml": "^4.4|^5.0|^6.0", + "symfony/messenger": "^5.4|^6.0", + "symfony/phpunit-bridge": "^6.0", + "symfony/var-dumper": "^5.4|^6.0", + "symfony/yaml": "^5.4|^6.0", "zenstruck/browser": "^1.0@dev" }, "config": { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3b262e2..486b356 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -25,11 +25,6 @@ parameters: count: 1 path: src/TestEmail.php - - - message: "#^Method Zenstruck\\\\Mailer\\\\Test\\\\TestEmail\\:\\:as\\(\\) should return T of Zenstruck\\\\Mailer\\\\Test\\\\TestEmail but returns object\\.$#" - count: 1 - path: src/TestEmail.php - - message: "#^Parameter \\#1 \\$events of static method Zenstruck\\\\Mailer\\\\Test\\\\SentEmails\\:\\:fromEvents\\(\\) expects Symfony\\\\Component\\\\Mailer\\\\Event\\\\MessageEvents, Symfony\\\\Component\\\\Mailer\\\\Event\\\\MessageEvents\\|null given\\.$#" count: 1 diff --git a/phpstan.neon b/phpstan.neon index 62ab5d1..28cf30b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,4 +5,3 @@ parameters: level: 8 paths: - src - - tests diff --git a/src/Bridge/Zenstruck/Browser/MailerComponent.php b/src/Bridge/Zenstruck/Browser/MailerComponent.php index 36af4d2..250d69c 100644 --- a/src/Bridge/Zenstruck/Browser/MailerComponent.php +++ b/src/Bridge/Zenstruck/Browser/MailerComponent.php @@ -3,8 +3,8 @@ namespace Zenstruck\Mailer\Test\Bridge\Zenstruck\Browser; use Symfony\Component\Mailer\DataCollector\MessageDataCollector; -use Zenstruck\Browser\BrowserKitBrowser; use Zenstruck\Browser\Component; +use Zenstruck\Browser\KernelBrowser; use Zenstruck\Mailer\Test\SentEmailMixin; use Zenstruck\Mailer\Test\SentEmails; @@ -19,8 +19,8 @@ public function sentEmails(): SentEmails { $browser = $this->browser(); - if (!$browser instanceof BrowserKitBrowser) { - throw new \RuntimeException(\sprintf('The "Mailer" component requires the browser be a %s.', BrowserKitBrowser::class)); + if (!$browser instanceof KernelBrowser) { + throw new \RuntimeException(\sprintf('The "Mailer" component requires the browser be a %s.', KernelBrowser::class)); } if (!$browser->profile()->hasCollector('mailer')) { diff --git a/src/InteractsWithMailer.php b/src/InteractsWithMailer.php index cd1cd84..659bab3 100644 --- a/src/InteractsWithMailer.php +++ b/src/InteractsWithMailer.php @@ -37,12 +37,10 @@ final protected function mailer(): TestMailer throw new \LogicException('The kernel must be booted before accessing the mailer.'); } - $container = \method_exists(self::class, 'getContainer') ? self::getContainer() : self::$container; - - if (!$container->has('zenstruck_mailer_test.mailer')) { + if (!self::getContainer()->has('zenstruck_mailer_test.mailer')) { throw new \LogicException(\sprintf('Cannot access test mailer - is %s enabled in your test environment?', ZenstruckMailerTestBundle::class)); } - return $container->get('zenstruck_mailer_test.mailer'); + return self::getContainer()->get('zenstruck_mailer_test.mailer'); } } diff --git a/tests/ContainerBC.php b/tests/ContainerBC.php deleted file mode 100644 index 8f125ed..0000000 --- a/tests/ContainerBC.php +++ /dev/null @@ -1,24 +0,0 @@ - - */ -trait ContainerBC -{ - private static function container(): ContainerInterface - { - if (!\method_exists(static::class, 'getContainer')) { - if (!static::$booted) { - static::bootKernel(); - } - - return self::$container; - } - - return self::getContainer(); - } -} diff --git a/tests/Fixture/Kernel.php b/tests/Fixture/Kernel.php index 5c00962..70c22e4 100644 --- a/tests/Fixture/Kernel.php +++ b/tests/Fixture/Kernel.php @@ -9,7 +9,6 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Kernel as BaseKernel; use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; -use Symfony\Component\Routing\RouteCollectionBuilder; use Zenstruck\Mailer\Test\ZenstruckMailerTestBundle; /** @@ -40,24 +39,13 @@ public function registerBundles(): iterable } } - protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader): void + private function configureContainer(ContainerBuilder $c, LoaderInterface $loader): void { $loader->load(\sprintf('%s/config/%s.yaml', __DIR__, $this->getEnvironment())); } - /** - * @param RouteCollectionBuilder|RoutingConfigurator $routes - */ - protected function configureRoutes($routes): void + private function configureRoutes(RoutingConfigurator $routes): void { - if ($routes instanceof RouteCollectionBuilder) { - // BC - $routes->add('/no-email', 'kernel::noEmail'); - $routes->add('/send-email', 'kernel::sendEmail'); - - return; - } - $routes->add('no-email', '/no-email')->controller('kernel::noEmail'); $routes->add('send-email', '/send-email')->controller('kernel::sendEmail'); } diff --git a/tests/InteractsWithMailerTest.php b/tests/InteractsWithMailerTest.php index 35a4cc4..7cdc8dc 100644 --- a/tests/InteractsWithMailerTest.php +++ b/tests/InteractsWithMailerTest.php @@ -16,7 +16,7 @@ */ final class InteractsWithMailerTest extends KernelTestCase { - use ContainerBC, EnvironmentProvider, InteractsWithMailer; + use EnvironmentProvider, InteractsWithMailer; /** * @test @@ -51,7 +51,7 @@ public function can_assert_email_sent(string $environment): void { self::bootKernel(['environment' => $environment]); - self::container()->get('mailer')->send(new Email1()); + self::getContainer()->get('mailer')->send(new Email1()); $this->mailer() ->assertSentEmailCount(1) @@ -93,7 +93,7 @@ public function assert_email_sent_to_fail(string $environment): void { self::bootKernel(['environment' => $environment]); - self::container()->get('mailer')->send(new Email1()); + self::getContainer()->get('mailer')->send(new Email1()); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('No email was sent to "jim@example.com".'); @@ -112,7 +112,7 @@ public function can_use_custom_test_email_class(string $environment): void $email = new Email1(); $email->getHeaders()->addTextHeader('X-PM-Tag', 'reset-password'); - self::container()->get('mailer')->send($email); + self::getContainer()->get('mailer')->send($email); $this->mailer()->assertEmailSentTo('kevin@example.com', function(CustomTestEmail $email) { $email->assertHasPostmarkTag('reset-password'); @@ -127,7 +127,7 @@ public function can_access_sent_test_emails(string $environment): void { self::bootKernel(['environment' => $environment]); - self::container()->get('mailer')->send(new Email1()); + self::getContainer()->get('mailer')->send(new Email1()); $this->assertInstanceOf(TestEmail::class, $this->mailer()->sentEmails()->all()[0]); } @@ -140,7 +140,7 @@ public function can_access_sent_test_emails_with_custom_test_email_class(string { self::bootKernel(['environment' => $environment]); - self::container()->get('mailer')->send(new Email1()); + self::getContainer()->get('mailer')->send(new Email1()); $this->assertInstanceOf(CustomTestEmail::class, $this->mailer()->sentEmails()->all(CustomTestEmail::class)[0]); } @@ -150,7 +150,7 @@ public function can_access_sent_test_emails_with_custom_test_email_class(string */ public function sent_test_email_argument_must_be_an_instance_of_test_email(): void { - self::container()->get('mailer')->send(new Email1()); + self::getContainer()->get('mailer')->send(new Email1()); $this->expectException(\InvalidArgumentException::class); @@ -175,7 +175,7 @@ public function profiler_does_not_need_to_enabled(): void { self::bootKernel(['environment' => 'no_profiler']); - self::container()->get('mailer')->send(new Email1()); + self::getContainer()->get('mailer')->send(new Email1()); $this->mailer()->assertSentEmailCount(1); } @@ -190,7 +190,7 @@ public function emails_are_persisted_between_reboots(string $environment): void $this->mailer()->assertNoEmailSent(); - self::container()->get('mailer')->send(new Email1()); + self::getContainer()->get('mailer')->send(new Email1()); $this->mailer()->assertSentEmailCount(1); @@ -211,7 +211,7 @@ public function can_reset_collected_emails(string $environment): void $this->mailer()->assertNoEmailSent(); - self::container()->get('mailer')->send(new Email1()); + self::getContainer()->get('mailer')->send(new Email1()); $this->mailer() ->assertSentEmailCount(1) @@ -223,7 +223,7 @@ public function can_reset_collected_emails(string $environment): void self::bootKernel(['environment' => $environment]); - self::container()->get('mailer')->send(new Email1()); + self::getContainer()->get('mailer')->send(new Email1()); $this->mailer()->assertSentEmailCount(1); } diff --git a/tests/NonInteractsWithMailerTest.php b/tests/NonInteractsWithMailerTest.php index 8a4756f..8e18b43 100644 --- a/tests/NonInteractsWithMailerTest.php +++ b/tests/NonInteractsWithMailerTest.php @@ -10,19 +10,17 @@ */ final class NonInteractsWithMailerTest extends KernelTestCase { - use ContainerBC; - /** * @test */ public function ensure_emails_are_not_collected(): void { - self::container()->get('mailer')->send(new Email1()); + self::getContainer()->get('mailer')->send(new Email1()); $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot access sent emails as email collection has not yet been started.'); - self::container()->get('zenstruck_mailer_test.mailer')->sentEmails(); + self::getContainer()->get('zenstruck_mailer_test.mailer')->sentEmails(); } /** @@ -30,11 +28,11 @@ public function ensure_emails_are_not_collected(): void */ public function cannot_reset_if_collection_not_yet_started(): void { - self::container()->get('mailer')->send(new Email1()); + self::getContainer()->get('mailer')->send(new Email1()); $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot access sent emails as email collection has not yet been started.'); - self::container()->get('zenstruck_mailer_test.mailer')->reset(); + self::getContainer()->get('zenstruck_mailer_test.mailer')->reset(); } } From 52aca25d98e9eb521cf0f778a6ed2a657b0eff45 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Thu, 7 Apr 2022 10:38:54 -0400 Subject: [PATCH 2/2] [minor] remove scrutinizer --- .scrutinizer.yml | 10 ---------- README.md | 1 - 2 files changed, 11 deletions(-) delete mode 100644 .scrutinizer.yml diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 618f98d..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,10 +0,0 @@ -filter: - dependency_paths: [vendor/] -checks: - php: true -build: - nodes: - analysis: - tests: - override: - - php-scrutinizer-run diff --git a/README.md b/README.md index fb03fcc..07a4695 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # zenstruck/mailer-test [![CI Status](https://github.com/zenstruck/mailer-test/workflows/CI/badge.svg)](https://github.com/zenstruck/mailer-test/actions?query=workflow%3ACI) -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/zenstruck/mailer-test/badges/quality-score.png?b=1.x)](https://scrutinizer-ci.com/g/zenstruck/mailer-test/?branch=1.x) [![Code Coverage](https://codecov.io/gh/zenstruck/mailer-test/branch/1.x/graph/badge.svg?token=R7OHYYGPKM)](https://codecov.io/gh/zenstruck/mailer-test) Alternative, opinionated helpers for testing emails sent with `symfony/mailer`. This package is