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{"DBICTEST_DSN"} || "dbi:SQLite:${db_file}";
55 my $dbuser = $ENV{"DBICTEST_DBUSER"} || '';
56 my $dbpass = $ENV{"DBICTEST_DBPASS"} || '';
58 my $schema = DBICTest::Schema->compose_namespace('DBICTest')
59 ->connect($dsn, $dbuser, $dbpass);
60 $schema->storage->on_connect_do(['PRAGMA synchronous = OFF']);
61 if ( !$args{no_deploy} ) {
62 __PACKAGE__->deploy_schema( $schema );
63 __PACKAGE__->populate_schema( $schema ) if( !$args{no_populate} );
70 DBICTest->deploy_schema( $schema );
72 This method does one of two things to the schema. It can either call
73 the experimental $schema->deploy() if the DBICTEST_SQLT_DEPLOY environment
74 variable is set, otherwise the default is to read in the t/lib/sqlite.sql
75 file and execute the SQL within. Either way you end up with a fresh set
76 of tables for testing.
84 if ($ENV{"DBICTEST_SQLT_DEPLOY"}) {
85 return $schema->deploy();
87 open IN, "t/lib/sqlite.sql";
89 { local $/ = undef; $sql = <IN>; }
91 ($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('Host', [
109 [ qw/hostname address/ ],
110 [ 'localhost', 2130706433 ],
113 $schema->populate('Network', [
114 [ qw/netname address/ ],
115 [ qw{localnet 127.0.0.0/8} ],