Skip to content

[Mailer] Add assertEmailAddressNotContains #60740

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 7.4
Choose a base branch
from

Conversation

santysisi
Copy link
Contributor

@santysisi santysisi commented Jun 7, 2025

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

$this->assertEmailAddressNotContains($email, 'To', 'test@test.com');

@@ -1,6 +1,10 @@
CHANGELOG
=========

7.4
---
* added `assertEmailAddressNotContains()` to `MailerAssertionsTrait`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* added `assertEmailAddressNotContains()` to `MailerAssertionsTrait`.
* Add `assertEmailAddressNotContains()` to the `MailerAssertionsTrait`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your suggestion, and I've made that change.
Thanks a lot for your help!

Comment on lines 109 to 111
$this->assertEmailAddressNotContains($email, 'To', 'fabien@fake.symfony.com');
$this->assertEmailAddressNotContains($email, 'To', 'thomas@fake.symfony.com');
$this->assertEmailAddressNotContains($email, 'Reply-To', 'me@fake.symfony.com');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that these assertions are redundant, given that the addresses specified have never been used before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think the assertions are an issue, but I’m happy to update the emails if you have any suggestions for alternatives.
Thanks again! 😄❤️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the emails to helene@symfony.com. I believe this still tests the same behavior, but this format is more in line with the emails currently used in Symfony tests 😊

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test that cannot fail is not useful. I think you should to add assertions that would actually fail if something breaks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to clarify a couple of points:

  1. The method is simply applying a LogicalNot to an existing Constraint that is already implemented and tested.
  2. If you look at several of the current assertions in the same test file, you'll notice that they cover similar cases to the ones I'm adding now. In fact, the same email is already being tested, just in a different way.

As always, if you have any suggestions, they're more than welcome! 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Spomky @bkosun 👋, I also added this assertion

$this->assertEmailAddressNotContains($email, 'To', 'thomas@symfony.com');

This checks that the first email does not include thomas@symfony.com in the "To" field.

Just to clarify: this address is included in the second email, but not in the first one, which is the behavior this assertion is verifying.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it makes sense. Thank you!

@@ -1,6 +1,10 @@
CHANGELOG
=========

7.4
---
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
---
---

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again! The change has been made.
Apologies for the many mistakes in the CHANGELOG.md, totally my fault 😄

@santysisi santysisi force-pushed the feature/add-assertEmailAddressNotContains branch from b64a567 to 559d45b Compare June 8, 2025 05:01
@Spomky
Copy link
Contributor

Spomky commented Jun 10, 2025

Hi @santysisi,

Indeed this could be a nice addition.
❓ Question: What about helper methods such as assertToEmailAddressNotContains/assertReplyToEmailAddressNotContains? I know assertToEmailAddressContains/assertReplyToEmailAddressContains do not exist. Could be added too. WDYT?

@santysisi
Copy link
Contributor Author

Hi @Spomky 👋, thanks a lot for your comment! 😊

I see where you're coming from. The main concern with that approach is that it could lead to a large number of helper methods, like assertBccEmailAddressContains, assertCcEmailAddressContains, assertFromEmailAddressContains, and so on. Personally, I prefer having a single method that accepts a headerName argument, it's more flexible (IMO) and avoids code duplication.

That said, if you and others feel that having separate, explicit methods is more readable or convenient, I'm happy to add them! 😄

Thanks again for your feedback ❤️

@Spomky
Copy link
Contributor

Spomky commented Jun 11, 2025

OK so let consider the suggested change from @bkosun and I'll approve this PR.

@santysisi santysisi force-pushed the feature/add-assertEmailAddressNotContains branch 3 times, most recently from 10566de to ce99b79 Compare June 11, 2025 22:08
@santysisi santysisi force-pushed the feature/add-assertEmailAddressNotContains branch from ce99b79 to 9cc6a63 Compare June 11, 2025 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants