I had fun this weekend at the PHP London Test Fest, it was a great opportunity to learn something new and meet some great programmers.
The tests our team took on were based around the SPLiterators I hadn’t used this part of PHP before and it was a great way to learn about it, especially as many of the functions we tested aren’t documented yet.
What we did was :
Take a copy of PHP source code
extract this and run ./configure
create a short script to run tests
and another to run the checked out version of PHO
Check the test coverage reports
Find an untested section of code (in red)
Figure out what it does
Write a test to run this part of code
go to 5
More details on how to write tests are at http://qa.php.net/write-test.php
I found the hardest bit was interpreting the C source code of PHP - this was made much easier by the mentors at the test fest, and once pointed in the right direction we were able to get going easily enough.
This does give me another reason to read this book:
One thing I didn’t figure out on the day - in order to regenerate the coverage reports and check that the new tests do add coverage I needed to
aptitude install lcov make lcov TESTS=./path-to tests
NB you can either run all tests or just a subdirectory
The script to run tests was
#!/bin/bash export TEST_PHP_EXECUTABLE=/path-to/php5.3-200905081030/sapi/cli/php $TEST_PHP_EXECUTABLE /path-to/php5.3-200905081030/run-tests.php $*
I also created an alias to
sapi/cli/php so that I could run the tests as simple PHP scripts