hi all... I hacked together the start of automagic support for PHP server-based tests.
basically, what the attached patch allows is for auto test script generation and configuration via Makefile.PL. that is Apache::TestRunPHP->generate_script(); and a file such as t/response/TestPHP/foo.php results is the autogenerated t/php/foo.t and a GET to /TestPHP/foo.php, which is properly script-aliased to t/response/TestPHP/foo.php. if foo.php looks something like <?php print "1..3\n"; print "ok 1\n"; print "not ok 2\n"; print "ok 3\n"; ?> you're on your way to writing Test::Harness compatible php scripts via Apache-Test. whee! the missing parts are important parts of Aapche::Test and Apache::TestUtil implemented in php. but if we just focused on adding plan(), ok() and t_cmp() I think we would have enough to ship. andy lester started some of this here: http://use.perl.org/~petdance/journal/14227 so I just need a clue on how to load a library in php and how to adjust httpd.conf so that that the library is picked up, then we can port andy's code over and... also missing is __DATA__-esque configuration, which would be identical to the perl implementation once somebody familiar with php tells me what a similar php token would be - maybe parsing everything following the closing ?> ? I have no idea. anyway, fwiw. any dual-life php folks out there interested in this can feel free to lend a hand. --Geoff
Index: lib/Apache/TestConfig.pm =================================================================== RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestConfig.pm,v retrieving revision 1.248 diff -u -r1.248 TestConfig.pm --- lib/Apache/TestConfig.pm 23 Sep 2004 00:34:57 -0000 1.248 +++ lib/Apache/TestConfig.pm 18 Oct 2004 20:05:49 -0000 @@ -49,6 +49,7 @@ use Symbol (); use Apache::TestConfigPerl (); +use Apache::TestConfigPHP (); use Apache::TestConfigParse (); use Apache::TestTrace; use Apache::TestServer (); --- /dev/null 2003-09-15 09:40:47.000000000 -0400 +++ lib/Apache/TestRunPHP.pm 2004-10-18 16:04:13.000000000 -0400 @@ -0,0 +1,63 @@ +# Copyright 2001-2004 The Apache Software Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +package Apache::TestRunPHP; + +use strict; +use warnings FATAL => 'all'; + +use Apache::TestRun (); +use Apache::TestConfigParse (); +use Apache::TestTrace; + +use vars qw($VERSION); +$VERSION = '1.00'; # make CPAN.pm's r() version scanner happy + +use File::Spec::Functions qw(catfile); + +#subclass of Apache::TestRun that configures mod_perlish things +use vars qw(@ISA); [EMAIL PROTECTED] = qw(Apache::TestRun); + +sub new_test_config { + my $self = shift; + + Apache::TestConfigPHP->new($self->{conf_opts}); +} + +sub configure_php { + my $self = shift; + + my $test_config = $self->{test_config}; + + $test_config->postamble_register(qw(configure_php_tests)); +} + +sub configure { + my $self = shift; + + $self->configure_php; + + $self->SUPER::configure; +} + +#if Apache::TestRun refreshes config in the middle of configure +#we need to re-add modperl configure hooks +sub refresh { + my $self = shift; + $self->SUPER::refresh; + $self->configure_php; +} + +1; --- /dev/null 2003-09-15 09:40:47.000000000 -0400 +++ lib/Apache/TestConfigPHP.pm 2004-10-18 16:05:37.000000000 -0400 @@ -0,0 +1,127 @@ +# Copyright 2001-2004 The Apache Software Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +package Apache::TestConfigPHP; + +#things specific to php + +use strict; +use warnings FATAL => 'all'; +use File::Spec::Functions qw(catfile splitdir abs2rel); +use File::Find qw(finddepth); +use Apache::TestTrace; +use Apache::TestRequest; +use Apache::TestConfig; +use Apache::TestConfigPerl; +use Config; + [EMAIL PROTECTED]::TestConfigPHP::ISA = qw(Apache::TestConfig); + +sub new { + return shift->SUPER::new(@_); +} + +my %outside_container = map { $_, 1 } qw{ +Alias AliasMatch +}; + +my %strip_tags = map { $_ => 1} qw(base noautoconfig); + +#test .php's can have configuration after the __DATA__ token +sub add_module_config { + # this is just a stub at the moment until somebody gives me + # an end-of-file PHP token that is similar to __DATA__ or __END__ +} + +my @extra_subdirs = qw(Response); + +sub configure_php_tests_pick { + my($self, $entries) = @_; + + for my $subdir (@extra_subdirs) { + my $dir = catfile $self->{vars}->{t_dir}, lc $subdir; + next unless -d $dir; + + finddepth(sub { + return unless /\.php$/; + + my $file = catfile $File::Find::dir, $_; + my $module = abs2rel $file, $dir; + my $status = $self->run_apache_test_config_scan($file); + push @$entries, [$file, $module, $subdir, $status]; + }, $dir); + } +} + +sub write_php_test { + my($self, $location, $test) = @_; + + (my $path = $location) =~ s/test//i; + (my $file = $test) =~ s/php$/t/i; + + my $dir = catfile $self->{vars}->{t_dir}, lc $path; + my $t = catfile $dir, $file; + return if -e $t; + + $self->gendir($dir); + my $fh = $self->genfile($t); + + print $fh <<EOF; +use Apache::TestRequest 'GET_BODY_ASSERT'; +print GET_BODY_ASSERT "/$location/$test"; +EOF + + close $fh or die "close $t: $!"; +} + +sub configure_php_tests { + my $self = shift; + + my @entries = (); + $self->configure_php_tests_pick([EMAIL PROTECTED]); + $self->configure_pm_tests_sort([EMAIL PROTECTED]); + + my %seen = (); + + for my $entry (@entries) { + my ($file, $module, $subdir, $status) = @$entry; + + my @args = (); + + my $directives = $self->add_module_config($file, [EMAIL PROTECTED]); + + my @parts = splitdir $file; + my $test = pop @parts; + my $location = $parts[-1]; + + debug "configuring PHP test file $file"; + + if ($directives->{noautoconfig}) { + $self->postamble(""); # which adds "\n" + } + else { + unless ($seen{$location}++) { + $self->postamble(Alias => [ catfile('', $parts[-1]), catfile(@parts) ]); + + my @args = (AddType => 'application/x-httpd-php .php'); + + $self->postamble(Location => "/$location", [EMAIL PROTECTED]); + } + } + + $self->write_php_test($location, $test); + } +} + +1;