Prepare for PHP Test Fest 2009
Upcoming SlideShare
Loading in...5
×
 

Prepare for PHP Test Fest 2009

on

  • 4,661 views

This presentation is a preparation for PHP Test Fest 2009 (http://qa.php.net/testfest). See your local PHP user group for details of this world wide event.

This presentation is a preparation for PHP Test Fest 2009 (http://qa.php.net/testfest). See your local PHP user group for details of this world wide event.

Statistics

Views

Total Views
4,661
Views on SlideShare
4,652
Embed Views
9

Actions

Likes
2
Downloads
27
Comments
0

1 Embed 9

http://www.slideshare.net 9

Accessibility

Upload Details

Uploaded via as Apple Keynote

Usage Rights

CC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Prepare for PHP Test Fest 2009 Prepare for PHP Test Fest 2009 Presentation Transcript

  • Preparing for PHP TestFest 2009 by Felix De Vliegher and Michelangelo van Dam
  • Welcome to PHP Test Fest 2009 ! • What is PHP Test Fest ? – improving code coverage of the PHP interpreter by writing tests – opportunity to learn how to write tests in a group/ workshop like environment – your chance to contribute back to the PHP community ! 2
  • Prerequisites • preferable a Linux version – virtual machine – core OS • with gcc and gcov (see next slide for details) • for testing coverages – gcov – lcov (version 1.5 or 1.6) • php 5.3 – from CVS (see next slide) • text editor like vi(m), textpad, pico, ... 3
  • Tools needed for PHP builds • gcc: 3.4+ (with gcov) Source: http://wiki.php.net/doc/articles/writing-tests • autoconf: 2.13 • automake: 1.4+ • libtool: 1.4.x+ (except 1.4.2) • bison: 1.28, 1.35, 1.75, 2.0 or higher • flex: 2.5.4 (not higher) • re2c: 0.9.11+ (0.12.0+ for HEAD) Source: http://www.php.net/anoncvs.php 4
  • Getting lcov • apt – apt-get install lcov • CSV – cvs - d:pserver:anonymous@ltp.cvs.sourceforge.net:/ cvsroot/ltp login – cvs -z3 - d:pserver:anonymous@ltp.cvs.sourceforge.net:/ cvsroot/ltp co -r LCOV_1_6 -P utils/analysis/lcov • RPM – lcov-1.6-2.noarch.rpm 5
  • Getting the latest PHP 5.3 Choose a development environment $ cd ~/src/php/ $ cvs -d :pserver:cvsread@cvs.php.net:/repository checkout - r PHP_5_3 php5 $ cd php5 Build a configure for your current version $ ./buildconf Run the configuration $ ./configure --enable-gcov choose --enable-gcov for code coverage reporting make & make test & make lcov $ make $ make test $ make lcov TESTS=tests/* 6
  • Code coverage report http://gcov.php.net or in your /path/to/php5/lcov_html directory 7
  • Writing Tests • What are phpt Tests ? Files ending with .phpt are test files containing a single test • What skills do I need to write phpt tests ? – basic knowledge of PHP – a text editor like vi(m), pico, notepad, textpad, ... – a way to get results of your test code • Where can I find more info about phpt ? http://phpt.info 8
  • Naming conventions • Tests for bugs – bug<bugid>.phpt (bug17123.phpt) • Tests for a function’s basic behaviour – <functionname>_basic.phpt (dba_open_basic.phpt) • Tests for a function’s error behaviour – <functionname>_error.phpt (dba_open_error.phpt) • Tests for variations in a function’s behaviour – <functionname>_variation.phpt (dba_open_variation.phpt) • General tests for extensions – <extname>_<no>.phpt (dba_003.phpt) 9
  • Basic format --TEST-- Hello World --FILE-- Hello World --EXPECT-- Hello World 10
  • Test, File and Expect --TEST-- Hello World --FILE-- <?php echo ‘Hello World’; ?> --EXPECT-- Hello World 11
  • Testing Errors --TEST-- Hello World --FILE-- <?php echo ‘Hello World --EXPECTF-- Parse Error: syntax error, unexpected $end in %s.php on line %d 12
  • Testing Errors with expectregex --TEST-- Hello World --FILE-- <?php echo ‘Hello World --EXPECTREGEX-- Parse Error: (parse|syntax) error, unexpected $end in .* ON .* 13
  • Cleaning up --TEST-- This will remove temporary files --FILE-- <?php $temp_filename = dirname(__FILE__) . '/foo.tmp'; $fp = fopen($temp_filename, 'w'); fwrite($fp, 'bar'); fclose($fp); ?> --CLEAN-- <?php $temp_filename = dirname(__FILE__) . '/foo.tmp'; unlink($temp_filename); ?> --EXPECT-- 14
  • Conditional Testing --TEST-- Check for 64bit platform --SKIPIF-- <?php if (PHP_INT_SIZE != 8) die('64bit platforms only'); ?> --FILE-- --EXPECT-- 15
  • Don’t forget the credits --TEST-- A test with a CREDITS section --CREDITS-- John Doe <john.doe@example.com> #testfest PHPBelgium 2009-05-09 --FILE-- --EXPECT-- 16
  • Running your test make test TESTS=/path/to/php5/ext/yourextension/tests 17
  • Resources • TestFest http://qa.php.net/testfest.php • PHP Quality Assurance Team http://qa.php.net/ • PHP: Test and Code Coverage Analysis http://gcov.php.net/ • Complete ./configure example http://gcov.php.net/viewer.php? version=PHP_5_3&func=system 18
  • Let PHP Test Fest begin ! Thank you for your interest ! Your work will be appreciated !!! Slides are available on http://www.slideshare.net/PHPBelgium 19
  • Proudly sponsored 20