As I previously mentioned we made some effort to better check exceptions. The target is not only ensuring that a various exception is thrown but also that this exception is really the one which is expected. The result was a patch for PHPUnit to test for the exception message (which is already in) and the exception code. As Sebastian mentioned in the PHPUnit 3.2.9 release announcement, the latter is now included too. Therefore a few new options are available.
Example will fail:
<?php
public function testException()
{
$this->setExpectedException('Exception', 'Exception message', 100);
throw new Exception('Invalid message', 10);
}
Example will pass:
<?php
public function testException()
{
$this->setExpectedException('Exception', 'Exception message', 100);
throw new Exception('Exception message', 100);
}
Specifying exception tests with the annotations syntax:
<?php
/**
* @expectedException Exception error message 100
*/
public function testException()
{
throw new Exception('error message', 100);
}
Another attractive new feature is the option to use namespaces as a test organization separators. Until now, the PEAR scheme was used for PHPUnit test (_ becomes the directory separator, .php is auto-attached). This means a test was called My_ObjectTest and was supposed to be located in My/ObjectTest.php. Thanks to a really simple patch the test location stays the same, while the class name might be changed to My::ObjectTest. Happy namespacing.
Filed under PHP, PHPUnit, Unit testing & five comments & no trackbacks
Trackback specific URI for this entry
tobias answers:
published on January 18th 2008, 03:30:20 amThank you very much for the patch about exception codes. I just searched for tests like that 5 days ago ;o)
Reply
Lars Strojny replys:
published on January 18th 2008, 04:25:41 amCredit where credit is due. The harder part, the regex, was done by Sebastian. Just to be clear about that.
Reply
Sebastian Bergmann supposes:
published on January 18th 2008, 08:06:56 amThe regular expression was crafted by Kore Nordmann.
Reply
... answers:
published on February 7th 2008, 07:51:25 amQuesto invece presidente desnudos gays ansa aishwarya ha rai [URL=http://www.diseno-de-casa.trenibuti.info] noi diseno casa de [/URL] accordo.
Reply
glocuntyAllot says:
published on February 8th 2008, 08:46:46 amThe Associated Press, Go to Google News … city have decided to allow a school health center to make birth control pills available to girls as young as 11. ... http://free-order-xanax.100webspace.net/map.html – pharmacy prescription us without xanax , xanax 50 mg
Reply