Beruflich Dokumente
Kultur Dokumente
Chris Shiflett
shiflett@php.net
Geoffrey Young
geoff@modperlcookbook.org
The Code
admin/add.php
<?php include '../functions.inc'; ... if (add_user($_POST['username'], $_POST['password'])) { echo '<p>User Added</p>'; echo '<p><a href="/admin/">Admin Home</a></p>'; } ?>
plan() the number of tests call ok() for each test you plan
or is()$ or like()$ or unlike()$ etc%%%
&ramework keeps track of the results and writes out the report Test nything Protocol "T P#
6
The Test
add_user.php
<?php require 'test-more.php'; require "{$_SERVER['DOCUMENT_ROOT']}/functions.inc"; plan(2); { # no user or password $rc = add_user('', ''); ok (!$rc, 'no user/pass fails'); } { # some generic user/password $rc = add_user('user', 'password'); ok ($rc, 'user/pass successfully added'); # cleanup delete_user('user'); } ?>
8
test-more.php
utomagically generated 'nterface into Apache-Test Pro(ides simple$ intuiti(e functions ok() is() like() Takes care of bookkeeping plan()
9
ok()
Used for boolean comparisons
ok($foo == $bar, '$foo equals $bar');
10
Goodness
)o tests in application code Simple interface *epeatable
tests are self!contained
)o Perl in(ol(ed
Chris particularly likes this aspect
11
Testing 'deology
good testing en(ironment should pro(ide
tools to make writing tests simple a self!contained and pristine en(ironment test automation
12
13
14
15
16
17
18
19
20
Apache-Test
&ramework for testing pache!based application components Part of the httpd-test S& pro-ect pache Pro(ides tools to make testing simple .ritten in Perl
21
pache &oo
pache needs a basic configuration to ser(ice re/uests
ServerRoot DocumentRoot ErrorLog Listen
Apache-Test 0intuits0 these and creates its own httpd.conf Uses an httpd binary you specify
patience$ young grasshopper
22
Cross Pollination
Apache-Test pro(ides a default php.ini
php.ini-recommended
23
Supplement default httpd.conf and php.ini with custom configurations Create t/conf/extra.conf.in
24
extra.conf.in
Same directi(es as httpd.conf Pulled into httpd.conf (ia Include llow for some fancy (ariable substitutions
25
extra.conf.in
AddType application/x-httpd-php .php DirectoryIndex index.php index.html <IfModule @PHP_MODULE@> php_flag register_globals On </IfModule>
26
extra.conf
AddType application/x-httpd-php .php DirectoryIndex index.php index.html <IfModule mod_php5.c> php_flag register_globals On </IfModule>
27
So &ar%%%
.e ha(e
PHP test script "add_user.php# test library "test-more.php# httpd.conf php.ini local o(errides
.e still need
a client to call the PHP script a running ser(er
28
29
31
Makefile.PL
.e still need to create the Makefile
so make test works
pache
32
Cool3
The glory will sink in tomorrow
we hope
PHP de(elopment will ne(er be the same See what happens when a Perl guy and a PHP guy start drinking?
33
Code
ll the code from this presentation can be found here
http://www.modperlcookbook.org/~geoff/slides/ApacheCon/2004/perl-php-test.tar.gz
34
35