Sebastian Bergmann as a new post talking about a few of the features of the PHPUnit unit testing framework, especially test isolation.
Some of PHPUnit features come with the cost of a performance penality. This posting explores the effect of the --no-syntax-check, $backupGlobals = FALSE;, and --coverage-html options.
He compares benchmarks for a test with few different settings - $GLOBALS, syntax check and code coverage (including graphical output of the execution times on the various parts of the tests).
In looking to test his fputscsv functionality, David Otton found a simple way to measure its performance by using streams.
Then I realised I could use PHP's (fairly) new IO streams to dump the function's output to a temporary buffer, and read it back in for comparison. Not perfect, but it removes concerns about file mutexes, permissions, unique filenames, etc. and speeds up the tests, as they never touch disc.
He uses a custom stream and points it to php://memory to store and read the data from. Code is included in the post as well as example usage. It runs an assert that the value pushed into another memory chunk is the same as the first one (ensuring that the results of his fputcsv calls are valid).
When it comes to code coverage and untested parts of your application (unit tested, of course), Zoe Slatteryhas a suggestion that could make your life easier anyway - follow the core PHP developer's example:
But - there is another way, and as usual the PHP core developers are showing us the way. The fastest way to improve percentage of code covered is to REMOVE UNTESTED CODE! Accordingly we saw the test coverage of PHP 5.3 increase from about 55% to a little over 70% over the summer of 2008. At the same time the lines of code in PHP dropped by about 50KLOC. How can this be?
Removing untested code (that's not needed anyway) can reduce unit testing times dramatically and can help you keep your code clean, lean and simple for the upgrades that will come later on.
Sebastian Bergmann talks about a new bit of functionality he's put into the 3.4 release of PHPUnit (the popular unit testing tool for PHP) based on a suggestion from a paper he'd read:
The feature is a system that helps localize problems at the source, stripping away all of the cascading issues it might have tripped off, causing other tests to fail. This new feature (as illustrated by his code example using a DependencyFailureTest class) makes it simple to fail a test immediately whenever the scripts needs to via a fail() method. Check out the full post for the rest of the code and some further explanation on how it works.
Brian Moon has released a simple blogging application he's worked up - a super-simple, lightweight application that already has several of the common blog features built in.
Up until now, I have used Wordpress.com for my blogging. It works quite well. You can get started quite quickly and it does what most people need. My wife uses Blogger for our family blog. It is, IMO, not as nice as Wordpress.com in some ways. But, it does allow you to edit your styles (for free) and such which is nice. So, why would I want to reinvent the wheel? I am a control freak and rarely run other people's code. I know, it is a character flaw. I am working on it.
His application, WordCraft, already includes things like Akismet/CAPTCHA support for comments, custom page creation, pingback support, temlpating and email notifications. You can download the latest release (version 0.5) from his google code page.
Pierre-Alain Joye has pointed out that the latest release candidate of the PHP 5.2.x series (5.2.7RC3) has been posted for download.
PHP 5.2.7RC3 has been released. It is likely to be the last RC and the final release is planed for Thursday next week. Please test it and report any issue you may found. The sources can be fetched here and the binaries in the windows site.
The ProDevTips site continues their look at using Doctrine in PHP with this latest article in the series that adds in a simple, automatic CRUD system to the application.
I just found myself wishing for automatic CRUD, for quick and simple administrative tasks, as it turned out a very easy thing to add.
They create a model for their Company table and a new controller to handle the admin requests. Throw in some fetching functions, a bit of form handling and a bit of Smarty login and you have a simple admin form that automatically creates itself based on the columns in the table.
In this article we will look at the protocol that is involved in sending email messages. We will also examine the thorny issue of how to send an attachment with an email message. This article is the second of two parts.
They include examples of sending simple messages and more complex ones with things like attachments and custom headers. They also tack on a look at the PEAR::Mail package to the end showing how it can make sending some things a little less painful.
In a new post to his blog Matthew Weier O'Phinney talks about using the Zend_Test component of the Zend Framework to set up test suites on your application.
Testing and test automation should be easy and the complex approach is overkill for most of our applications. Fortunately, PHPUnit offers some other methods that make doing so relatively simple. The easiest method is to use an XML configuration file.
He includes a basic XML config file for a "My Test Suite" setup defining the application's directory and where to log the end report to. This simple PHPUnit configuration can be used with the "phpunit" command line binary to auto-configure all you'll need for the testing. Matthew also includes the code for a sample TestHelper you can drop right into the app to help set up your environment correctly when testing is needed.
In a recent blog postZoe Slattery took a look at opcodes in PHP, specifically related to performance increases.
After one particularly frustrating day [looking at how the Zend engine works] I asked a colleague (Andy Wharmby) about the issue I was looking at. Then a miracle happened - he'd not only looked at it but had documented it (and many other things) in a set of charts.
She has linked to the charts (Open Office format) for the results of some tests her friend had already run. They're a bit out of date and some parts might be inaccurate, but they're still a good start.