Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Add failing test for execute_array()
Browse files Browse the repository at this point in the history
This is something we've tried using, and hence mocking in tests at $work
recently.
This script fails with the same error we're seeing, so is a good starting
point for adding the functionality:

    $ prove -lv t/030_st_execute_array.t
    t/030_st_execute_array.t ..
    ok 1 - use DBD::Mock;
    ok 2 - use DBI;
    DBD::Mock::st execute_array failed: 3 bind values supplied but 0 expected at t/030_st_execute_array.t line 28.
    not ok 3 - Called execute_array() ok

    #   Failed test 'Called execute_array() ok'
    #   at t/030_st_execute_array.t line 30.
    1..3
    # Looks like you failed 1 test of 3.
    Dubious, test returned 1 (wstat 256, 0x100)
    Failed 1/3 subtests
  • Loading branch information
chizmw committed Sep 27, 2012
1 parent a6f8fa8 commit c9d7bd7
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions t/030_st_execute_array.t
@@ -0,0 +1,33 @@
use strict;
use warnings;

use Test::More;

# test style cribbed from t/013_st_execute_bound_params.t

BEGIN {
use_ok('DBD::Mock');
use_ok('DBI');
}

my $sql = 'INSERT INTO staff (first_name, last_name, dept) VALUES(?, ?, ?)';

{
my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
my $sth = eval { $dbh->prepare( $sql ) };

# taken from: https://metacpan.org/module/DBI#Statement-Handle-Methods
$dbh->{RaiseError} = 1; # save having to check each method call
$sth = $dbh->prepare($sql);

$sth->bind_param_array(1, [ 'John', 'Mary', 'Tim' ]);
$sth->bind_param_array(2, [ 'Booth', 'Todd', 'Robinson' ]);
$sth->bind_param_array(3, "SALES"); # scalar will be reused for each row

eval {
$sth->execute_array( { ArrayTupleStatus => \my @tuple_status } );
};
ok( ! $@, 'Called execute_array() ok' );
}

done_testing;

0 comments on commit c9d7bd7

Please sign in to comment.