开发者

PHPUnit alert on failure, by email or text?

My website has an API, which essentially is a data scraping API for 开发者_JAVA百科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?


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


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.


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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜