| 1 |
use 5.008; |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use Test::More; |
| 7 |
|
| 8 |
BEGIN { |
| 9 |
use_ok('DBD::Mock'); |
| 10 |
use_ok('DBI'); |
| 11 |
} |
| 12 |
|
| 13 |
my $sql = 'SELECT * FROM foo WHERE bar = ? AND baz = ?'; |
| 14 |
|
| 15 |
{ |
| 16 |
my $dbh = DBI->connect( 'DBI:Mock:', '', '' ); |
| 17 |
my $sth = eval { $dbh->prepare( $sql ) }; |
| 18 |
eval { $sth->execute( 'baz', 'bar' ) }; |
| 19 |
ok( ! $@, 'Called execute() ok (inline params)' ); |
| 20 |
my $t_params = $sth->{mock_my_history}->bound_params; |
| 21 |
is( scalar @{ $t_params }, 2, |
| 22 |
'Correct number of parameters bound (inline; method on tracker)' ); |
| 23 |
is( $t_params->[0], 'baz', |
| 24 |
'Statement handle stored bound inline parameter (method on tracker)' ); |
| 25 |
is( $t_params->[1], 'bar', |
| 26 |
'Statement handle stored bound inline parameter (method on tracker)' ); |
| 27 |
my $a_params = $sth->{mock_my_history}->bound_params; |
| 28 |
is( scalar @{ $a_params }, 2, |
| 29 |
'Correct number of parameters bound (inline; attribute)' ); |
| 30 |
is( $a_params->[0], 'baz', |
| 31 |
'Statement handle stored bound inline parameter (attribute)' ); |
| 32 |
is( $a_params->[1], 'bar', |
| 33 |
'Statement handle stored bound inline parameter (attribute)' ); |
| 34 |
} |
| 35 |
|
| 36 |
done_testing(); |