Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
fbee460 to05c1ae4CompareUh oh!
There was an error while loading.Please reload this page.
fabpot commentedAug 4, 2019
05c1ae4 toc96a967Comparefabpot commentedAug 4, 2019
Now with some functional tests. |
03ea45e toe1645f0Comparesrc/Symfony/Component/Mime/Test/Constraint/EmailAttachmentCount.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Mime/Test/Constraint/EmailHtmlBodyContains.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Mime/Test/Constraint/EmailTextBodyContains.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/FrameworkBundle/Test/MailerAssertionsTrait.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...mfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
0259074 toa1ab4d5Comparejaviereguiluz commentedAug 5, 2019
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 as $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'); |
a1ab4d5 toc263f21Compare2ed6076 to9ea3b0eComparefabpot commentedAug 5, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@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). |
9ea3b0e to23f237bCompare…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

Uh oh!
There was an error while loading.Please reload this page.
This PR introduces PHPUnit constraints and assertions to ease testing emails in functional tests: