Fix last remaining tests with -T under < 5.10
[dbsrgits/DBIx-Class.git] / t / 94versioning.t
index ab9d261..af46ef7 100644 (file)
@@ -24,6 +24,11 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/};
 # in case it came from the env
 $ENV{DBIC_NO_VERSION_CHECK} = 0;
 
+# FIXME - work around RT#113965 in combination with -T on older perls:
+# the non-deparsing XS portion of D::D gets confused by some of the IO
+# handles trapped in the debug object of DBIC. What a mess.
+$Data::Dumper::Deparse = 1;
+
 use_ok('DBICVersion_v1');
 
 my $version_table_name = 'dbix_class_schema_versions';
@@ -281,6 +286,35 @@ is
   ), 3, "Expected number of connections at end of script"
 ;
 
+# Test custom HandleError setting on an in-memory instance
+{
+  my $custom_handler = sub { die $_[0] };
+
+  # try to setup a custom error handle without unsafe set -- should
+  # fail, same behavior as regular Schema
+  throws_ok {
+    DBICVersion::Schema->connect( 'dbi:SQLite::memory:', undef, undef, {
+      HandleError => $custom_handler,
+      ignore_version => 1,
+    })->deploy;
+  }
+    qr/Refusing clobbering of \{HandleError\} installed on externally supplied DBI handle/,
+    'HandleError with unsafe not set causes an exception'
+  ;
+
+  # now try it with unsafe set -- should work (see RT #113741)
+  my $s = DBICVersion::Schema->connect( 'dbi:SQLite::memory:', undef, undef, {
+    unsafe => 1,
+    HandleError => $custom_handler,
+    ignore_version => 1,
+  });
+
+  $s->deploy;
+
+  is $s->storage->dbh->{HandleError}, $custom_handler, 'Handler properly set on main schema';
+  is $s->{vschema}->storage->dbh->{HandleError}, $custom_handler, 'Handler properly set on version subschema';
+}
+
 END {
   rm_rf $ddl_dir unless $ENV{DBICTEST_KEEP_VERSIONING_DDL};
 }