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.
49 my $db_file = "t/var/DBIxClass.db";
51 unlink($db_file) if -e $db_file;
52 unlink($db_file . "-journal") if -e $db_file . "-journal";
53 mkdir("t/var") unless -d "t/var";
55 my $dsn = $args{"dsn"} || "dbi:SQLite:${db_file}";
56 my $dbuser = $args{"user"} || '';
57 my $dbpass = $args{"pass"} || '';
61 my @connect_info = ($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
63 if ($args{compose_connection}) {
64 $schema = DBICTest::Schema->compose_connection(
65 'DBICTest', @connect_info
68 $schema = DBICTest::Schema->compose_namespace('DBICTest')
69 ->connect(@connect_info);
72 if ( !$args{no_deploy} ) {
73 __PACKAGE__->deploy_schema( $schema );
74 __PACKAGE__->populate_schema( $schema ) if( !$args{no_populate} );
84 return 't/lib/' . lc($schema->storage->dbh->{Driver}->{Name}) . '.sql';
89 DBICTest->deploy_schema( $schema );
98 my $file = $self->get_ddl_file($schema);
101 { local $/ = undef; $sql = <IN>; }
103 ($schema->storage->dbh->do($_) || print "Error on SQL: $_\n") for split(/;\n/, $sql);
109 DBICTest->clear_schema( $schema );
117 foreach my $class ($schema->sources) {
118 $schema->resultset($class)->delete;
123 =head2 populate_schema
125 DBICTest->populate_schema( $schema );
127 After you deploy your schema you can use this method to populate
128 the tables with test data.
132 sub populate_schema {
136 $schema->populate('Artist', [
137 [ qw/artistid name/ ],
138 [ 1, 'Caterwauler McCrae' ],
139 [ 2, 'Random Boy Band' ],
140 [ 3, 'We Are Goth' ],
143 $schema->populate('CD', [
144 [ qw/cdid artist title year/ ],
145 [ 1, 1, "Spoonful of bees", 1999 ],
146 [ 2, 1, "Forkful of bees", 2001 ],
147 [ 3, 1, "Caterwaulin' Blues", 1997 ],
148 [ 4, 2, "Generic Manufactured Singles", 2001 ],
149 [ 5, 2, "We like girls and stuff", 2003 ],
150 [ 6, 3, "Come Be Depressed With Us", 1998 ],
153 $schema->populate('Tag', [
154 [ qw/tagid cd tag/ ],
166 $schema->populate('Producer', [
167 [ qw/producerid name/ ],
168 [ 1, 'Matt S Trout' ],
169 [ 2, 'Bob The Builder' ],
170 [ 3, 'Fred The Phenotype' ],
173 $schema->populate('CD_to_Producer', [
180 $schema->populate('Track', [
181 [ qw/trackid cd position title last_updated_on/ ],
182 [ 4, 2, 1, "Stung with Success"],
183 [ 5, 2, 2, "Stripy"],
184 [ 6, 2, 3, "Sticky Honey"],
185 [ 7, 3, 1, "Yowlin"],
186 [ 8, 3, 2, "Howlin"],
187 [ 9, 3, 3, "Fowlin", '2007-10-20 00:00:00'],
188 [ 10, 4, 1, "Boring Name"],
189 [ 11, 4, 2, "Boring Song"],
190 [ 12, 4, 3, "No More Ideas"],
192 [ 14, 5, 2, "Under The Weather"],
193 [ 15, 5, 3, "Suicidal"],
194 [ 16, 1, 1, "The Bees Knees"],
195 [ 17, 1, 2, "Apiary"],
196 [ 18, 1, 3, "Beehind You"],