NAME

Test::SQLite - SQLite setup/teardown for tests

VERSION

version 0.0205

SYNOPSIS

  use DBI;
  use Test::SQLite;

  my $sqlite = Test::SQLite->new(database => '/some/where/production.db');

  my $dbh = $sqlite->dbh;

  $sqlite = Test::SQLite->new(
    schema   => '/some/where/schema.sql',
    db_attrs => { RaiseError => 1, AutoCommit => 0 },
  );

  $dbh = DBI->connect($sqlite->dsn, '', '', $sqlite->db_attrs);

DESCRIPTION

Test::SQLite is loosely inspired by Test::PostgreSQL and Test::mysqld, and creates a temporary db to use in tests. Unlike those modules, it is limited to setup/teardown of the test db given a database or schema SQL file. Also this module will return the database dbh handle and dsn connection string.

ATTRIBUTES

database

The database to copy.

has_database

Boolean indicating that a database file was provided to the constructor.

schema

The SQL schema to create a test database.

has_schema

Boolean indicating that a schema file was provided to the constructor.

db_attrs

DBI connection attributes. Default: { RaiseError => 1, AutoCommit => 1 }

dsn

The database connection string.

dbh

A connected database handle based on the dsn and db_attrs.

METHODS

new

  $sqlite = Test::SQLite->new(%arguments);

Create a new Test::SQLite object, which creates a temporary database based on the given database or schema.

BUILD

Ensure that we are given either a database or a schema and not both.

SEE ALSO

The t/01-methods.t file in this distribution.

DBI

File::Copy

File::Temp

Moo

THANK YOU

Kaitlyn Parkhurst <symkat@symkat.com>

AUTHOR

Gene Boggs <gene@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2020 by Gene Boggs.

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