Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Mailer][Mime] Add PHPUnit constraints and assertions for the Mailer#32930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:4.4fromfabpot:mailer-test-assertions
Aug 5, 2019

Conversation

@fabpot
Copy link
Member

@fabpotfabpot commentedAug 4, 2019
edited
Loading

QA
Branch?4.4
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed ticketsrefs#31592,closes#32409,closes#31947,closes#31747,closes#30850
LicenseMIT
Doc PRn/a

This PR introduces PHPUnit constraints and assertions to ease testing emails in functional tests:

<?phpnamespaceApp\Tests;useSymfony\Bundle\FrameworkBundle\Test\WebTestCase;class MailerAssertionsTraitsTestextends WebTestCase{publicfunctiontestSomething()    {$client =static::createClient();$client->request('GET','/');$this->assertEmailCount(2);$this->assertEmailIsQueued($this->getMailerEvent(0));$email =$this->getMailerMessage(0);$this->assertEmailHasHeader($email,'To');$this->assertEmailHeaderSame($email,'To','fabien@symfony.com');$this->assertEmailTextBodyContains($email,'Bar');$this->assertEmailHtmlBodyContains($email,'Foo');$this->assertEmailAttachementCount($email,1);    }}

leevigraham reacted with thumbs up emojisstok reacted with hooray emojisstok, evertharmeling, bricejulia, and freiondrej reacted with heart emoji
@fabpot
Copy link
MemberAuthor

image

@fabpot
Copy link
MemberAuthor

Now with some functional tests.

@fabpotfabpotforce-pushed themailer-test-assertions branch 3 times, most recently from03ea45e toe1645f0CompareAugust 5, 2019 05:57
@fabpotfabpotforce-pushed themailer-test-assertions branch 2 times, most recently from0259074 toa1ab4d5CompareAugust 5, 2019 13:55
@javiereguiluz
Copy link
Member

The proposed asserts are nice! Thanks.

I wonder if we need asserts for addresses. The mailer component allows to define email addresses in multiple ways (seehttps://symfony.com/doc/current/mailer.html#email-addresses). If I define some address asJane Smith <jane@example.com> ... which of the following would work?

$this->assertEmailHeaderSame($email,'From','jane@example.com');$this->assertEmailHeaderSame($email,'From','Jane Smith');$this->assertEmailHeaderSame($email,'From','Jane Smith <jane@example.com>');

If others agree that this is confusing and also a common thing to assert, then we could add some assert for addresses which accept only a plain email address no matter how you defined the address:

$this->assertEmailFromAddress($email,'jane@example.com');

Related to this, what happens with multiple addresses?

$this->assertEmailToAddressContains($email,'john@example.com');

@fabpotfabpotforce-pushed themailer-test-assertions branch froma1ab4d5 toc263f21CompareAugust 5, 2019 15:46
@fabpotfabpotforce-pushed themailer-test-assertions branch 2 times, most recently from2ed6076 to9ea3b0eCompareAugust 5, 2019 16:15
@fabpot
Copy link
MemberAuthor

fabpot commentedAug 5, 2019
edited
Loading

@javiereguiluz Good idea. Implemented:

$this->assertEmailAddressContains($email,'To','fabien@symfony.com');$this->assertEmailAddressContains($email,'To','thomas@symfony.com');$this->assertEmailAddressContains($email,'Reply-To','me@symfony.com');

Works with headers that can contain only 1 or several addresses (also with named addresses).

@fabpotfabpotforce-pushed themailer-test-assertions branch from9ea3b0e to23f237bCompareAugust 5, 2019 16:16
@fabpotfabpot merged commit23f237b intosymfony:4.4Aug 5, 2019
fabpot added a commit that referenced this pull requestAug 5, 2019
…for the Mailer (fabpot)This PR was merged into the 4.4 branch.Discussion----------[Mailer][Mime] Add PHPUnit constraints and assertions for the Mailer| Q             | A| ------------- | ---| Branch?       | 4.4| Bug fix?      | no| New feature?  | yes| BC breaks?    | no     <!-- seehttps://symfony.com/bc -->| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->| Fixed tickets | refs#31592,closes#32409,closes#31947,closes#31747,closes#30850| License       | MIT| Doc PR        | n/aThis PR introduces PHPUnit constraints and assertions to ease testing emails in functional tests:```php<?phpnamespace App\Tests;use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;class MailerAssertionsTraitsTest extends WebTestCase{    public function testSomething()    {        $client = static::createClient();        $client->request('GET', '/');        $this->assertEmailCount(2);        $this->assertEmailIsQueued($this->getMailerEvent(0));        $email = $this->getMailerMessage(0);        $this->assertEmailHasHeader($email, 'To');        $this->assertEmailHeaderSame($email, 'To', 'fabien@symfony.com');        $this->assertEmailTextBodyContains($email, 'Bar');        $this->assertEmailHtmlBodyContains($email, 'Foo');        $this->assertEmailAttachementCount($email, 1);    }}```Commits-------23f237b added PHPUnit constraints and assertions for the Mailer
@fabpotfabpot deleted the mailer-test-assertions branchAugust 5, 2019 16:41
@nicolas-grekasnicolas-grekas modified the milestones:next,4.4Oct 27, 2019
This was referencedNov 12, 2019
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@javiereguiluzjaviereguiluzjaviereguiluz left review comments

+1 more reviewer

@kevin-verschaevekevin-verschaevekevin-verschaeve left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.4

Development

Successfully merging this pull request may close these issues.

[Mailer] NullTransport: store messages for verification in tests [Mailer][RFC] KernelTestCase Assertion send messages

5 participants

@fabpot@javiereguiluz@kevin-verschaeve@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp