Test::Instance::Apache - Create Apache instance for Testing
use FindBin qw/ $Bin /; use Test::Instance::Apache; my $instance = Test::Instance::Apache->new( config => [ "VirtualHost *" => [ DocumentRoot => "$Bin/root", ], ], modules => [ qw/ mpm_prefork authz_core mime / ], ); $instance->run;
Test::Instance::Apache allows you to spin up a complete Apache instance for testing. This is useful when developing various plugins for Apache, or if your application is tightly integrated to the webserver.
These are the attributes available on Test::Instance::Apache.
The root folder for creating the Apache instance. This folder is passed to Apache during instantiation as the server root configuration, and normally contains all the configuration files for Apache. If not set during object creation, a new folder will be created using File::Temp.
The directory for holding the configuration files. Defaults to $server_root/conf. If set during object creation, then you will need to create the folder manually.
$server_root/conf
The directory for holding all the log files. Defaults to $server_root/logs. If set during object creation, then you will need to create the folder manually.
$server_root/logs
The path to the main configuration file. Defaults to $conf_dir/httpd.conf. This is then used by Test::Instance::Apache::Config to create the base configuration file.
$conf_dir/httpd.conf
Takes an arrayref of values to pass to Test::Instance::Apache::Config.
Takes an arrayref of modules to load into Apache. These are the same names as they appear in a2enmod, so only the modules which are available on your local machine can be used.
a2enmod
Path to the pid file for Apache. Defaults to $server_root/httpd.pid.
$server_root/httpd.pid
Port for Apache master process to listen on. If not set, will use "empty_port" in Net::EmptyPort to find an unused high-number port.
Path to the main Apache process. Uses "which" in File::Which to determine the path of the binary from your $PATH.
$PATH
Pid number for the main Apache process. Set during "run" and then used during "DEMOLISH" to kill the correct process.
These are the various methods inside this module either for internal or basic usage.
Sets up all the pre-required folders, writes the config files, loads the required modules, and then starts Apache itself.
Used internally to create folders under the server root. Will take an array of directory names, which are then passed to File::Spec - so if you do the following:
$instance->make_server_dir( 'a', 'b', 'c' );
Then a path of $server_root/a/b/c will be created.
$server_root/a/b/c
Returns the contents of the first line of the pid file. Used internally to set the pid after startup.
This will return all the items in the log directory as a hashref of filename and content. This is useful either during test development, or if you are testing exceptions on your application. Please note that it does not recurse subdirectories in the logs folder.
This is more for use during development of this module - prints out the path of all the files and folders stored as attributes in this module.
Kills the Apache instance started during run.
Tom Bloor <t.bloor@shadowcat.co.uk>
Initial development sponsored by Runbox
Copyright 2016 Tom Bloor
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Test::Instance::Apache::Config
Test::Instance::Apache::Modules
Apache::Test
To install Test::Instance::Apache, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Instance::Apache
CPAN shell
perl -MCPAN -e shell install Test::Instance::Apache
For more information on module installation, please visit the detailed CPAN module installation guide.