News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

PHPMaster.com:
Testing Error Conditions with PHPUnit
October 02, 2012 @ 11:57:40

Over on PHPMaster.com there's a new post for the unit testers in the audience (you all unit test, right?) from Matt Turland about testing error conditions in your applications.

Let's say you're maintaining code that uses PHP's native trigger_error() function to log error information. Let's also say that you're in the process of using PHPUnit to write unit tests for that code. If you refer to the PHPUnit manual, there's a section that deals with testing for error condition. [...] However, depending on what your code looks like, it's possible that you'll run into a problem with PHPUnit's approach to this. This article will detail what this problem is, how it impacts your ability to test your code, and how to go about solving it.

He points out that, since errors and exceptions handle differently, you have to work with them differently in your tests. PHPUnit has a feature that automatically turns errors into a specific type of exception when they're thrown and how, by using a simple custom error handler, you can more correctly tests error vs exception.

0 comments voice your opinion now!
unittest error exception phpunit tutorial handler custom


blog comments powered by Disqus

Similar Posts

Benjamin Eberlei's Blog: Trying a Two Step PEAR/PHAR approach to develop and deploy

MaltBlue.com: Zend Framework - How To Implement RSS Feeds the Easy Way

Matthew Weier O'Phinney: RESTful APIs with ZF2, Part 2

Vid Luther's Blog: Installing the PHP SSH2 extension in Snow Leopard (10.6)

Rob Morgan's Blog: Howto Log Directly to Your OS X Terminal using Zend Framework and NodeJS


Community Events





Don't see your event here?
Let us know!


interview list voicesoftheelephpant deployment laravel series community framework podcast install language release introduction symfony library bugfix package opinion api tips

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework