writing a phpt test article

From: Date: Sun, 09 Jul 2006 23:06:07 +0000
Subject: writing a phpt test article
Groups: php.qa 
Request: Send a blank email to php-qa+get-26825@lists.php.net to get a copy of this message
I am currently working on an article about writing phpt tests (been thinking about it for a while and only recently had some time to start it) and would like your input on what it should cover. I don't know yet who (if anyone) will be publishing it - though I am considering asking the ZendDev zone to do it. Worst case scenario - it will go on my blog. Below is what I have currently - it is not completed and a number of sections still need some fleshing out and/or rewording, but it should give you an idea of what I am trying to do. Some parts are currently directly from the doc provided on writing tests. Any and all suggestions and feedback would be appreciated since you will be directly affected by it if anyone chooses to help out. --------------------------------------------------------------- phpt tests So there you sit. A PHP coder who loves PHP. But lately you find yourself wanting to help the PHP community by contributing. Only one problem - you aren't a uber 1337 coder - whether it is because you have only recently started to learn how to program in PHP or you just don't yet have the experience with advanced concepts. But you really want to help out and you are unsure though how to go about doing it. You have looked at the various 'normal' ways of helping out with PHP but nothing seems to fit. Your C coding isn't the best (if you even know how) so helping with the core or PECL is out, nothing in PEAR really 'calls' to you, and you don't know anything about the PHP docs and the software it uses. So where does that leave you. Have no fear there is still a way you can help with PHP - you can help the PHP Quality Assurance team by writing phpt tests. phpt Test Basics * So what are phpt tests? A phpt test is a little script used by the php internal and quality assurance teams to test PHP's functionality. It can be used with new releases to make sure they can do all the things that previous releases can, or to help find bugs in current releases. So by writing phpt tests you are helping to make PHP stabler. * What skills are needed to write a phpt test? All that is really needed to write a phpt test is a basic understanding of the PHP language, a text editor, and a way to get the results of your code. That is it. So if you have been writing and running PHP scripts already - you have everything you need. * What do you write phpt tests on? Basically you can write a phpt test on one of the various php functions available. You can write a test on a basic language function (a string function or an array function) , or a function provided by one of PHP's numerous extensions (a mysql function or a image function or a mcrypt function). You can find out what functions already have phpt tests on them by looking in the html version of the cvs. After that - you can pick any function you want. If you want more guidance than that - you can always ask the PHP Quality Assurance Team on their mailing list (php-qa@lists.php.net) where they would like you to direct your attentions. * How is a phpt test is used? When a test is called by the run-test.php script it takes various parts of the phpt file to name and create a .php file. That .php file is then executed. The output of that .php file is then compared to a different section of the phpt file. If the output of the script "matches" the output provided in the phpt script - it passes. Otherwise there is a problem that the QA team needs to know about. * What should a phpt test do? Basically - it should try and break the PHP function. It should check the functions normal parameters, as well as checking edge cases. Intentionally generating an error is allowed. Writing a phpt test * Naming Conventions - Tests should be named according to the following conventions: Tests for bugs: bug<bugid>.phpt Ex: bug17123.phpt Tests for functions: <functionname>.phpt Ex: dba_open.phpt General tests for extensions: <extname><no>.phpt Ex: dba3.phpt This allows the QA team to easily track what each phpt test checks. * Basic Format A test must at least contain the sections TEST, FILE and either EXPECT or EXPECTF. * Various Optional Sections --SKIPIF--
    is condition when to skip this test.
--POST--
    is POST variable passed to test script.
--GET--
    is GET variable passed to test script.
--INI--
    each line contains an ini setting e.g. foo=bar.
--ARGS--
    a single line defining the arguments passed to php.
--ENV--
    configures the environment to be used for php.
--FILEEOF--
    an alternative to --FILE-- where any trailing line break is omitted. (alternative to --FILE--)
--EXPECTF--
    an alternative of --EXPECT--. The difference is that this form uses sscanf for output validation. (alternative to --EXPECT--)
--EXPECTREGEX--
    an alternative of --EXPECT--. This form allows the tester to specify the result in a regular expression. (alternative to --EXPECT--)
--REDIRECTTEST--
    this block allows to redirect from one test to a bunch of other tests. (alternative to --FILE--)
--HEADERS--
    header to be used when sending the request. Currently only available with server-tests.php
--EXPECTHEADERS--
    the expected headers. Any header specified here must exist in the response and have the same value. Additional headers do not matter.
--CLEAN--
    code that is executed after the test has run. Using run-tests.php switch --no-clean you can prevent its execution to inspect generated data/files that were normally removed after the test.
Examples phpt Tests Submitting a phpt Test --------------------------------------------------------------- Respectfully, Ligaya Turmelle -- life is a game... so have fun.

« previous php.qa (#26825) next »