The following post was written by Rafael Dohms.
Chances are if you are not out drinking beer at Shirtless Jim’s or at the Chicago Bull game you will be hanging out at the php|tek Hackathon. Aside from all the cool projects present there, one of the easiest to get involved with is testing PHP. This is quite simply the action of creating tests in the PHPT format which run regular PHP function through the drills, can’t get any easier then that.
If this strikes your fancy and you would like to contribute to PHP, its important to come to the Hackathon with your ammunition fully packed, so I’m going to give you a few tips to get you going faster:
Setup your Environment
Running PHPT tests is very easy, you just need to compile PHP from source and run make test. So first thing you should do is download the latest source from the website, and compile it, to make sure you have all of the libraries and everything you need to get to the point where you can run tests, follow these steps:
- wget http://br.php.net/get/php-5.3.6.tar.gz/from/www.php.net/mirror
- tar -xvf php-5.3.6.tar.gz
- cd php-5.3.6
You do not need to run make install, at this point you are perfectly capable of running make test by pointing PHP to your own test directory. Its a good idea to run make install so that you have a working version of the correct PHP release, since PHPT tests are basically PHP code, you can run the test code to copy outputs you can use later testing.
Get to know a bit of PHPT
We will be showing a bit more of this at the hackathon itself, but its a good idea to get used to the PHPT syntax. You can check it out here: phpt. But the basic test has 3 sections, TEST, FILE, EXPECT. This is how a regular testcase looks like:
Hello World Test Description
<?php print ‘Hello World’ ; ?>
TEST is the description of the test, what shows up when you are running it
FILE is the actual code that will be executed by that test. If you run this phpt files as if it were a .php file, this is still actually executed, good debugging.
EXPECT is an assertion, its what the output of the code in FILE will be checked against.
Figure out what you want to test
Once you know how to run tests and how to write them, the next step is to figure out what you want to test. You can pick: write tests for a bug report or select a piece of code that is not covered yet.
If you choose to write tests for a bug, just go to the bug tracker and look for a nice report that you can isolate and replicate in a test, naming convention will be bug[number].phpt
If you choose to cover a piece of un-tested code, then you need to get a little comfortable with C and with the GCOV. The GCOV page basically tells us which lines of code were executed by our regular test suite, this in terms of C not of PHP, so you need to understand a little of the underlying C structure to identify what function that code belongs to and in which scenario its executed. You can then use the naming convention [function-name]_[basic|variation|error+counter].phpt
We will be looking a little closer at this at the testfest. If you want to get more information and dive a little deeper, check out this presentation and they will give you a little more detail on each of these topics, also feel free to ping me on Twitter (@rdohms) with questions, and see you at the Hackathon!