File Coverage

blib/lib/Test/DBIC/Versioned.pm
Criterion Covered Total %
statement 18 20 90.0
branch n/a
condition n/a
subroutine 6 7 85.7
pod n/a
total 24 27 88.8


line stmt bran cond sub pod time code
1             package Test::DBIC::Versioned;
2              
3 1     1   14836 use strict;
  1         2  
  1         44  
4 1     1   6 use warnings;
  1         1  
  1         29  
5 1     1   19 use 5.016;
  1         6  
  1         67  
6              
7             our $VERSION = '0.02'; # VERSION
8              
9             =head1 NAME
10              
11             Test::DBIC::Versioned - Test upgrade scripts for L<< DBIx::Class::Schema::Versioned >>
12              
13             =head1 VERSION
14              
15             version 0.02
16              
17             =head1 SYNOPSIS
18              
19             use Test::More;
20             use Test::DBIC::Versioned;
21             use Test::DBIC::Versioned::MySQL;
22              
23             my $old_DB = Test::DBIC::Versioned::MySQL->new();
24             my $new_DB = Test::DBIC::Versioned::MySQL->new();
25              
26             is $old_DB->run_sql('sql/DB-21-MySQL.sql'), '',
27             'No errors deploying at version 21';
28             is $new_DB->run_sql('sql/DB-22-MySQL.sql'), '',
29             'No errors deploying at version 22';
30              
31             my $errors = $old_DB->run_sql('upgrades/RL-DB-21-22-MySQL.sql';
32             is $errors, '', 'No errors upgrading from 21 to 22';
33              
34             is_deeply $old_DB->describe_tables, $new_DB->describe_tables,
35             'Upgrade of version 21 to 22 matches a fresh deploy of 22';
36              
37             done_testing();
38              
39             =head1 DESCRIPTION
40              
41             This module provides helpful a wrapper for testing the correctness of
42             L<< DBIx::Class::Schema::Versioned >> upgrade scripts. Currently only MySQL
43             is supported.
44              
45             =head1 METHODS
46              
47             =head2 new
48              
49             A standard L<< Moose >> constructor. Takes no arguments. A temporary database
50             of the appropriate type will be lazy built when needed.
51              
52             =head2 run_sql
53              
54             Runs some SQL commands on the database. Normally this will be the deployment
55             script to set-up the database schema, or an upgrade script to modify the
56             schema.
57              
58             The commands can be in a file, file-handle, or be supplied in a scalar
59             reference.
60              
61             Returns any errors as a string, or an empty string if there where none.
62              
63             =head2 describe_tables
64              
65             Probes all tables in the database and returns a data structure describing the
66             schema (columns and indexes) on each table. The structure is intended to be
67             passed to is_deeply for comparison.
68              
69             =cut
70              
71 1     1   854 use JSON; # Used to convert perl data to a string.
  1         15919  
  1         3  
72 1     1   564 use Moose;
  1         333227  
  1         7  
73 1     1   5826 use MooseX::StrictConstructor;
  1         16524  
  1         4  
74              
75             =head1 FIELDS
76              
77             =head2 dsn
78              
79             The database dsn string. It can be used to connect to the database.
80              
81             =cut
82              
83             has 'dsn' => (
84             is => 'rw',
85             isa => 'Str',
86             );
87              
88             =head2 dbh
89              
90             The database dbh handle. It contains a connection to the database.
91              
92             =cut
93              
94             has 'dbh' => (
95             is => 'ro',
96             isa => 'DBI::db',
97             lazy_build => 1,
98             );
99              
100             sub _build_dbh {
101 0     0     my $self = shift;
102 0           return DBI->connect( $self->dsn );
103             }
104              
105             =head2 test_db
106              
107             The test database. The details of it are dependent on the database specific
108             subclass. For example in L<< Test::DBIC::Versioned::MySQL >> it is an
109             instance of L<< Test::mysqld >>.
110              
111             =cut
112              
113             has 'test_db' => (
114             is => 'ro',
115             isa => 'Ref',
116             lazy_build => 1,
117             );
118              
119             has _json_engine => (
120             is => 'ro',
121             isa => 'JSON',
122             default => sub { return JSON->new->pretty(1) }
123             );
124              
125             =head1 LICENSE AND COPYRIGHT
126              
127             Copyright (C) 2014 "spudsoup"
128              
129             This program is released under the Artistic License version 2.0
130              
131             =cut
132              
133             1;