Commit | Line | Data |
efe6365b |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
7 | |
baa31d2f |
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 | |
19fb8520 |
35 | plan tests => 5; |
efe6365b |
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 | |
baa31d2f |
42 | my $storage = $schema->storage; |
43 | $storage->ensure_connected; |
44 | |
19fb8520 |
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 | |
baa31d2f |
55 | bless $storage, "DBICTest::ExplodingStorage"; |
56 | $schema->storage($storage); |
57 | |
58 | eval { |
19fb8520 |
59 | $schema->resultset('Artist')->create({ name => "Exploding Sheep" }); |
baa31d2f |
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 | |
efe6365b |
68 | 1; |