NAME
Test::DBIC::DBDConnector - A Moo::Role for implementing DBD-versions of a DBIC test-class
SYNOPSIS
package Test::DBIC::SQLite;
use Moo;
with 'Test::DBIC::DBDConnector';
sub MyDBD_connection_parameters {
my $class = shift;
my ($db_name) = @_;
$db_name //= ':memory:';
return [ "dbi:SQLite:dbname=$db_name" ];
}
sub MyDBD_check_wants_deploy {
my $class = shift;
my ($connection_params) = @_;
my ($db_name) = $connection_params->[0] =~ m{dbname=(.+)(?:;|$)};
my $wants_deploy = $db_name eq ':memory:'
? 1
: ((not -f $db_name) ? 1 : 0);
return $wants_deploy;
}
use namespace::autoclean 0.16;
1;
package main;
use Test::More;
my $td = Test::DBIC::SQLite->new(schema_class => 'My::Schema');
my $schema = $td->connect_dbic_ok();
...
$td->drop_dbic_ok();
done_testing();
output:
ok 1 - the schema ISA My::Schema
1..1
DESCRIPTION
This Moo::Role is intended to be the base for this type of tester module. It is part of the Test::DBIC::SQLite distribution because SQLite is also used for testing DBIx::Class, so the only way to test this role (that deploys a DBIx::Class::Schema subclass to a database), was to write a working implementation of Test::DBIC::SQLite although there already was one.
Test::DBIC::YourDBD->connect_dbic_ok(%arguments)
Arguments
These are named parameters.
- schema_class =>
$your_schema_class
(Required) -
This is the DBIx::Class::Schema subclass for your ORM.
- dbi_connect_info =>
$your_dbd_connect_info
(Optional) -
This argument is always passed to the Driver-Specific-Implementation of
MyDBD_connection_parameters()
that should return an array of arguments that will be passed toDBIx::Class::Schema->connect()
. - pre_deploy_hook =>
$pre_deploy_hook
(Optional) -
A CodeRef to execute before
$schema->deploy
is called.This CodeRef is called with an instantiated
$your_schema_class
object as argument. - post_connect_hook =>
$post_connect_hook
(Optional) -
A coderef to execute after
$schema->deploy
is called, if at all.This coderef is called with an instantiated
$your_schema_class
object as argument.
Test::DBIC::YourDBD->MyDBD_connection_parameters()
MyDBD_connection_parameters
is a class method that you must implement in your class.
This role provides an around
for this method that makes sure the ignore_version
option is added with a true value in the extra connection options hash. One can check this in the connect method of the schema-class.
Arguments
It gets the second argument from dbic_connect_ok()
, this will be DBD specific.
Response
This method should return an ArrayRef with the list of arguments to pass to YourDBD::DBIC::Schema->connect()
Test::DBIC::YourDBD->MyDBD_check_wants_deploy()
MyDBD_check_wants_deploy
is a class method that you must implement in your class.
Arguments
It gets the second argument from dbic_connect_ok()
, this will be DBD specific.
COPYRIGHT
(c) 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.