Apache-Test
view release on metacpan or search on metacpan
lib/Apache/TestConfigPHP.pm view on Meta::CPAN
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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;
@Apache::TestConfigPHP::ISA = qw(Apache::TestConfig);
my ($php_ini, $test_more);
{
# __DATA__ contains both php.ini and test-more.php
local $/ = "END_OF_FILE\n";
$php_ini = <DATA>;
chomp $php_ini;
$test_more = <DATA>;
chomp $test_more;
}
sub new {
return shift->SUPER::new(@_);
}
my %warn_style = (
html => sub { "<!-- @_ -->" },
c => sub { "/* @_ */" },
ini => sub { join '', grep {s/^/; /gm} @_ },
php => sub { join '', "<?php\n", grep {s/^/# /gm} @_ },
default => sub { join '', grep {s/^/\# /gm} @_ },
);
my %file_ext = (
map({$_ => 'html'} qw(htm html)),
map({$_ => 'c' } qw(c h)),
map({$_ => 'ini' } qw(ini)),
map({$_ => 'php' } qw(php)),
);
sub warn_style_sub_ref {
my ($self, $filename) = @_;
my $ext = $self->filename_ext($filename);
return $warn_style{ $file_ext{$ext} || 'default' };
}
sub configure_php_tests_pick {
my($self, $entries) = @_;
for my $subdir (qw(Response)) {
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;
my $php_t = catfile $dir, $test;
return if -e $t;
# don't write out foo.t if foo.php already exists
return if -e $php_t;
$self->gendir($dir);
my $fh = $self->genfile($t);
print $fh <<EOF;
use Apache::TestRequest 'GET_BODY_ASSERT';
( run in 0.585 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )