Skip to content
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

Email->assertTo() might accept multiple recipient email addresses #21

Open
myselfhimself opened this issue Jan 13, 2023 · 3 comments
Open

Comments

@myselfhimself
Copy link

Hello

for now TestEmail::assertTo allows for checking that only 1 email address belongs in the To: recipients email addresses list.

So if I want to check that my e-mail goes to three specific email addresses, I have to call assertTo 3 three times, then check a count as follows:

        foreach($effectiveToEmailAddresses as $effectiveToEmailAddress) {
            $sentEmail->assertTo($effectiveToEmailAddress);
        }
        $this->assertCount(count($effectiveToEmailAddresses), $sentEmail->getTo());

maybe final public function assertTo(string $expectedEmail, ?string $expectedName = null): self could have a friend sibling method assertToAddresses(Address[]|array $expectedAddresses, bool $strict = true): self where the $strict ensures that the recipient addresses set is exactly that of $expectedAddresses, instead of just checking for a subset inclusion (ie. expected addresses belong in actual addresses).

This is not blocking... Just ideating.

@kbond
Copy link
Member

kbond commented Jan 13, 2023

This makes sense. We'd need this method for each of the methods that return addresses.

Would be nice to perhaps have a TestAddressSet object so we could do:

$email->getTo()
    ->assertCount(int)
    ->assertContains(string $expectedEmail, ?string $expectedName = null)
    ->assertContainsAll(Address[] $expectedAddresses) // check subset
    ->assertOnlyContainsAll(Address[] $expectedAddresses) // strict
;

Not sure how to preserve BC for this though as changing the signature of getTo() would be a BC break.

@myselfhimself
Copy link
Author

myselfhimself commented Jan 19, 2023

Hello,

maybe... getTo() could have a getToMultiple() or getToAsSet() sibling method returning your imagined TestAddressSet object and linked methods.

assertOnlyContainsAll could equate to assertContainsAll( with a $strict = true) flag last parameter.

@kbond
Copy link
Member

kbond commented Jan 19, 2023

maybe... getTo() could have a getToMultiple() or getToAsSet() sibling method returning your imagined TestAddressSet object and linked methods.

getToAsSet() seems nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants