NAME

Test::DBIC::Pg - Connect to and deploy a DBIx::Class::Schema on Postgres

SYNOPSIS

The preferred way:

#! perl -w
use Test::More;
use Test::DBIC::Pg;

my $td = Test::DBIC::Pg->new(schema_class => 'My::Schema');
my $schema = $td->connect_dbi_ok();
...
$schema->storage->disconnect();
$td->drop_dbic_ok();
done_testing();

The compatible with Test::DBIC::SQLite way:

#! perl -w
use Test::More;
use Test::DBIC::Pg;
my $schema = connect_dbic_pg_ok('My::Schema');
...
$schema->storage->disconnect();
drop_dbic_pg_ok();
done_testing();

DESCRIPTION

This is an implementation of Test::DBIC::Pg that uses the Moo::Role: Test::DBIC::DBDConnector from the Test::DBIC::SQLite package.

It will import() warnings and strict for you.

Test::DBIC::Pg->new

my $td = Test::DBIC::Pg->new(%parameters);
my $schema = $td->connect_dbic_ok();
...
$schema->storage->disconnect();
$td->drop_dbic_ok();

Parameters

Named, list:

$td->connect_dbic_ok()

This method is inherited from Test::DBIC::DBDConnoctor.

If the database needs deploying, there will be another temporary database connection to the template database in order to issue the CREATE DATABASE $dbname statement.

Returns

An initialised instance of $schema_class.

$td->drop_dbic_ok

This method implements a dropdb $dbname, in order not to litter your server with test databases.

During this method there will be another temporary database connection to the template database, in order to issue the DROP DATABASE $dbname statement (that cannot be run from the connection with the test database it self).

connect_dbic_pg_ok(@parameters)

Create a PostgreSQL database and deploy a dbic_schema. This function is provided for compatibility with Test::DBIC::SQLite.

See Test::DBIC::Pg->new for further information, although only these 4 arguments are supported.

Parameters

Positional:

  1. $schema_class (Required)
  2. $pg_connect_info (Optional)
  3. $pre_deploy_hook (Optional)
  4. $post_connect_hook (Optional)

drop_dbic_pg_ok()

This function uses the cached information of the call to connect_dbic_pg_ok() and clears it after the database is dropped, using another temporary connection to the template database.

See the drop_dbic_ok() method.

Implementation of MyDBD_connection_parameters

As there is no fiddling with the already provided connection paramaters, this method sets up the connection parameter for the temporary connection to the template database in order to create or drop the (temporary) test database.

Implementation of MyDBD_check_wants_deploy

In this method the temporary connection to the template database is set up and a list of available database is requested - via $dbh->data_sources() - to check if the test database already exists. If it doesn't, the database will be created and a true value is returned, otherwise a false value is returned and no new database is created.

AUTHOR

© MMXXI - Abe Timmerman abeltje@cpan.org

LICENSE

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

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.