Test::Mock::Apache2 - Mock mod_perl2 objects when running outside of Apache
version 0.05
use Test::Mock::Apache2; my $r = Apache2::RequestUtil->request(); my $apr_req = APR::Request::Apache2->handle($r); ... # Add configuration data that $r->dir_config() later can supply use Test::Mock::Apache2 { MyAppSetting => "foo", MyPort => 1233 }; my $r = Apache2::RequestUtil->request(); my $port = $r->dir_config('MyPort'); # 1233
Allows to work with Apache2::* objects without a running modperl server.
Apache2::*
The purpose of this class is to be able to run some minimal unit tests for a code base that's hopelessly entangled with the Apache internals.
Current state is, to say the least, very incomplete. Will be hopefully expanded as the unit test suite grows.
Return a mock Apache2::ServerRec empty object, with the following methods: server_hostname.
server_hostname
To set the hostname, set a server_hostname key in the configuration block when using the module.
use Test::Mock::Apache2 { server_hostname => 'localhost.localdomain' };
Default server_hostname is localhost.
localhost
Return a mock Apache2::RequestRec empty object, with the following methods: hostname, dir_config, server.
hostname
dir_config
server
Return a mock APR::Request::Apache2 empty object with the following methods: new, jar, param, handle.
new
jar
param
handle
Mocks the Apache2::RequestUtil> module to fake the +GlobalRequest option, so you can execute code like:
+GlobalRequest
my $r = Apache2::RequestUtil->request();
and get back an Apache2::RequestRec object. Uses "ap2_request". Supplies the following methods: new, request, dir_config.
request
Creates the initial instances of the mocked objects for the various Apache2::* classes.
Cosimo Streppone <cosimo@opera.com>
This software is Copyright (c) 2012 by Opera Software ASA.
This is free software, licensed under:
The (three-clause) BSD License
To install Test::Mock::Apache2, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Mock::Apache2
CPAN shell
perl -MCPAN -e shell install Test::Mock::Apache2
For more information on module installation, please visit the detailed CPAN module installation guide.