X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fstorage%2Fdbi_env.t;h=462da111f0e3e050c7cfcd4fdacb82f0cf5edc93;hb=ab63014e90ff44053204ba629619838e5317720f;hp=f5275c3b4f121a3b51ad1bbb66ca76cb0c75395e;hpb=c1807ed502a52187c5f7654346ddf5135616576f;p=dbsrgits%2FDBIx-Class.git diff --git a/t/storage/dbi_env.t b/t/storage/dbi_env.t index f5275c3..462da11 100644 --- a/t/storage/dbi_env.t +++ b/t/storage/dbi_env.t @@ -1,21 +1,33 @@ -#!/usr/bin/perl use strict; use warnings; use lib qw(t/lib); use DBICTest; use Test::More; use Test::Exception; +use DBIx::Class::_Util 'sigwarn_silencer'; BEGIN { delete @ENV{qw(DBI_DSN DBI_DRIVER)} } -my $schema; +$ENV{DBICTEST_LOCK_HOLDER} = -1; -DBICTest->init_schema(sqlite_use_file => 1); +# pre-populate +my $schema = DBICTest->init_schema(sqlite_use_file => 1); my $dbname = DBICTest->_sqlite_dbname(sqlite_use_file => 1); sub count_sheep { my $schema = shift; + + local $SIG{__WARN__} = sigwarn_silencer( + qr/ + \QThis version of DBIC does not yet seem to supply a driver for your particular RDBMS\E + | + \QUnable to extract a driver name from connect info\E + | + \QYour storage class (DBIx::Class::Storage::DBI) does not set sql_limit_dialect\E + /x + ); + scalar $schema->resultset('Artist')->search( { name => "Exploding Sheep" } ) ->all; } @@ -70,7 +82,7 @@ $schema = DBICTest::Schema->connect("dbi::$dbname"); lives_ok { count_sheep($schema) } 'SQLite in DBI_DRIVER'; isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite'; -undef $ENV{DBI_DRIVER}; +delete $ENV{DBI_DRIVER}; $ENV{DBI_DSN} = "dbi:SQLite:$dbname"; $schema = DBICTest::Schema->connect; lives_ok { count_sheep($schema) } 'SQLite in DBI_DSN'; @@ -87,4 +99,21 @@ $schema = DBICTest::Schema->connect; lives_ok { count_sheep($schema) } 'SQLite in DBI_DRIVER (not DBI_DSN)'; isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite'; +# make sure that dynamically setting DBI_DSN post-connect works +{ + local $ENV{DBI_DSN}; + + my $s = DBICTest::Schema->connect(); + + throws_ok { + $s->storage->ensure_connected + } qr/You did not provide any connection_info/, + 'sensible exception on empty conninfo connect'; + + $ENV{DBI_DSN} = 'dbi:SQLite::memory:'; + + lives_ok { $s->storage->ensure_connected } 'Second connection attempt worked'; + isa_ok ( $s->storage, 'DBIx::Class::Storage::DBI::SQLite' ); +} + done_testing;