smartcoderx
smartcoderx

Reputation: 1081

Implement unit test for sending contact mails

I have a contact controller which render my contact form and validate the request. After validation success the contact controller create a Contactobject and call the method proceedContact from ContactHandler. Now i would like to write a phpunit test for my handler. It's my first unit test. I have following questions.

Upvotes: 0

Views: 73

Answers (1)

chalasr
chalasr

Reputation: 13167

This kind of logic (email sending) should not be done in an Entity.

You should create a service instead, or create a method in the corresponding controller.

Also, when the architecture of your logic is ok, to deal with the service container in your tests, see the corresponding part of the documentation.

See also this very good article about using Dependency Injection in tests.

And, to send e-mail from your tests (more functional than unit in this case), see E-mail testing.

Try to use this informations to build your test, and if you encounter difficulties, ask a precise question for a precise problem here.

Upvotes: 1

Related Questions