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

C343c439f0c144f0d63a0de256c82f79?s=128

PHP Community

May 01, 2009
Tweet

Transcript

  1. 2.

    Content • facts about phptestfest & phpt • Build Process

    & Setup • Executing & Coverage • Sections of a .phpt file
  2. 4.
  3. 9.
  4. 13.

    What is phpt ? • a way to check PHP‘s

    functions • PHP Code • Self contained • input - output check
  5. 14.
  6. 19.
  7. 20.
  8. 21.
  9. 27.
  10. 28.

    • cvs -d :pserver:cvsread@cvs.php.net:/repository login • password: phpfi • cvs

    -d :pserver:cvsread@cvs.php.net:/repository checkout -r PHP_5_3 php5
  11. 29.
  12. 38.

    • basically php script + output to evaluate • .ini,

    GET, POST etc. can be set • different ways to evaluate output Sections of a .phpt file
  13. 40.

    --TEST-- • Documentation section • name the function you are

    testing • describe the test case • if testing bugs, add the bugid
  14. 41.

    --CREDITS-- • for people without CVS accounts • name and

    email • (optional) testfest event and date
  15. 42.

    --FILE-- • the code goes here • open with <?php

    and close with ?> • make it output something
  16. 43.

    --EXPECT-- • compares ouput of script to given string •

    take care: paths will differ go for --EXPECTF--
  17. 44.
  18. 45.

    --EXPECTF-- • uses palceholders like scanf • %s for strings

    (e.g. path) • %r...%r - regex • !! Multinline
  19. 46.

    --EXPECTREGEX-- • Use a regular Expression to check on output

    • A simple way for certain things • Check EXPECTF for a simpler version
  20. 47.

    --GET-- --POST-- • sets get and pots values • uses

    the CGI binary instead of the CLI
  21. 48.

    --SKIPIF-- • do NOT execute the test under certian conditions

    • OS based Test • 32 bit vs. 64 bit
  22. 56.

    • Test only one function at a time • Change

    only one parameter • Check only one result ONE!
  23. 57.

    selfcontained • keep testdata in the test • avoid external

    files if possible • document what you try to achieve
  24. 58.
  25. 59.

    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/
  26. 60.

    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.