| 1 | package Tapper::Schema::TestTools; | ||
| 2 | 8 | our $AUTHORITY = 'cpan:TAPPER'; | |
| 3 | 8 | $Tapper::Schema::TestTools::VERSION = '5.0.12'; | |
| 4 | # inspired by Test::Fixture::DBIC::Schema | ||
| 5 | |||
| 6 | 8 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 8 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 8 | ▶ | BEGIN { |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 8 | ▶ | use Class::C3; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 8 | ▶ | use MRO::Compat; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 8 | $DBD::SQLite::sqlite_version; # fix "used only once" warning | |
| 13 | } | ||
| 14 | |||
| 15 | 8 | ▶ | use Tapper::Config; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | 8 | ▶ | use Tapper::Schema::TestrunDB; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | |||
| 18 | 8 | my $testrundb_schema; | |
| 19 | |||
| 20 | |||
| 21 | sub setup_db | ||
| 22 | 8 | ▶ | { |
|
Subroutine
setup_db: called CC=1 SCAR=0.0
Pod
documented
| |||
| 23 | # explicitely prefix into {test} subhash of the config file, | ||
| 24 | # to avoid painful mistakes with deploy | ||
| 25 | |||
| 26 | 8 | my ($db, $cfgbase) = @_; | |
| 27 | |||
| 28 | 8 | my $cfg = $cfgbase->{$db}; | |
| 29 | 8 | my $dsn = $cfg->{dsn}; | |
| 30 | 8 | my ($tmpfname) = $dsn =~ m,dbi:SQLite:dbname=([\w./]+),i; | |
| 31 | 8 | unlink $tmpfname; | |
| 32 | 8 | my $schema = Tapper::Schema::TestrunDB->connect($dsn, $cfg->{username}, $cfg->{password}, { ignore_version => 1 }); | |
| 33 | 8 | $schema->deploy; | |
| 34 | # $schema->upgrade if $schema->schema_version > $schema->get_db_version; | ||
| 35 | 8 | return $schema; | |
| 36 | } | ||
| 37 | |||
| 38 | |||
| 39 | 8 | ▶ | sub setup_testrundb { |
|
Subroutine
setup_testrundb: called CC=1 SCAR=0.0
Pod
documented
| |||
| 40 | 8 | $testrundb_schema = setup_db("TestrunDB", Tapper::Config->subconfig->{test}{database}); | |
| 41 | } | ||
| 42 | |||
| 43 | |||
| 44 | 7 | ▶ | sub import { |
|
Subroutine
import: called CC=1 SCAR=0.0
| |||
| 45 | 7 | my $pkg = caller(0); | |
| 46 | 8 | ▶ | no strict 'refs'; ## no critic. |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 47 | 7 | ▶ | *{"$pkg\::testrundb_schema"} = sub () { $testrundb_schema }; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 48 | } | ||
| 49 | |||
| 50 | 8 | setup_testrundb; | |
| 51 | |||
| 52 | 8 | 1; | |
| 53 | |||
| 54 | __END__ | ||