News Feed
Sections




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

PHP and Me Blog:
How to Type Less $this in PHPUnit
March 10, 2011 @ 13:25:51

In a recent post to the "PHP and Me" blog they look at how to type less $this in your PHPUnit tests using some handy tricks and a bit of custom code.

Lately I've been writing a few tests (using PHPUnit), and when you do there's one thing you end up doing a lot, which is typing $this-> whenever you need to do pretty much anything. It's not that bad (and PHP can be quite verbose itself) but it can become a bit of a bore I guess, especially after a while. [...] Those were valid points [about the global testing functions added to PHPUnit], and for a while that feature was even temporarily removed. So.. now what? Back to typing all those $this-> over & over again? Maybe not.

The post shows how to use the included functions to remove the "$this" in something like "$this->assertTrue()" or, to reduce things even more and not pollute the global namespace, a different approach by extending Assert. A few code examples are included as well as the class that extends the normal Assert functionality PHPUnit provides. It allows for the more flexible short-hand function calls to automatically be mapped back to their "more correct" versions.

0 comments voice your opinion now!
phpunit global method assert namespace


blog comments powered by Disqus

Similar Posts

DZone.com: PHP Tool Integration (PHPsrc)

Greg Beaver's Blog: Working towards Pyrus and PEAR2, check it out or miss out

Sebastian Bergmann's Blog: Zend/PHP Conference 2006

VG Tech: Using PHP's Built-in Web Server in Your Test Suites

Matthias Noback: Test Symfony2 commands using the Process component and asynchronous assertions


Community Events





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


tips interview zendserver bugfix language release api conference introduction community series code podcast deployment symfony list framework threedevsandamaybe voicesoftheelephpant laravel

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