Skip to content

Commit c9500d8

Browse files
feature #60740 [Mailer] Add assertEmailAddressNotContains (santysisi)
This PR was merged into the 7.4 branch. Discussion ---------- [Mailer] Add `assertEmailAddressNotContains` | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | No | License | MIT This PR introduces a new assertion method `assertEmailAddressNotContains()` to the `MailerAssertionsTrait`. The new method complements the existing `assertEmailAddressContains()` by allowing developers to assert that a specific email address **does not** appear in a given header. This addition brings the `assertEmailAddressContains` in line with other similar assertion pairs already available in the trait, such as: - `assertEmailTextBodyContains` / `assertEmailTextBodyNotContains` - `assertEmailHtmlBodyContains` / `assertEmailHtmlBodyNotContains` - `assertEmailSubjectContains` / `assertEmailSubjectNotContains` ### Example usage ```php $this->assertEmailAddressNotContains($email, 'To', 'test@test.com'); ``` Commits ------- 9cc6a63 [Mailer] Add new `assertEmailAddressNotContains` method
2 parents 7b19f53 + 9cc6a63 commit c9500d8

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Deprecate `Symfony\Bundle\FrameworkBundle\Console\Application::add()` in favor of `Symfony\Bundle\FrameworkBundle\Console\Application::addCommand()`
8+
* Add `assertEmailAddressNotContains()` to the `MailerAssertionsTrait`
89

910
7.3
1011
---

src/Symfony/Bundle/FrameworkBundle/Test/MailerAssertionsTrait.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ public static function assertEmailAddressContains(RawMessage $email, string $hea
9090
self::assertThat($email, new MimeConstraint\EmailAddressContains($headerName, $expectedValue), $message);
9191
}
9292

93+
public static function assertEmailAddressNotContains(RawMessage $email, string $headerName, string $expectedValue, string $message = ''): void
94+
{
95+
self::assertThat($email, new LogicalNot(new MimeConstraint\EmailAddressContains($headerName, $expectedValue)), $message);
96+
}
97+
9398
public static function assertEmailSubjectContains(RawMessage $email, string $expectedValue, string $message = ''): void
9499
{
95100
self::assertThat($email, new MimeConstraint\EmailSubjectContains($expectedValue), $message);

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/MailerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,15 @@ public function testMailerAssertions()
9999
$this->assertEmailHtmlBodyContains($email, 'Foo');
100100
$this->assertEmailHtmlBodyNotContains($email, 'Bar');
101101
$this->assertEmailAttachmentCount($email, 1);
102+
$this->assertEmailAddressNotContains($email, 'To', 'thomas@symfony.com');
102103

103104
$email = $this->getMailerMessage($second);
104105
$this->assertEmailSubjectContains($email, 'Foo');
105106
$this->assertEmailSubjectNotContains($email, 'Bar');
106107
$this->assertEmailAddressContains($email, 'To', 'fabien@symfony.com');
107108
$this->assertEmailAddressContains($email, 'To', 'thomas@symfony.com');
108109
$this->assertEmailAddressContains($email, 'Reply-To', 'me@symfony.com');
110+
$this->assertEmailAddressNotContains($email, 'To', 'helene@symfony.com');
111+
$this->assertEmailAddressNotContains($email, 'Reply-To', 'helene@symfony.com');
109112
}
110113
}

0 commit comments

Comments
 (0)