1Apache::TestRunPHP(3) User Contributed Perl DocumentationApache::TestRunPHP(3)
2
3
4
6 Apache::TestRunPHP - configure and run a PHP-based test suite
7
9 use Apache::TestRunPHP;
10 Apache::TestRunPHP->new->run(@ARGV);
11
13 The "Apache::TestRunPHP" package controls the configuration and running
14 of the test suite for PHP-based tests. It's a subclass of
15 "Apache::TestRun" and similar in function to "Apache::TestRunPerl".
16
17 Refer to the "Apache::TestRun" manpage for information on the available
18 API.
19
21 "TestRunPHP" works almost identially to "TestRunPerl", but in case you
22 are new to "Apache-Test" here is a quick getting started guide. be
23 sure to see the links at the end of this document for places to find
24 additional details.
25
26 because "Apache-Test" is a Perl-based testing framework we start from a
27 "Makefile.PL", which should have the following lines (in addition to
28 the standard "Makefile.PL" parts):
29
30 use Apache::TestMM qw(test clean);
31 use Apache::TestRunPHP ();
32
33 Apache::TestMM::filter_args();
34
35 Apache::TestRunPHP->generate_script();
36
37 "generate_script()" will create a script named "t/TEST", the gateway to
38 the Perl testing harness and what is invoked when you call "make test".
39 "filter_args()" accepts some "Apache::Test"-specific arguments and
40 passes them along. for example, to point to a specific "httpd" instal‐
41 lation you would invoke "Makefile.PL" as follows
42
43 $ perl Makefile.PL -httpd /my/local/apache/bin/httpd
44
45 and "/my/local/apache/bin/httpd" will be propagated throughout the rest
46 of the process. note that PHP needs to be active within Apache prior
47 to configuring the test framework as shown above, either by virtue of
48 PHP being compiled into the "httpd" binary statically or through an
49 active "LoadModule" statement within the configuration located in
50 "/my/local/apache/conf/httpd.conf". Other required modules are the
51 (very common) mod_alias and mod_env.
52
53 now, like with "Apache::TestRun" and "Apache::TestRunPerl", you can
54 place client-side Perl test scripts under "t/", such as "t/01basic.t",
55 and "Apache-Test" will run these scripts when you call "make test".
56 however, what makes "Apache::TestRunPHP" unique is some added magic
57 specifically tailored to a PHP environment. here are the mechanics.
58
59 "Apache::TestRunPHP" will look for PHP test scripts in that match the
60 following pattern
61
62 t/response/TestFoo/bar.php
63
64 where "Foo" and "bar" can be anything you like, and "t/response/Test*"
65 is case sensitive. when this format is adhered to, "Apache::TestRun‐
66 PHP" will create an associated Perl test script called "t/foo/bar.t",
67 which will be executed when you call "make test". all "bar.t" does is
68 issue a simple GET to "bar.php", leaving the actual testing to
69 "bar.php". in essence, you can forget that "bar.t" even exists.
70
71 what does "bar.php" look like? here is an example:
72
73 <?php
74 print "1..1\n";
75 print "ok 1\n"
76 ?>
77
78 if it looks odd, that's ok because it is. I could explain to you
79 exactly what this means, but it isn't important to understand the gory
80 details. instead, it is sufficient to understand that when
81 "Apache::Test" calls "bar.php" it feeds the results directly to
82 "Test::Harness", a module that comes with every Perl installation, and
83 "Test::Harness" expects what it receives to be formated in a very spe‐
84 cific way. by itself, all of this is pretty useless, so "Apache::Test"
85 provides PHP testers with something much better. here is a much better
86 example:
87
88 <?php
89 # import the Test::More emulation layer
90 # see
91 # http://search.cpan.org/dist/Test-Simple/lib/Test/More.pm
92 # for Perl's documentation - these functions should behave
93 # in the same way
94 require 'test-more.php';
95
96 # plan() the number of tests
97 plan(6);
98
99 # call ok() for each test you plan
100 ok ('foo' == 'foo', 'foo is equal to foo');
101 ok ('foo' != 'foo', 'foo is not equal to foo');
102
103 # ok() can be other things as well
104 is ('bar', 'bar', 'bar is bar');
105 is ('baz', 'bar', 'baz is baz');
106 isnt ('bar', 'beer', 'bar is not beer');
107 like ('bar', '/ar$/', 'bar matches ar$');
108
109 diag("printing some debugging information");
110
111 # whoops! one too many tests. I wonder what will happen...
112 is ('biff', 'biff', 'baz is a baz');
113 ?>
114
115 the include library "test-more.php" is automatically generated by
116 "Apache::TestConfigPHP" and configurations tweaked in such a a way that
117 your PHP scripts can find it without issue. the functions provided by
118 "test-more.php" are equivalent in name and function to those in
119 "Test::More", a standard Perl testing library, so you can see that man‐
120 page for details on the syntax and functionality of each.
121
122 at this point, we have enough in place to run some tests from PHP-land
123 - a "Makefile.PL" to configure Apache for us, and a PHP script in
124 "t/response/TestFoo/bar.php" to send some results out to the testing
125 engine. issuing "make test" would start Apache, issue the request to
126 "bar.php", generate a report, and shut down Apache. the report would
127 look like something like this after running the tests in verbose mode
128 (eg "make test TEST_VERBOSE=1"):
129
130 t/php/bar....1..6
131 ok 1 - foo is equal to foo
132 not ok 2 - foo is not equal to foo
133 # Failed test (/src/devel/perl-php-test/t/response/TestFoo/bar.php at line 13)
134 ok 3 - bar is bar
135 not ok 4 - baz is baz
136 # Failed test (/src/devel/perl-php-test/t/response/TestFoo/bar.php at line 17)
137 # got: 'baz'
138 # expected: 'bar'
139 ok 5 - bar is not beer
140 ok 6 - bar matches ar$
141 # printing some debugging information
142 ok 7 - baz is a baz
143 FAILED tests 2, 4, 7
144 Failed 3/6 tests, 50.00% okay
145 Failed Test Stat Wstat Total Fail Failed List of Failed
146 -------------------------------------------------------------------------------
147 t/php/bar.t 6 3 50.00% 2 4 7
148 Failed 1/1 test scripts, 0.00% okay. 1/6 subtests failed, 83.33% okay.
149
150 note that the actual test file that was run was "t/php/bar.t". this
151 file is autogenerated based on the "t/response/TestFoo/bar.php" pattern
152 of your PHP script. "t/php/bar.t" happens to be written in Perl, but
153 you really don't need to worry about it too much.
154
155 as an interesting aside, if you are using perl-5.8.3 or later you can
156 actually create your own "t/foo.php" client-side scripts and they will
157 be run via php (using our "php.ini"). but more on that later...
158
160 the best source of information about using Apache-Test with PHP (at
161 this time) is probably the talk given at ApacheCon 2004
162 (<http://xrl.us/phpperl>), as well as the code from the talk
163 (<http://xrl.us/phpperlcode>). there is also the online tutorial
164 <http://perl.apache.org/docs/general/testing/testing.html> which has
165 all of the mod_perl-specific syntax and features have been ported to
166 PHP with this class.
167
169 "Apache-Test" is a community effort, maintained by a group of dedicated
170 volunteers.
171
172 Questions can be asked at the test-dev <at> httpd.apache.org list For
173 more information see: http://httpd.apache.org/test/.
174
175
176
177perl v5.8.8 2006-11-19 Apache::TestRunPHP(3)