Test::DBIC::DBDConnector - A Moo::Role for implementing DBD-versions of a DBIC test-class
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
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.
These are named parameters.
$your_schema_class
This is the DBIx::Class::Schema subclass for your ORM.
$your_dbd_connect_info
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 to DBIx::Class::Schema->connect().
MyDBD_connection_parameters()
DBIx::Class::Schema->connect()
$pre_deploy_hook
A CodeRef to execute before $schema->deploy is called.
$schema->deploy
This CodeRef is called with an instantiated $your_schema_class object as argument.
$post_connect_hook
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.
MyDBD_connection_parameters is a class method that you must implement in your class.
MyDBD_connection_parameters
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.
around
ignore_version
It gets the second argument from dbic_connect_ok(), this will be DBD specific.
dbic_connect_ok()
This method should return an ArrayRef with the list of arguments to pass to YourDBD::DBIC::Schema->connect()
YourDBD::DBIC::Schema->connect()
MyDBD_check_wants_deploy is a class method that you must implement in your class.
MyDBD_check_wants_deploy
© MMXXI - Abe Timmerman <abeltje@cpan.org>
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.
To install Test::DBIC::SQLite, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::DBIC::SQLite
CPAN shell
perl -MCPAN -e shell install Test::DBIC::SQLite
For more information on module installation, please visit the detailed CPAN module installation guide.