NAME

Apache2::Dummy::RequestRec - dummy Apache request record class for testing

VERSION

version 1.0

SYNOPSIS

Test and debug Apache2 mod_perl handlers without running an apache server.

USAGE

use JSON;
use Test::More;

sub catch_stdout { ... }

sub unescapeURIString { ... }

sub test_http_handler
{
    my ($handler, $exp_res, $cl, $ct, @params) = @_;

    my $r = Apache2::Dummy::RequestRec->new(ref($params[0]) ? { params => $params[0] } : @params);

    my $params = ref($params[0]) ? { params => $params[0] } : { @params };

    my $ares = catch_stdout(sub { &$handler($r); });

    my $body = $r->body;
    
    ok($r->headers_out->{'Content-Length'} == $cl, "Content-Length == $cl");
    
    ok($r->headers_out->{'Content-Type'} eq $ct, "Content-Type: '$ct'");
    
    my $result = $ct =~ /json/i ? from_json(unescapeURIString($body)) : $body;
    
    ok(Compare($result, $exp_res), "body");
}

test_http_handler('My::Apache::Request::handler', { redirect => "https://localhost/" }, 55, 'application/json', login => 'mylogin', password => 'mypasswd');

DESCRIPTION

Apache2::Dummy::RequestRec can be used to test Apache2 mod_perl request handlers without an actual web server running. The difference to other similar modules is, that it uses APR::Table and APR::Pool to act much more like a real Apache.

AUTHOR

Jens Fischer <jeff@lipsia.de>

COPYRIGHT AND LICENSE

This software is copyright (c) 2021 by Jens Fischer.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.