Codeception / module-laravel

Modern Laravel module for Codeception
MIT License
5 stars 13 forks source link

Laravel module email assertions #22

Open janhenkgerritsen opened 8 years ago

janhenkgerritsen commented 8 years ago

Add email assertions to Laravel 5 module.

Idea for implementation came from https://laracasts.com/series/phpunit-testing-in-laravel/episodes/12. Will work with all default mail transports in Laravel, they all have the beforeSendPerformed method.

Have to think about a good API for these assertions though.

DavertMik commented 8 years ago

We have seeEmailIsSent in Symfony2 module but it doesn't perform any checks on type of email messages. Just verifies that something was sent...

janhenkgerritsen commented 8 years ago

I could just provide assertions for the last email that was sent, things like seeEmailIsSent, seeEmailIsSentTo, seeEmailIsSentFrom, seeEmailIsSentWithSubject, etc. But what if multiple emails were sent?

One option is to just loop through all emails that were sent and check if one of those satisfies the assertion.

Another option is to just add a method grabEmails and let users handle those cases themselves.

In the Laracast video Jeffrey adds a second optional parameter for the message object to the assertion methods, but if we do that the assertions should probably have other names.

Any preferences or other ideas?

DavertMik commented 8 years ago

My preferable syntax will be:

seeEmailIsSent(array $params = null, $num = 1);

so to be used as:

$I->seeEmailIsSent();
$I->seeEmailIsSent(['from' => 'admin@site.com'], 2);
$I->seeEmailIsSent(['subject' => 'XXX', 'from' => 'yyyy']);
janhenkgerritsen commented 8 years ago

Ok, that look's good to me too. I don't know when I have time to implement it yet though.

DavertMik commented 8 years ago

I don't know when I have time to implement it yet though.

Yep, that's always an issue. Maybe someone who accidentally finds oneself here will have a chance to implement it =)

grahamsutton commented 7 years ago

Accidentally found myself here and I am considering implementing this. Is there any documentation on the inner workings of Codeception's email support?

@janhenkgerritsen I can help out if you're still interested in implementing this.

Naktibalda commented 7 years ago

There is no such thing as "Codeception email support", this functionality is module specific.

janhenkgerritsen commented 7 years ago

It would be great if you implement this, because I don't really have the time to do this myself. So if you come up with a nice solution it will definitely get merged :)

grahamsutton commented 7 years ago

@janhenkgerritsen Sounds good! I will start working on it now.

edno commented 5 years ago

@janhenkgerritsen, @grahamsutton - any progress on implementing email assertions? If not, then I'll be happy to try to push something this weekend.