Introducing DBIx::Class::Schema::SanityChecker
[dbsrgits/DBIx-Class.git] / t / cdbi / testlib / MyBase.pm
index fa66258..106b359 100644 (file)
@@ -5,42 +5,40 @@ use warnings;
 use strict;
 
 use DBI;
-
-use lib 't/lib';
 use DBICTest;
 
-use base qw(DBIx::Class::CDBICompat);
+BEGIN {
+  # offset the warning from DBIx::Class::Schema on 5.8
+  # keep the ::Schema default as-is otherwise
+   DBIx::Class::_ENV_::OLD_MRO
+    and
+  ( eval <<'EOS' or die $@ );
 
-our $dbh;
+  sub setup_schema_instance {
+    my $s = shift->next::method(@_);
+    $s->schema_sanity_checker('');
+    $s;
+  }
 
-my $err;
-if (! $ENV{DBICTEST_MYSQL_DSN} ) {
-  $err = 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test';
-}
-elsif ( ! DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_mysql') ) {
-  $err = 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_mysql')
+  1;
+EOS
 }
 
-if ($err) {
-  my $t = eval { Test::Builder->new };
-  if ($t and ! $t->current_test) {
-    $t->skip_all ($err);
-  }
-  else {
-    die "$err\n";
-  }
-}
+use base qw(DBIx::Class::CDBICompat);
 
 my @connect = (@ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}, { PrintError => 0});
 # this is only so we grab a lock on mysql
 {
-  my $x = DBICTest->connect_schema(@connect);
+  my $x = DBICTest::Schema->connect(@connect);
 }
 
-$dbh = DBI->connect(@connect) or die DBI->errstr;
+our $dbh = DBI->connect(@connect) or die DBI->errstr;
 my @table;
 
-END { $dbh->do("DROP TABLE $_") foreach @table }
+END {
+  $dbh->do("DROP TABLE $_") for @table;
+  undef $dbh;
+}
 
 __PACKAGE__->connection(@connect);