Database-Migrator

 view release on metacpan or  search on metacpan

lib/Test/Database/Migrator.pm  view on Meta::CPAN

package Test::Database::Migrator;

use strict;
use warnings;
use namespace::autoclean;
use autodie;

our $VERSION = '0.14';

use File::Temp qw( tempdir );
use Database::Migrator::Types qw( ClassName Dir File Str );
use Log::Dispatch;
use Log::Dispatch::TestDiag;
use Path::Class qw( dir );
use Test::Fatal;
use Test::More 0.88;

use Moose;

has class => (
    is       => 'ro',
    isa      => ClassName,
    required => 1,
);

has database => (
    is      => 'ro',
    isa     => Str,
    default => 'DatabaseMigrator_test_' . $$,
);

has _tempdir => (
    is       => 'ro',
    isa      => Dir,
    init_arg => undef,
    lazy     => 1,
    default  => sub { dir( tempdir( CLEANUP => 1 ) ) },
);

has _schema_file => (
    is       => 'ro',
    isa      => File,
    init_arg => undef,
    lazy     => 1,
    default  => sub { $_[0]->_tempdir()->file('schema.sql') },
);

has _migrations_dir => (
    is       => 'ro',
    isa      => Dir,
    init_arg => undef,
    lazy     => 1,
    builder  => '_build_migrations_dir',
);

has _dbh => (
    is        => 'ro',
    isa       => 'DBI::db',
    init_arg  => undef,
    lazy      => 1,
    builder   => '_build_dbh',
    predicate => '_has_dbh',
);

sub run_tests {
    my $self = shift;

    $self->_write_ddl_file( $self->_schema_file(), $self->_schema_ddl() );

    ok(
        !$self->_new_migrator()->_database_exists(),
        $self->database() . ' does not exist yet'
    );

    $self->_check_initial_database();



( run in 0.999 second using v1.01-cache-2.11-cpan-54e63673c56 )