Download the PHP package ingenerator/mailhook without Composer
On this page you can find all versions of the php package ingenerator/mailhook. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ingenerator/mailhook
More information about ingenerator/mailhook
Files in ingenerator/mailhook
Package mailhook
Short Description Collects email from a local postfix server so you can inspect, assert and otherwise mess around with emails sent during development.
License BSD-3-Clause
Homepage https://github.com/ingenerator/mailhook
Informations about the package mailhook
Mailhook
A php library that collects email from a local postfix server so you can inspect, assert and otherwise mess around with emails sent during development.
Installing
Add mailhook to your development dependencies in composer.json:
You will also need to configure postfix to deliver all outbound mail to a local file. If you're using chef, see our
postfix-relay cookbook, and configure the
"postfix_relay.allow_live_email" attribute to false. To install manually, apt-get install postfix
and then append
to your postfix configuration as follows.
Using mailhook to inspect messages
Obviously you'd usually use mailhook inside a test framework of some kind (Behat, for example). But this very simple example should give you an idea of how you can use it:
Getting more detail
You probably want to know more than just that an email with some content was sent to some user. For example, you might want to assert that an email was sent to a specific user. For this, you can use the matching/assertion framework built into the package:
These assertion methods throw an exception if they fail, or return the matching email(s) if they succeed. You can add your own custom criteria by implementing the EmailMatcher interface and providing an instance of the class.
You can pass multiple matchers to assert that an email matching all the criteria was sent. For example, if you were testing the common "password reset email" feature you could do something like:
Testing and developing
mailhook has a suite of PhpSpec specifications. Run them with bin/phpspec run
. Contributions
will only be accepted if they are accompanied by well structured specs. Installing with composer should get you
everything you need to work on the project.
License
mailhook is copyright 2012-2014 inGenerator Ltd and released under the BSD license.