Adding datetime_undef_if_invalid to squelch errors on DateTime inflation of bogus...
[dbsrgits/DBIx-Class.git] / t / 92storage.t
1 use strict;
2 use warnings;  
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7
8 {
9     package DBICTest::ExplodingStorage::Sth;
10     use strict;
11     use warnings;
12
13     sub execute { die "Kablammo!" }
14
15     sub bind_param {}
16
17     package DBICTest::ExplodingStorage;
18     use strict;
19     use warnings;
20     use base 'DBIx::Class::Storage::DBI::SQLite';
21
22     my $count = 0;
23     sub sth {
24       my ($self, $sql) = @_;
25       return bless {},  "DBICTest::ExplodingStorage::Sth" unless $count++;
26       return $self->next::method($sql);
27     }
28
29     sub connected {
30       return 0 if $count == 1;
31       return shift->next::method(@_);
32     }
33 }
34
35 plan tests => 6;
36
37 my $schema = DBICTest->init_schema();
38
39 is( ref($schema->storage), 'DBIx::Class::Storage::DBI::SQLite',
40     'Storage reblessed correctly into DBIx::Class::Storage::DBI::SQLite' );
41
42 my $storage = $schema->storage;
43 $storage->ensure_connected;
44
45 eval {
46     $schema->storage->throw_exception('test_exception_42');
47 };
48 like($@, qr/\btest_exception_42\b/, 'basic exception');
49
50 eval {
51     $schema->resultset('CD')->search_literal('broken +%$#$1')->all;
52 };
53 like($@, qr/prepare_cached failed/, 'exception via DBI->HandleError, etc');
54
55 bless $storage, "DBICTest::ExplodingStorage";
56 $schema->storage($storage);
57
58 eval { 
59     $schema->resultset('Artist')->create({ name => "Exploding Sheep" });
60 };
61
62 is($@, "", "Exploding \$sth->execute was caught");
63
64 is(1, $schema->resultset('Artist')->search({name => "Exploding Sheep" })->count,
65   "And the STH was retired");
66
67 my $info = { on_connect_do => [] };
68
69 $storage->connect_info(['foo','bar','baz',$info]);
70
71 ok(exists($info->{on_connect_do}), q{Didn't kill key passed to storage});
72
73 1;