NAME
Test::Mojo::Pg - a helper for dealing with Pg during tests
SYNOPSIS
use Test::Mojo::Pg;
my $db;
# Bring up database to prepare for tests
BEGIN {
$db = Test::Mojo::Pg->new(host => 'ananke', db => 'mydb'), 'Test::Mojo::Pg';
$db->construct;
}
# Tear down the database to clean the environment
END {
$db->deconstruct;
}
DESCRIPTION
Test::Mojo::Pg makes the creation and removal of a transitory database during testing when using Mojo::Pg. This is useful when every test should work from a 'clean' database.
CONSTRUCTOR
You can either pass options in when calling the constructor or set the attributes later.
my $p1 = Test::Mojo::Pg->new();
my $p2 = Test::Mojo::Pg->new(host=>'myhost', db => 'db1');
Option keys match the attribute names.
ATTRIBUTES
The following are the attributes for this module.
host
Sets the Postgres server hostname. If omitted, no hostname (or port, if defined) will be configured for the connection string (which effectively means use localhost).
port
Sets the Postgres server port. If omitted, no port will be configured for the connection string.
db
Sets the test database name.
default: testdb
username
Sets the login username. If omitted, no username will be provided to the server.
password
Sets the login password. If omitted, no password will be provided to the server.
migsql
Sets the file to use for Mojo::Pg::Migrations. If no sql file is provided, a warning will be emitted that only an empty database has been provided.
verbose
Enables verbose output of operations such as the server's version string.
# get the verbose level - 0|1
$p->verbose;
# set the verbose level to 'on'
$p->verbose(1);
METHODS
The following are the methods for this module.
connstring
Returns the connection string for the database. Returns the connection string for the dbms by passing in '1'.
my $testdb_connstring = $testdb->connstring;
my $testdb_dbms = $testdb->connstring(1);
construct
The construct method removes current connections to the database and the database itself if it exists, creates a new database, and loads the migrations file if it's defined. This normally gets called from the BEGIN block.
$testdb->construct;
deconstruct
The deconstruct method removes current connections to the database and the database itself if it exists. This normally gets called from the END block.
$testdb->desconstruct;
create_database
Creates the database as defined by the connection string.
$testdb->create_database;
drop_database
Drops the database as defined by the connection string.
$testdb->drop_database;
get_version
my $version = $testdb->get_version;
Retrieve the database version.
remove_connections
Force removal of connection related data in the dbms. Many times required in order to drop the database.
$testdb->remove_connections;
AUTHORS
Richard A. Elberger <riche@cpan.org>.
MAINTAINERS
CONTRIBUTORS
BUGS
See http://rt.cpan.org to report and view bugs.
SOURCE
The source code repository for Test::More can be found at http://github.com/rpcme/Test-Mojo-Pg/.
COPYRIGHT
Copyright 2015 by Richard A. Elberger <riche@cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html