20
Writing PHP Tests PHPNW TestFest 2009 Wednesday, 27 May 2009

How to write PHPT tests

Embed Size (px)

Citation preview

Page 1: How to write PHPT tests

Writing PHP TestsPHPNW TestFest 2009

Wednesday, 27 May 2009

Page 2: How to write PHPT tests

Goals

Increase test coverage in PHP

Win an elePHPant

Have Fun

Beat London

Cheat if we have to

Wednesday, 27 May 2009

Page 3: How to write PHPT tests

Preparation

Grab gcc, autotools, flex-old, bison

Make your directory ~/testfest

Wednesday, 27 May 2009

Page 4: How to write PHPT tests

Snapshot

CVS Checkout

Snapshot (snaps.php.net)

Windows Snapshot (windows.php.net/snapshots/)

Wednesday, 27 May 2009

Page 5: How to write PHPT tests

Windows

run-tests.php

PHP 5.3 http://short.ie/yui3db

PHP 5.2 http://short.ie/zm5vwb

Relax

Wednesday, 27 May 2009

Page 6: How to write PHPT tests

Building

cd ~/testfest

./configure --disable-all --enable-spl

make / make -j3

Wednesday, 27 May 2009

Page 7: How to write PHPT tests

Checking it worked

sapi/cli/php -v

make test (takes a while)

Submit a report

Wednesday, 27 May 2009

Page 8: How to write PHPT tests

Running Selective Tests

run run-tests.php manually

set TEST_PHP_EXECUTABLE

Wednesday, 27 May 2009

Page 9: How to write PHPT tests

Demo

Wednesday, 27 May 2009

Page 10: How to write PHPT tests

What makes a phpt?

Small Collection of PHP Scripts

Separated by section markers

TEST, FILE, EXPECT

Wednesday, 27 May 2009

Page 11: How to write PHPT tests

phpt bits--TEST--

Description of the test

--FILE--

Contents is passed to PHP

--EXPECT--

The expected output

Wednesday, 27 May 2009

Page 12: How to write PHPT tests

A simple phpt

Wednesday, 27 May 2009

Page 13: How to write PHPT tests

Other sections

--CREDITS--

--SKIPIF--

--EXPECTF--

Wednesday, 27 May 2009

Page 15: How to write PHPT tests

SPL

Standard PHP Library

Solves Common Problems

Data structures, algorithms, iterators

Wednesday, 27 May 2009

Page 16: How to write PHPT tests

SPL Documentation

http://php.net/~helly/

http://uk2.php.net/spl

Wednesday, 27 May 2009

Page 17: How to write PHPT tests

Our Goals

Write a simple basic test

Write a test for SPLFixedArray, SPLDoublyLinkedList

Look at some iterator tests

Wednesday, 27 May 2009

Page 18: How to write PHPT tests

SVN Checkout

SVN Command Line

Tortoise SVN

Versions on OSX

http://testfest.php.net/repos/testfest/NorthWestUG/

Wednesday, 27 May 2009

Page 19: How to write PHPT tests

Run testSVN: http://testfest.php.net/repos/testfest/NorthWestUG/

Linux: export TEST_PHP_EXECUTABLE=/path/to/checkout/sapi/cli/php

Windows: set TEST_PHP_EXECUTABLE=c:\path\to\php.exe

php run-tests.php /path/to/svntestfest/ext/spl/tests

Wednesday, 27 May 2009