1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
9 use DBIx::Class::_Util 'sigwarn_silencer';
11 BEGIN { delete @ENV{qw(DBI_DSN DBI_DRIVER)} }
13 $ENV{DBICTEST_LOCK_HOLDER} = -1;
16 my $schema = DBICTest->init_schema(sqlite_use_file => 1);
18 my $dbname = DBICTest->_sqlite_dbname(sqlite_use_file => 1);
23 local $SIG{__WARN__} = sigwarn_silencer(
25 \QThis version of DBIC does not yet seem to supply a driver for your particular RDBMS\E
27 \QUnable to extract a driver name from connect info\E
29 \QYour storage class (DBIx::Class::Storage::DBI) does not set sql_limit_dialect\E
33 scalar $schema->resultset('Artist')->search( { name => "Exploding Sheep" } )
37 $schema = DBICTest::Schema->connect("dbi::$dbname");
38 throws_ok { count_sheep($schema) } qr{I can't work out what driver to use},
39 'Driver in DSN empty';
40 isa_ok $schema->storage, 'DBIx::Class::Storage::DBI';
42 $schema = DBICTest::Schema->connect("dbi:Test_NonExistant_DBD:$dbname");
43 throws_ok { count_sheep($schema) }
44 qr{Can't locate DBD/Test_NonExistant_DBD\.pm in \@INC},
45 "Driver class doesn't exist";
46 isa_ok $schema->storage, 'DBIx::Class::Storage::DBI';
48 $ENV{DBI_DSN} = "dbi::$dbname";
49 $schema = DBICTest::Schema->connect;
50 throws_ok { count_sheep($schema) } qr{I can't work out what driver to use},
51 "Driver class not defined in DBI_DSN either.";
52 isa_ok $schema->storage, 'DBIx::Class::Storage::DBI';
54 $ENV{DBI_DSN} = "dbi:Test_NonExistant_DBD2:$dbname";
55 $schema = DBICTest::Schema->connect;
56 throws_ok { count_sheep($schema) }
57 qr{Can't locate DBD/Test_NonExistant_DBD2\.pm in \@INC},
58 "Driver class defined in DBI_DSN doesn't exist";
59 isa_ok $schema->storage, 'DBIx::Class::Storage::DBI';
61 $ENV{DBI_DSN} = "dbi::$dbname";
62 $ENV{DBI_DRIVER} = 'Test_NonExistant_DBD3';
63 $schema = DBICTest::Schema->connect;
64 throws_ok { count_sheep($schema) }
65 qr{Can't locate DBD/Test_NonExistant_DBD3\.pm in \@INC},
66 "Driver class defined in DBI_DRIVER doesn't exist";
67 isa_ok $schema->storage, 'DBIx::Class::Storage::DBI';
69 $ENV{DBI_DSN} = "dbi:Test_NonExistant_DBD4:$dbname";
70 $schema = DBICTest::Schema->connect;
71 throws_ok { count_sheep($schema) }
72 qr{Can't locate DBD/Test_NonExistant_DBD4\.pm in \@INC},
73 "Driver class defined in DBI_DSN doesn't exist";
74 isa_ok $schema->storage, 'DBIx::Class::Storage::DBI';
76 delete @ENV{qw(DBI_DSN DBI_DRIVER)};
78 $schema = DBICTest::Schema->connect("dbi:SQLite:$dbname");
79 lives_ok { count_sheep($schema) } 'SQLite passed to connect_info';
80 isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite';
82 $schema = DBICTest::Schema->connect("dbi:SQLite(ReadOnly=1):$dbname");
83 lives_ok { count_sheep($schema) } 'SQLite passed to connect_info despite extra arguments present';
84 isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite';
86 $ENV{DBI_DRIVER} = 'SQLite';
87 $schema = DBICTest::Schema->connect("dbi::$dbname");
88 lives_ok { count_sheep($schema) } 'SQLite in DBI_DRIVER';
89 isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite';
91 delete $ENV{DBI_DRIVER};
92 $ENV{DBI_DSN} = "dbi:SQLite:$dbname";
93 $schema = DBICTest::Schema->connect;
94 lives_ok { count_sheep($schema) } 'SQLite in DBI_DSN';
95 isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite';
97 $ENV{DBI_DRIVER} = 'SQLite';
98 $schema = DBICTest::Schema->connect;
99 lives_ok { count_sheep($schema) } 'SQLite in DBI_DSN (and DBI_DRIVER)';
100 isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite';
102 $ENV{DBI_DSN} = "dbi::$dbname";
103 $ENV{DBI_DRIVER} = 'SQLite';
104 $schema = DBICTest::Schema->connect;
105 lives_ok { count_sheep($schema) } 'SQLite in DBI_DRIVER (not DBI_DSN)';
106 isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite';
108 # make sure that dynamically setting DBI_DSN post-connect works
112 my $s = DBICTest::Schema->connect();
115 $s->storage->ensure_connected
116 } qr/You did not provide any connection_info/,
117 'sensible exception on empty conninfo connect';
119 $ENV{DBI_DSN} = 'dbi:SQLite::memory:';
121 lives_ok { $s->storage->ensure_connected } 'Second connection attempt worked';
122 isa_ok ( $s->storage, 'DBIx::Class::Storage::DBI::SQLite' );