blib/lib/Apache/TestHarnessPHP.pm untested

filter: Statementstmt 0.0% 0 / 99 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 149 CC 11 SCAR 41.6
CC
11
Cov
0%
get_tests
132.0
run
2.0
command_line
2.0
CRAP 64.2
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 package Apache::TestHarnessPHP;
17  
18 use strict;
19 use warnings FATAL => 'all';
20  
21 use File::Spec::Functions qw(catfile catdir);
22 use File::Find qw(finddepth);
23 use Apache::TestHarness ();
24 use Apache::TestTrace;
25 use Apache::TestConfig ();
26  
27 use vars qw(@ISA);
28 @ISA = qw(Apache::TestHarness);
29 use TAP::Formatter::Console;
30 use TAP::Harness;
31  
32 sub get_tests {
33  
34 my $self = shift;
35 my $args = shift;
36 my @tests = ();
37  
38 my $base = -d 't' ? catdir('t', '.') : '.';
39  
40 my $ts = $args->{tests} || [];
41  
42 if (@$ts) {
43 for (@$ts) {
44 if (-d $_) {
45 push(@tests, sort <$base/$_/*.t>);
46 push(@tests, sort <$base/$_/*.php>);
47 }
48 else {
49 $_ .= ".t" unless /(\.t|\.php)$/;
50 push(@tests, $_);
51 }
52 }
53 }
54 else {
55 if ($args->{tdirs}) {
56 push @tests, map { sort <$base/$_/*.t> } @{ $args->{tdirs} };
57 push @tests, map { sort <$base/$_/*.php> } @{ $args->{tdirs} };
58 }
59 else {
60 finddepth(sub {
61 return unless /\.(t|php)$/;
62 return if $File::Find::dir =~ m/\b(conf|htdocs|logs|response)\b/;
63 my $t = catfile $File::Find::dir, $_;
64 my $dotslash = catfile '.', "";
65 $t =~ s:^\Q$dotslash::;
66 push @tests, $t
67 }, $base);
68 @tests = sort @tests;
69 }
70 }
71  
72 @tests = $self->prune(@tests);
73  
74 if (my $skip = $self->skip) {
75 # Allow / \ and \\ path delimiters in SKIP file
76 $skip =~ s![/\\\\]+![/\\\\]!g;
77  
78 @tests = grep { not /(?:$skip)/ } @tests;
79 }
80  
81 Apache::TestSort->run(\@tests, $args);
82  
83 #when running 't/TEST t/dir' shell tab completion adds a /
84 #dir//foo output is annoying, fix that.
85 s:/+:/:g for @tests;
86  
87 # remove *.php tests unless we can run them with php
88 if (! Apache::TestConfig::which('php')) {
89 warning(join ' - ', 'skipping *.php tests',
90 'make sure php is in your PATH');
91 @tests = grep { not /\.php$/ } @tests;
92 }
93 elsif (! $phpclient) {
94 warning(join ' - ', 'skipping *.php tests',
95 'Test::Harness 2.38 not available');
96 @tests = grep { not /\.php$/ } @tests;
97 }
98  
99 return @tests;
100 }
101  
102 sub run {
103 my $self = shift;
104 my $args = shift || {};
105 my $formatter = TAP::Formatter::Console->new;
106 my $agg = TAP::Parser::Aggregator->new;
107 my $verbose = $args->{verbose} && $args->{verbose};
108 my $php_harness = TAP::Harness->new
109 ({exec => $self->command_line(),
110 verbosity => $verbose});
111 my $perl_harness = TAP::Harness->new
112 ({verbosity => $verbose});
113 my @tests = $self->get_tests($args, @_);
114  
115 $agg->start();
116 $php_harness->aggregate_tests($agg, grep {m{\.php$}} @tests);
117 $perl_harness->aggregate_tests($agg, grep {m{\.t$}} @tests);
118 $agg->stop();
119  
120 $formatter->summary($agg);
121 }
122  
123 sub command_line {
124 my $self = shift;
125  
126 my $server_root = Apache::Test::vars('serverroot');
127  
128 my $conf = catfile($server_root, 'conf');
129  
130 my $ini = catfile($conf, 'php.ini');
131  
132 my $php = Apache::TestConfig::which('php') ||
133 die 'no php executable found in ' . $ENV{PATH};
134  
135 return ["env", "SERVER_ROOT=$server_root",
136 $php, "--php-ini", $ini, "--define", "include_path=$conf"];
137 }
138  
139 1;