1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
14 [ on_connect_do => "_NOPE_" ],
15 [ on_connect_call => sub { shift->_dbh->do("_NOPE_") } ],
16 [ on_connect_call => "_NOPE_" ],
18 for my $method (qw( ensure_connected _server_info _get_server_version _get_dbh )) {
20 my $s = DBICTest->init_schema(
22 on_disconnect_call => sub { fail 'Disconnector should not be invoked' },
26 my $storage = $s->storage;
27 $storage = $storage->master if $ENV{DBICTEST_VIA_REPLICATED};
29 ok( ! $storage->connected, 'Starting unconnected' );
31 my $desc = "calling $method with broken on_connect action @{[ explain $conn_args ]}";
33 throws_ok { $storage->$method }
35 "Throwing correctly when $desc";
37 ok( ! $storage->connected, "Still not connected after $desc" );
39 # this checks that the on_disconect_call FAIL won't trigger
45 [ on_disconnect_do => "_NOPE_" ],
46 [ on_disconnect_call => sub { shift->_dbh->do("_NOPE_") } ],
47 [ on_disconnect_call => "_NOPE_" ],
49 my $s = DBICTest->init_schema( no_deploy => 1, @$conn_args );
51 my $storage = $s->storage;
52 $storage = $storage->master if $ENV{DBICTEST_VIA_REPLICATED};
54 my $desc = "broken on_disconnect action @{[ explain $conn_args ]}";
57 my $dbh = $storage->dbh;
59 ok ($dbh->FETCH('Active'), 'Freshly connected DBI handle is healthy');
61 warnings_exist { eval { $storage->disconnect } } [
62 qr/\QDisconnect action failed\E .+ _NOPE_ \b/x
63 ], "Found warning of failed $desc";
65 ok (! $dbh->FETCH('Active'), "Actual DBI disconnect was not prevented by $desc" );
68 my $schema = DBICTest->init_schema;
73 $schema->resultset('CD')->create({ title => 'vacation in antarctica' })
75 qr/DBI Exception.+(?x:
76 \QNOT NULL constraint failed: cd.artist\E
78 \Qcd.artist may not be NULL\E
80 ); # as opposed to some other error
81 }, [], 'No warnings besides exception' );
83 my $dbh = $schema->storage->dbh;
87 $dbh->do ('INSERT INTO nonexistent_table VALUES (1)')
89 qr/DBI Exception.+no such table.+nonexistent_table/s,
90 'DBI exceptions properly handled by dbic-installed callback'
93 # This usage is a bit unusual but it was actually seen in the wild
94 # destruction of everything except the $dbh should use the proper
98 if ( !!DBIx::Class::_ENV_::PEEPEENESS ) {
99 skip "Your perl version $] appears to leak like a sieve - skipping garbage collected \$schema test", 1;
105 $dbh->do ('INSERT INTO nonexistent_table VALUES (1)')
107 qr/DBI Exception.+unhandled by DBIC.+no such table.+nonexistent_table/s,
108 'callback works after $schema is gone'