Replace inadequate $dbh->ping SQLite implementation (RT#78420)
[dbsrgits/DBIx-Class.git] / t / storage / reconnect.t
index b28734b..784a245 100644 (file)
@@ -36,26 +36,24 @@ my @art_two = $schema->resultset("Artist")->search({ }, { order_by => 'name DESC
 cmp_ok(@art_two, '==', 3, "Three artists returned");
 
 ### Now, disconnect the dbh, and move the db file;
-# create a new one and chmod 000 to prevent SQLite from connecting.
+# create a new one full of garbage, prevent SQLite from connecting.
 $schema->storage->_dbh->disconnect;
 move( $db_orig, $db_tmp )
   or die "failed to move $db_orig to $db_tmp: $!";
-open DBFILE, '>', $db_orig;
-print DBFILE 'THIS IS NOT A REAL DATABASE';
-close DBFILE;
-chmod 0000, $db_orig;
+open my $db_file, '>', $db_orig;
+print $db_file 'THIS IS NOT A REAL DATABASE';
+close $db_file;
 
-### Try the operation again... it should fail, since there's no db
+### Try the operation again... it should fail, since there's no valid db
 {
-    # Catch the DBI connection error
-    local $SIG{__WARN__} = sub {};
-    dies_ok {
-        my @art_three = $schema->resultset("Artist")->search( {}, { order_by => 'name DESC' } );
-    } 'The operation failed';
+  # Catch the DBI connection error
+  local $SIG{__WARN__} = sub {};
+  throws_ok {
+    my @art_three = $schema->resultset("Artist")->search( {}, { order_by => 'name DESC' } );
+  }  qr/not a database/, 'The operation failed';
 }
 
-# otherwise can't unlink the fake db file
-$schema->storage->_dbh->disconnect if $^O eq 'MSWin32';
+ok (! $schema->storage->connected, 'We are not connected' );
 
 ### Now, move the db file back to the correct name
 unlink($db_orig) or die "could not delete $db_orig: $!";