How to write PHPT tests

Post on 18-May-2015

1.166 views 3 download

Tags:

Transcript of How to write PHPT tests

Writing PHP TestsPHPNW TestFest 2009

Wednesday, 27 May 2009

Goals

Increase test coverage in PHP

Win an elePHPant

Have Fun

Beat London

Cheat if we have to

Wednesday, 27 May 2009

Preparation

Grab gcc, autotools, flex-old, bison

Make your directory ~/testfest

Wednesday, 27 May 2009

Snapshot

CVS Checkout

Snapshot (snaps.php.net)

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

Wednesday, 27 May 2009

Windows

run-tests.php

PHP 5.3 http://short.ie/yui3db

PHP 5.2 http://short.ie/zm5vwb

Relax

Wednesday, 27 May 2009

Building

cd ~/testfest

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

make / make -j3

Wednesday, 27 May 2009

Checking it worked

sapi/cli/php -v

make test (takes a while)

Submit a report

Wednesday, 27 May 2009

Running Selective Tests

run run-tests.php manually

set TEST_PHP_EXECUTABLE

Wednesday, 27 May 2009

Demo

Wednesday, 27 May 2009

What makes a phpt?

Small Collection of PHP Scripts

Separated by section markers

TEST, FILE, EXPECT

Wednesday, 27 May 2009

phpt bits--TEST--

Description of the test

--FILE--

Contents is passed to PHP

--EXPECT--

The expected output

Wednesday, 27 May 2009

A simple phpt

Wednesday, 27 May 2009

Other sections

--CREDITS--

--SKIPIF--

--EXPECTF--

Wednesday, 27 May 2009

SPL

Standard PHP Library

Solves Common Problems

Data structures, algorithms, iterators

Wednesday, 27 May 2009

SPL Documentation

http://php.net/~helly/

http://uk2.php.net/spl

Wednesday, 27 May 2009

Our Goals

Write a simple basic test

Write a test for SPLFixedArray, SPLDoublyLinkedList

Look at some iterator tests

Wednesday, 27 May 2009

SVN Checkout

SVN Command Line

Tortoise SVN

Versions on OSX

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

Wednesday, 27 May 2009

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