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