Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHP Testfest 2009: How to write PHP tests

PHP Testfest 2009: How to write PHP tests

Slides created by Sebastian Schürmann for PHP TestFest 2009.

More details: https://wiki.php.net/qa/testfesttalk

PHP Community

May 01, 2009
Tweet

More Decks by PHP Community

Other Decks in Programming

Transcript

  1. Content • facts about phptestfest & phpt • Build Process

    & Setup • Executing & Coverage • Sections of a .phpt file
  2. What is phpt ? • a way to check PHP‘s

    functions • PHP Code • Self contained • input - output check
  3. • basically php script + output to evaluate • .ini,

    GET, POST etc. can be set • different ways to evaluate output Sections of a .phpt file
  4. --TEST-- • Documentation section • name the function you are

    testing • describe the test case • if testing bugs, add the bugid
  5. --CREDITS-- • for people without CVS accounts • name and

    email • (optional) testfest event and date
  6. --FILE-- • the code goes here • open with <?php

    and close with ?> • make it output something
  7. --EXPECT-- • compares ouput of script to given string •

    take care: paths will differ go for --EXPECTF--
  8. --EXPECTF-- • uses palceholders like scanf • %s for strings

    (e.g. path) • %r...%r - regex • !! Multinline
  9. --EXPECTREGEX-- • Use a regular Expression to check on output

    • A simple way for certain things • Check EXPECTF for a simpler version
  10. --GET-- --POST-- • sets get and pots values • uses

    the CGI binary instead of the CLI
  11. --SKIPIF-- • do NOT execute the test under certian conditions

    • OS based Test • 32 bit vs. 64 bit
  12. • Test only one function at a time • Change

    only one parameter • Check only one result ONE!
  13. selfcontained • keep testdata in the test • avoid external

    files if possible • document what you try to achieve
  14. CREDITS IMAGES • http://www.flickr.com/photos/zach_manchester/2589742713/ Zach Rathore • http://farm1.static.flickr.com/4/9261879_e5c2340937_o.jpg http://www.duncancumming.co.uk/ •

    http://www.flickr.com/photos/firewarrior/180546141/sizes/l/ http://www.flickr.com/people/firewarrior/ • http://www.flickr.com/photos/fredericksburg/3085671440/sizes/o/ http://www.flickr.com/people/fredericksburg/ • http://www.flickr.com/photos/ajax/164119589/sizes/l/ http://www.flickr.com/people/ajax/ • http://www.flickr.com/photos/thowi/26609866/sizes/l/ http://www.flickr.com/photos/thowi/ • http://www.flickr.com/photos/radiofree/475730956/sizes/l/ http://www.flickr.com/people/timwilson/
  15. CREDITS IMAGES II • http://www.flickr.com/photos/tashland/259178493/sizes/o/ http://www.flickr.com/people/tashland/ • http://www.flickr.com/photos/tracyleephoto/2925320390/sizes/o/ http://www.flickr.com/photos/tracyleephoto/ •

    http://www.flickr.com/photos/danielle_scott/2410922192/sizes/l/ http://www.flickr.com/people/danielle_scott/ • http://www.flickr.com/photos/beckzaidan/1218151329/sizes/o/ http://www.flickr.com/photos/beckzaidan/ • http://www.flickr.com/photos/bz3rk/3358291041/ credited to James WIllamor CLTblog.com.