Jason
Jason

Reputation: 14615

PHPUnit alert on failure, by email or text?

My website has an API, which essentially is a data scraping API for a number of sites. If any of the other sites change, my API breaks. I need my API to be as stable as possible, and if it breaks I need to update it as quickly as possible.

In order to ensure that it is working properly, I have written a suite of PHPUnit tests which ensure that it is working as expected.

I'd like these tests to run periodically, maybe once a day, perhaps more frequently depending of how resource-intensive they are. I could set up a cron job which runs PHPUnit every so often, and I'd like to be alerted, either by email or text, when any of the PHPUnit tests fails, so I can fix the API promptly. As far as I can tell, there are no options for doing this in PHPUnit itself which is a shame. What is the best way to set this up?

Upvotes: 0

Views: 2066

Answers (4)

james
james

Reputation: 3583

Simplest solution would be to run the tests in a cron job and pipe the output to your email address.

Check the article and scroll to the section about emailing the CRON JOB.

Upvotes: 1

edorian
edorian

Reputation: 38961

To provide some more resources:

For setting up a CI (continuous integration) Server (the thing that runs your tests) I'd strongly suggest taking a look at jenkins-php.org.

From my personal experience Jenkins is way easier to get running and to work with compared to phpundercontrol. Also more stable and actively developed.

Jenkins has a ton of Plugins that can do any sort of notification for you if you don't want to "just get an email" but a instant message or a irc message for example.

It's darn easy to set up (self promotion) way less trouble to administrate/maintain and "just works" for pretty much any use case.

Upvotes: 2

netcoder
netcoder

Reputation: 67715

Get yourself a nice little continuous integration environment. I use CruiseControl. You can also use it with phpUnderControl (which I personally don't use because of the variety of languages I'm coding in).

You can automate builds using Apache Ant (or Phing, if you really want a PHP solution). You can setup emails, unit testing, automated nightlies, etc.

Just make sure to use the JUnit logging format in PHPUnit (--log-junit switch).

Upvotes: 1

dogmatic69
dogmatic69

Reputation: 7585

you should be using something like hudson / jenkins that preforms the tests when the code is changed. eg using pre/post commit hooks of your favourite source control app.

This way you wont ever have broken code deployed (with capistrano) to a live server.

http://hudson-ci.org/

http://jenkins-ci.org/

https://github.com/capistrano/capistrano/wiki

As for emailing when there are errors, there is some code like that around. There is a CakePHP plugin that you could use/port or get ideas from

https://github.com/joebeeson/referee

Upvotes: 3

Related Questions