| 1 | package Interchange6::Test::Role::Database; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use Test::Roo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 4 | requires qw(_build_database _build_dbd_version); | |||||||||
| 6 | |||||||||||
| 7 | =head1 NAME | ||||||||||
| 8 | |||||||||||
| 9 | Interchange6::Test::Role::Database | ||||||||||
| 10 | |||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||
| 12 | |||||||||||
| 13 | Role consumed by all database-specific roles such as SQLite and Pg to provide common functionality. | ||||||||||
| 14 | |||||||||||
| 15 | =head1 ATTRIBUTES | ||||||||||
| 16 | |||||||||||
| 17 | =head2 database | ||||||||||
| 18 | |||||||||||
| 19 | The database object. We expect a database-specific role to supply the builder. | ||||||||||
| 20 | |||||||||||
| 21 | =cut | ||||||||||
| 22 | |||||||||||
| 23 | 4 | has database => ( | |||||||||
| 24 | is => 'lazy', | ||||||||||
| 25 | clearer => 1, | ||||||||||
| 26 | ); | ||||||||||
| 27 | |||||||||||
| 28 | =head2 database_info | ||||||||||
| 29 | |||||||||||
| 30 | Database backend version and other interesting info (if available). We expect a database-specific role to supply the builder. | ||||||||||
| 31 | |||||||||||
| 32 | =cut | ||||||||||
| 33 | |||||||||||
| 34 | 4 | has database_info => ( | |||||||||
| 35 | is => 'lazy', | ||||||||||
| 36 | ); | ||||||||||
| 37 | |||||||||||
| 38 | sub _build_database_info { | ||||||||||
| 39 | 0 | ▶ | return "no info"; | ||||||||
|
Subroutine
_build_database_info: not called CC=1 SCAR=6.9
| |||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | =head2 dbd_version | ||||||||||
| 43 | |||||||||||
| 44 | DBD::Foo version string. We expect a database-specific role to supply the builder. | ||||||||||
| 45 | |||||||||||
| 46 | =cut | ||||||||||
| 47 | |||||||||||
| 48 | 4 | has dbd_version => ( | |||||||||
| 49 | is => 'lazy', | ||||||||||
| 50 | ); | ||||||||||
| 51 | |||||||||||
| 52 | =head2 schema_class | ||||||||||
| 53 | |||||||||||
| 54 | Defaults to Interchange6::Schema. This gives tests the normal expected schema but allows them to overload with some other test schema if desired. | ||||||||||
| 55 | |||||||||||
| 56 | =cut | ||||||||||
| 57 | |||||||||||
| 58 | 4 | has schema_class => ( | |||||||||
| 59 | is => 'ro', | ||||||||||
| 60 | default => 'Interchange6::Schema', | ||||||||||
| 61 | ); | ||||||||||
| 62 | |||||||||||
| 63 | =head2 ic6s_schema | ||||||||||
| 64 | |||||||||||
| 65 | Our connected and deployed schema, | ||||||||||
| 66 | |||||||||||
| 67 | =cut; | ||||||||||
| 68 | |||||||||||
| 69 | 4 | has ic6s_schema => ( | |||||||||
| 70 | is => 'lazy', | ||||||||||
| 71 | clearer => 1, | ||||||||||
| 72 | ); | ||||||||||
| 73 | |||||||||||
| 74 | sub _build_ic6s_schema { | ||||||||||
| 75 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_build_ic6s_schema: called CC=4 SCAR=15.0
| |||||||||||
| 76 | |||||||||||
| 77 | 1 | require DBIx::Class::Optional::Dependencies; | |||||||||
| 78 | 1 | ▶ | if ( my $missing = | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | DBIx::Class::Optional::Dependencies->req_missing_for('deploy') ) | ||||||||||
| 80 | { | ||||||||||
| 81 | 0 | diag "WARN: missing $missing"; | |||||||||
| 82 | 0 | plan skip_all => "$missing required to run tests"; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 1 | my $schema_class = $self->schema_class; | |||||||||
| 86 | 1 | ▶ | eval "require $schema_class" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | or die "failed to require $schema_class: $@"; | ||||||||||
| 88 | |||||||||||
| 89 | 1 | ▶ | my $schema = $schema_class->connect( $self->connect_info ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | or die "failed to connect to "; | ||||||||||
| 91 | 1 | $schema->deploy(); | |||||||||
| 92 | 1 | return $schema; | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | =head1 MODIFIERS | ||||||||||
| 96 | |||||||||||
| 97 | =head2 before setup | ||||||||||
| 98 | |||||||||||
| 99 | Add diag showing DBD version info. | ||||||||||
| 100 | |||||||||||
| 101 | =cut | ||||||||||
| 102 | |||||||||||
| 103 | before setup => sub { | ||||||||||
| 104 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 105 | 1 | diag "using: " . $self->dbd_version; | |||||||||
| 106 | 1 | diag "db: " . $self->database_info; | |||||||||
| 107 | 4 | }; | |||||||||
| 108 | |||||||||||
| 109 | 4 | 1; | |||||||||