Deprecate emulate_limit() - can not be sanely supported by DQ
[dbsrgits/DBIx-Class.git] / t / storage / dbi_env.t
CommitLineData
c1807ed5 1use strict;
2use warnings;
3use lib qw(t/lib);
4use DBICTest;
5use Test::More;
6use Test::Exception;
7
8BEGIN { delete @ENV{qw(DBI_DSN DBI_DRIVER)} }
9
8d6b1478 10$ENV{DBICTEST_LOCK_HOLDER} = -1;
c1807ed5 11
8d6b1478 12# pre-populate
13my $schema = DBICTest->init_schema(sqlite_use_file => 1);
c1807ed5 14
15my $dbname = DBICTest->_sqlite_dbname(sqlite_use_file => 1);
16
17sub count_sheep {
18 my $schema = shift;
19 scalar $schema->resultset('Artist')->search( { name => "Exploding Sheep" } )
20 ->all;
21}
22
23$schema = DBICTest::Schema->connect("dbi::$dbname");
24throws_ok { count_sheep($schema) } qr{I can't work out what driver to use},
25 'Driver in DSN empty';
26isa_ok $schema->storage, 'DBIx::Class::Storage::DBI';
27
28$schema = DBICTest::Schema->connect("dbi:Test_NonExistant_DBD:$dbname");
29throws_ok { count_sheep($schema) }
30 qr{Can't locate DBD/Test_NonExistant_DBD\.pm in \@INC},
31 "Driver class doesn't exist";
32isa_ok $schema->storage, 'DBIx::Class::Storage::DBI';
33
34$ENV{DBI_DSN} = "dbi::$dbname";
35$schema = DBICTest::Schema->connect;
36throws_ok { count_sheep($schema) } qr{I can't work out what driver to use},
37 "Driver class not defined in DBI_DSN either.";
38isa_ok $schema->storage, 'DBIx::Class::Storage::DBI';
39
40$ENV{DBI_DSN} = "dbi:Test_NonExistant_DBD2:$dbname";
41$schema = DBICTest::Schema->connect;
42throws_ok { count_sheep($schema) }
43 qr{Can't locate DBD/Test_NonExistant_DBD2\.pm in \@INC},
44 "Driver class defined in DBI_DSN doesn't exist";
45isa_ok $schema->storage, 'DBIx::Class::Storage::DBI';
46
47$ENV{DBI_DSN} = "dbi::$dbname";
48$ENV{DBI_DRIVER} = 'Test_NonExistant_DBD3';
49$schema = DBICTest::Schema->connect;
50throws_ok { count_sheep($schema) }
51 qr{Can't locate DBD/Test_NonExistant_DBD3\.pm in \@INC},
52 "Driver class defined in DBI_DRIVER doesn't exist";
53isa_ok $schema->storage, 'DBIx::Class::Storage::DBI';
54
55$ENV{DBI_DSN} = "dbi:Test_NonExistant_DBD4:$dbname";
56$schema = DBICTest::Schema->connect;
57throws_ok { count_sheep($schema) }
58qr{Can't locate DBD/Test_NonExistant_DBD4\.pm in \@INC},
59 "Driver class defined in DBI_DSN doesn't exist";
60isa_ok $schema->storage, 'DBIx::Class::Storage::DBI';
61
62delete @ENV{qw(DBI_DSN DBI_DRIVER)};
63
64$schema = DBICTest::Schema->connect("dbi:SQLite:$dbname");
65lives_ok { count_sheep($schema) } 'SQLite passed to connect_info';
66isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite';
67
68$ENV{DBI_DRIVER} = 'SQLite';
69$schema = DBICTest::Schema->connect("dbi::$dbname");
70lives_ok { count_sheep($schema) } 'SQLite in DBI_DRIVER';
71isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite';
72
442cb03d 73delete $ENV{DBI_DRIVER};
c1807ed5 74$ENV{DBI_DSN} = "dbi:SQLite:$dbname";
75$schema = DBICTest::Schema->connect;
76lives_ok { count_sheep($schema) } 'SQLite in DBI_DSN';
77isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite';
78
79$ENV{DBI_DRIVER} = 'SQLite';
80$schema = DBICTest::Schema->connect;
81lives_ok { count_sheep($schema) } 'SQLite in DBI_DSN (and DBI_DRIVER)';
82isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite';
83
84$ENV{DBI_DSN} = "dbi::$dbname";
85$ENV{DBI_DRIVER} = 'SQLite';
86$schema = DBICTest::Schema->connect;
87lives_ok { count_sheep($schema) } 'SQLite in DBI_DRIVER (not DBI_DSN)';
88isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite';
89
90done_testing;