Testing PHP

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 SPL iterators 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 :

  1. Take a copy of PHP source code

  2. extract this and run ./configure
  3. create a short script to run tests
  4. and another to run the checked out version of PHO
  5. Check the test coverage reports
  6. Find an untested section of code (in red)
  7. Figure out what it does
  8. Write a test to run this part of code
  9. 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:
Extending and Embedding PHP Sara Golemon

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

Tags

Post new comment

Got something to add - just enter a comment
all other fields are optional.

Your email address will not be published.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.