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