Fix failures and protect the suite from spurious VERSION-related warnings
[dbsrgits/DBIx-Class.git] / t / cdbi / 98-failure.t
CommitLineData
83eef562 1use DBIx::Class::Optional::Dependencies -skip_all_without => 'cdbicompat';
2
5a66aa65 3use strict;
4a233f30 4use warnings;
83eef562 5
5a66aa65 6use Test::More;
7
8#----------------------------------------------------------------------
9# Test database failures
10#----------------------------------------------------------------------
11
50891152 12use lib 't/cdbi/testlib';
5a66aa65 13use Film;
14
15Film->create_test_film;
16
17{
6a3bf251 18 my $btaste = Film->retrieve('Bad Taste');
19 isa_ok $btaste, 'Film', "We have Bad Taste";
20 {
21 no warnings 'redefine';
22 local *DBIx::ContextualFetch::st::execute = sub { die "Database died" };
23 eval { $btaste->delete };
24 ::like $@, qr/Database died/s, "We failed";
25 }
26 my $still = Film->retrieve('Bad Taste');
27 isa_ok $btaste, 'Film', "We still have Bad Taste";
5a66aa65 28}
29
30{
6a3bf251 31 my $btaste = Film->retrieve('Bad Taste');
32 isa_ok $btaste, 'Film', "We have Bad Taste";
33 $btaste->numexplodingsheep(10);
34 {
35 no warnings 'redefine';
36 local *DBIx::ContextualFetch::st::execute = sub { die "Database died" };
37 eval { $btaste->update };
38 ::like $@, qr/Database died/s, "We failed";
39 }
40 $btaste->discard_changes;
41 my $still = Film->retrieve('Bad Taste');
42 isa_ok $btaste, 'Film', "We still have Bad Taste";
43 is $btaste->numexplodingsheep, 1, "with 1 sheep";
5a66aa65 44}
45
46if (0) {
6a3bf251 47 my $sheep = Film->maximum_value_of('numexplodingsheep');
48 is $sheep, 1, "1 exploding sheep";
49 {
50 local *DBIx::ContextualFetch::st::execute = sub { die "Database died" };
51 my $sheep = eval { Film->maximum_value_of('numexplodingsheep') };
52 ::like $@, qr/select.*Database died/s,
53 "Handle database death in single value select";
54 }
5a66aa65 55}
56
d9bd5195 57done_testing;