Apache-Test

 view release on metacpan or  search on metacpan

lib/Apache/TestRunPHP.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::TestRunPHP;

use strict;
use warnings FATAL => 'all';

use File::Spec::Functions qw(catfile canonpath);

use Apache::TestRun ();
use Apache::TestConfigParse ();
use Apache::TestTrace;
use Apache::TestConfigPHP ();
use Apache::TestHarnessPHP ();

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 php things
use vars qw(@ISA);
@ISA = qw(Apache::TestRun);

sub start {
    my $self = shift;

    # point php to our own php.ini file
    $ENV{PHPRC} = catfile $self->{test_config}->{vars}->{serverroot},
                          'conf';

    $self->SUPER::start(@_);
}

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_inc
                                        configure_php_ini
                                        configure_php_functions
                                        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 php configure hooks
sub refresh {
    my $self = shift;
    $self->SUPER::refresh;
    $self->configure_php;
}

my @request_opts = qw(get post head);

sub run_tests {
    my $self = shift;

    my $test_opts = {
        verbose => $self->{opts}->{verbose},
        tests   => $self->{tests},
        order   => $self->{opts}->{order},
        subtests => $self->{subtests} || [],
    };

    if (grep { exists $self->{opts}->{$_} } @request_opts) {
        run_request($self->{test_config}, $self->{opts});
    }
    else {
        Apache::TestHarnessPHP->run($test_opts)
            if $self->{opts}->{'run-tests'};
    }
}

sub split_test_args {
    my($self) = @_;

    my(@tests);
    my $top_dir = $self->{test_config}->{vars}->{top_dir};
    my $t_dir = $self->{test_config}->{vars}->{t_dir};

    my $argv = $self->{argv};
    my @leftovers = ();
    for (@$argv) {
        my $arg = $_;
        # need the t/ (or t\) for stat-ing, but don't want to include
        # it in test output
        $arg =~ s@^(?:\.[\\/])?t[\\/]@@;
        my $file = catfile $t_dir, $arg;
        if (-d $file and $_ ne '/') {
            my @files = <$file/*.t>;
            push @files, <$file/*.php>;
            my $remove = catfile $top_dir, "";
            if (@files) {
                push @tests, map { s,^\Q$remove,,; $_ } @files;
                next;
            }
        }
        else {
            if (($file =~ /\.t$/ || $file =~ /\.php$/) and -e $file) {
                push @tests, "t/$arg";
                next;
            }
            elsif (-e "$file.t") {
                push @tests, "t/$arg.t";
                next;
            }
            elsif (/^[\d.]+$/) {
                my @t = $_;
                #support range of subtests: t/TEST t/foo/bar 60..65



( run in 1.248 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )