1 package # hide from PAUSE
10 DBICTest - Library to be used by DBIx::Class test scripts.
18 my $schema = DBICTest->init_schema();
22 This module provides the basic utilities to write tests against
29 my $schema = DBICTest->init_schema(
34 This method removes the test SQLite database in t/var/DBIxClass.db
35 and then creates a new, empty database.
37 This method will call deploy_schema() by default, unless the
38 no_deploy flag is set.
40 Also, by default, this method will call populate_schema() by
41 default, unless the no_deploy or no_populate flags are set.
48 my $db_file = "t/var/DBIxClass.db";
50 unlink($db_file) if -e $db_file;
51 unlink($db_file . "-journal") if -e $db_file . "-journal";
52 mkdir("t/var") unless -d "t/var";
54 my $dsn = $ENV{"FIXTURETEST_DSN"} || "dbi:SQLite:${db_file}";
55 my $dbuser = $ENV{"FIXTURETEST_DBUSER"} || '';
56 my $dbpass = $ENV{"FIXTURETEST_DBPASS"} || '';
60 my @connect_info = ($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
62 if ($args{compose_connection}) {
63 $schema = DBICTest::Schema->compose_connection(
64 'DBICTest', @connect_info
67 $schema = DBICTest::Schema->compose_namespace('DBICTest')
68 ->connect(@connect_info);
70 $schema->storage->on_connect_do(['PRAGMA synchronous = OFF']);
71 if ( !$args{no_deploy} ) {
72 __PACKAGE__->deploy_schema( $schema );
73 __PACKAGE__->populate_schema( $schema ) if( !$args{no_populate} );
80 DBICTest->deploy_schema( $schema );
88 open IN, "t/lib/sqlite.sql";
90 { local $/ = undef; $sql = <IN>; }
92 ($schema->storage->dbh->do($_) || print "Error on SQL: $_\n") for split(/;\n/, $sql);
95 =head2 populate_schema
97 DBICTest->populate_schema( $schema );
99 After you deploy your schema you can use this method to populate
100 the tables with test data.
104 sub populate_schema {
108 $schema->populate('Artist', [
109 [ qw/artistid name/ ],
110 [ 1, 'Caterwauler McCrae' ],
111 [ 2, 'Random Boy Band' ],
112 [ 3, 'We Are Goth' ],
115 $schema->populate('CD', [
116 [ qw/cdid artist title year/ ],
117 [ 1, 1, "Spoonful of bees", 1999 ],
118 [ 2, 1, "Forkful of bees", 2001 ],
119 [ 3, 1, "Caterwaulin' Blues", 1997 ],
120 [ 4, 2, "Generic Manufactured Singles", 2001 ],
121 [ 5, 3, "Come Be Depressed With Us", 1998 ],
124 $schema->populate('Tag', [
125 [ qw/tagid cd tag/ ],
137 $schema->populate('Producer', [
138 [ qw/producerid name/ ],
139 [ 1, 'Matt S Trout' ],
140 [ 2, 'Bob The Builder' ],
141 [ 3, 'Fred The Phenotype' ],
144 $schema->populate('CD_to_Producer', [
151 $schema->populate('Track', [
152 [ qw/trackid cd position title/ ],
153 [ 4, 2, 1, "Stung with Success"],
154 [ 5, 2, 2, "Stripy"],
155 [ 6, 2, 3, "Sticky Honey"],
156 [ 7, 3, 1, "Yowlin"],
157 [ 8, 3, 2, "Howlin"],
158 [ 9, 3, 3, "Fowlin"],
159 [ 10, 4, 1, "Boring Name"],
160 [ 11, 4, 2, "Boring Song"],
161 [ 12, 4, 3, "No More Ideas"],
163 [ 14, 5, 2, "Under The Weather"],
164 [ 15, 5, 3, "Suicidal"],
165 [ 16, 1, 1, "The Bees Knees"],
166 [ 17, 1, 2, "Apiary"],
167 [ 18, 1, 3, "Beehind You"],