mailer-test
mailer-test copied to clipboard
Email->assertTo() might accept multiple recipient email addresses
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.
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.
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.
maybe... getTo() could have a getToMultiple() or getToAsSet() sibling method returning your imagined TestAddressSet object and linked methods.
getToAsSet() seems nice.