Skip to content

Commit

Permalink
Merge pull request #15 from kbond/symfony-54
Browse files Browse the repository at this point in the history
Require Symfony 5.4+
  • Loading branch information
kbond committed Apr 7, 2022
2 parents e5caa26 + 52aca25 commit 518edc7
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 104 deletions.
46 changes: 27 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
10 changes: 0 additions & 10 deletions .scrutinizer.yml

This file was deleted.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
],
"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"
},
"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": {
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ parameters:
level: 8
paths:
- src
- tests
6 changes: 3 additions & 3 deletions src/Bridge/Zenstruck/Browser/MailerComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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')) {
Expand Down
6 changes: 2 additions & 4 deletions src/InteractsWithMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
24 changes: 0 additions & 24 deletions tests/ContainerBC.php

This file was deleted.

16 changes: 2 additions & 14 deletions tests/Fixture/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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');
}
Expand Down
22 changes: 11 additions & 11 deletions tests/InteractsWithMailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
final class InteractsWithMailerTest extends KernelTestCase
{
use ContainerBC, EnvironmentProvider, InteractsWithMailer;
use EnvironmentProvider, InteractsWithMailer;

/**
* @test
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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".');
Expand All @@ -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');
Expand All @@ -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]);
}
Expand All @@ -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]);
}
Expand All @@ -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);

Expand All @@ -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);
}
Expand All @@ -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);

Expand All @@ -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)
Expand All @@ -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);
}
Expand Down
10 changes: 4 additions & 6 deletions tests/NonInteractsWithMailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,29 @@
*/
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();
}

/**
* @test
*/
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();
}
}

0 comments on commit 518edc7

Please sign in to comment.