 こんなかんじのアイコンです
 こんなかんじのアイコンですPerl と ミルキィホームズが好きですuse Test::Stub::DBI;
my $count = 0;
my $guard = stub_dbi(
    sth => {
        fetchrow_arrayref => sub { 
            $count++;
            return [0] if ( $count == 1 );
            return;
        }
    },
);
my $dbh = Test::Stub::DBI->connect();
my $sth = $dbh->prepare('SELECT * FROM SOME_TABLE');
$sth->execute();
is_deeply( $sth->fetchrow_arrayref, [0] );
is( $sth->fetchrow_arrayref, undef );
my $count = 0;
my $guard = stub_dbi(
    dbh => { prepare => sub { die "prepare failed" }, },
);
my $dbh = Test::Stub::DBI->connect();
try {
    my $sth = $dbh->prepare('SELECT * FROM SOME_TABLE');
    fail 'exception expected';
} catch {
    like( $_, qr/^prepare failed/ );
};
my $count = 0;
my $guard = stub_dbi(
    dbi => {
        connect => sub { die "connect failed" },
    },
);
try {
    my $dbh = DBI->connect('dbd::dummy');
    fail 'exception expected';
} catch {
    like( $_, qr/^connect failed/ );
};
Use a spacebar or arrow keys to navigate