Commit | Line | Data |
c1807ed5 |
1 | use strict; |
2 | use warnings; |
3 | use lib qw(t/lib); |
4 | use DBICTest; |
5 | use Test::More; |
6 | use Test::Exception; |
7 | |
8 | BEGIN { delete @ENV{qw(DBI_DSN DBI_DRIVER)} } |
9 | |
8d6b1478 |
10 | $ENV{DBICTEST_LOCK_HOLDER} = -1; |
c1807ed5 |
11 | |
8d6b1478 |
12 | # pre-populate |
13 | my $schema = DBICTest->init_schema(sqlite_use_file => 1); |
c1807ed5 |
14 | |
15 | my $dbname = DBICTest->_sqlite_dbname(sqlite_use_file => 1); |
16 | |
17 | sub 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"); |
24 | throws_ok { count_sheep($schema) } qr{I can't work out what driver to use}, |
25 | 'Driver in DSN empty'; |
26 | isa_ok $schema->storage, 'DBIx::Class::Storage::DBI'; |
27 | |
28 | $schema = DBICTest::Schema->connect("dbi:Test_NonExistant_DBD:$dbname"); |
29 | throws_ok { count_sheep($schema) } |
30 | qr{Can't locate DBD/Test_NonExistant_DBD\.pm in \@INC}, |
31 | "Driver class doesn't exist"; |
32 | isa_ok $schema->storage, 'DBIx::Class::Storage::DBI'; |
33 | |
34 | $ENV{DBI_DSN} = "dbi::$dbname"; |
35 | $schema = DBICTest::Schema->connect; |
36 | throws_ok { count_sheep($schema) } qr{I can't work out what driver to use}, |
37 | "Driver class not defined in DBI_DSN either."; |
38 | isa_ok $schema->storage, 'DBIx::Class::Storage::DBI'; |
39 | |
40 | $ENV{DBI_DSN} = "dbi:Test_NonExistant_DBD2:$dbname"; |
41 | $schema = DBICTest::Schema->connect; |
42 | throws_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"; |
45 | isa_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; |
50 | throws_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"; |
53 | isa_ok $schema->storage, 'DBIx::Class::Storage::DBI'; |
54 | |
55 | $ENV{DBI_DSN} = "dbi:Test_NonExistant_DBD4:$dbname"; |
56 | $schema = DBICTest::Schema->connect; |
57 | throws_ok { count_sheep($schema) } |
58 | qr{Can't locate DBD/Test_NonExistant_DBD4\.pm in \@INC}, |
59 | "Driver class defined in DBI_DSN doesn't exist"; |
60 | isa_ok $schema->storage, 'DBIx::Class::Storage::DBI'; |
61 | |
62 | delete @ENV{qw(DBI_DSN DBI_DRIVER)}; |
63 | |
64 | $schema = DBICTest::Schema->connect("dbi:SQLite:$dbname"); |
65 | lives_ok { count_sheep($schema) } 'SQLite passed to connect_info'; |
66 | isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite'; |
67 | |
68 | $ENV{DBI_DRIVER} = 'SQLite'; |
69 | $schema = DBICTest::Schema->connect("dbi::$dbname"); |
70 | lives_ok { count_sheep($schema) } 'SQLite in DBI_DRIVER'; |
71 | isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite'; |
72 | |
442cb03d |
73 | delete $ENV{DBI_DRIVER}; |
c1807ed5 |
74 | $ENV{DBI_DSN} = "dbi:SQLite:$dbname"; |
75 | $schema = DBICTest::Schema->connect; |
76 | lives_ok { count_sheep($schema) } 'SQLite in DBI_DSN'; |
77 | isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite'; |
78 | |
79 | $ENV{DBI_DRIVER} = 'SQLite'; |
80 | $schema = DBICTest::Schema->connect; |
81 | lives_ok { count_sheep($schema) } 'SQLite in DBI_DSN (and DBI_DRIVER)'; |
82 | isa_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; |
87 | lives_ok { count_sheep($schema) } 'SQLite in DBI_DRIVER (not DBI_DSN)'; |
88 | isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite'; |
89 | |
90 | done_testing; |