Apache-Test for the php CLI

geoff on 2005-01-28T03:04:31

UPDATE:you might find this all confusing if you haven't heard about our Apache-Test efforts yet and how it joins PHP and Perl together in the testing world. take a look at the talk Chris and I gave at ApacheCon 2004:

now, back to the blog...



today I added the ability to run client-side PHP scripts to Apache-Test. so, now you can have

  t/foo.t
  t/bar.php
  t/response/TestPHP/baz.php


all within the same t/ directory.

the perl script t/foo.t will run using perl, just like always. t/bar.php will run using the php command-line interpreter, while t/response/TestPHP/baz.php will run via PHP within the Apache runtime (through standard Apache-Test magic). and all are executed with a simple make test and tabulated on the command line like you would expect.



furthermore, the test-more.php that Apache-Test generates can be automatically found from the client-side tests as well. so, here is what a sample t/foo.php looks like:


plan(1); diag("this is a php test"); is('php', 'perl', "something php passed"); ?>


look familiar? so does the output...

$ make test TEST_VERBOSE=1
/perl/perl-5.8.6/bin/perl -Iblib/arch -Iblib/lib \
t/TEST  -clean
APACHE_TEST_GROUP= APACHE_TEST_HTTPD= APACHE_TEST_PORT= APACHE_TEST_USER= APACHE_TEST_APXS= \
/perl/perl-5.8.6/bin/perl -Iblib/arch -Iblib/lib \
t/TEST  -bugreport -verbose=1 t/foo.php t/foo.t
/usr/local/apache/bin/httpd  -d /src/devel/perl-php-test/t -f /src/devel/perl-php-test/t/conf/httpd.conf -D APACHE1 -D PERL_USEITHREADS
using Apache/1.3.32
 
waiting 60 seconds for server to start: ..
waiting 60 seconds for server to start: ok (waited 1 secs)
server localhost.localdomain:8529 started
t/foo....1..1
# this is a php test
not ok 1 - something php passed
#     Failed test (t/foo.php at line 9)
#          got: 'php'
#     expected: 'perl'
# Looks like you failed 1 tests of 1.
FAILED test 1
        Failed 1/1 tests, 0.00% okay
t/foo....1..1
# this is a perl test
not ok 1 - something perl passed
 
#     Failed test (t/foo.t at line 7)
#          got: 'php'
#     expected: 'perl'
# Looks like you failed 1 test of 1.
dubious
        Test returned status 1 (wstat 256, 0x100)
DIED. FAILED test 1
        Failed 1/1 tests, 0.00% okay
Failed Test Stat Wstat Total Fail  Failed  List of Failed
-------------------------------------------------------------------------------
t/foo.t        1   256     1    1 100.00%  1
t/foo.php                  1    1 100.00%  1
Failed 2/2 test scripts, 0.00% okay. 2/2 subtests failed, 0.00% okay.


hard to tell which is Test::More and which is test-more.php isn't it?



I find it interesting that in a very large testing framework here at work we use a mixture of *.t tests that have nothing to do with mod_perl or Apache, yet we just let Apache-Test run everything for convenience. now, PHP users can do the same - code PHP clients to talk to their PHP web app using Test::More syntax, or just use Apache-Test as the engine for their CLI scripts:

$ t/TEST -no-httpd t/foo.php  -v
[warning] skipping httpd configuration
t/foo....1..1
# this is a php test
not ok 1 - something php passed
#     Failed test (t/foo.php at line 5)
#          got: 'php'
#     expected: 'perl'
# Looks like you failed 1 tests of 1.
FAILED test 1
        Failed 1/1 tests, 0.00% okay
Failed Test Stat Wstat Total Fail  Failed  List of Failed
-------------------------------------------------------------------------------
t/foo.php                  1    1 100.00%  1
Failed 1/1 test scripts, 0.00% okay. 1/1 subtests failed, 0.00% okay.