| 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 |
ok( ! $@, 'Statement handle prepared ok' ); |
| 19 |
is( ref( $sth ), 'DBI::st', |
| 20 |
'Statement handle returned of the proper type' ); |
| 21 |
is( $sth->{mock_my_history}->statement, $sql, |
| 22 |
'Statement handle stores SQL (method on tracker)' ); |
| 23 |
is( $sth->{mock_statement}, $sql, |
| 24 |
'Statement handle stores SQL (attribute)' ); |
| 25 |
is( $sth->{mock_is_executed}, 'no', |
| 26 |
'Execute flag not set yet' ); |
| 27 |
my $rows = eval { $sth->execute() }; |
| 28 |
ok( ! $@, 'Called execute() ok (no params)' ); |
| 29 |
is($rows, '0E0', '... we got back 0E0 for num of rows'); |
| 30 |
is( $sth->{mock_is_executed}, 'yes', |
| 31 |
'Execute flag set after execute()' ); |
| 32 |
my $t_params = $sth->{mock_my_history}->bound_params; |
| 33 |
is( scalar @{ $t_params }, 0, |
| 34 |
'No parameters tracked (method on tracker)' ); |
| 35 |
my $a_params = $sth->{mock_params}; |
| 36 |
is( scalar @{ $a_params }, 0, |
| 37 |
'No parameters tracked (attribute)' ); |
| 38 |
is( $sth->{mock_is_finished}, 'no', |
| 39 |
'Finished flag not set yet' ); |
| 40 |
eval { $sth->finish }; |
| 41 |
ok( ! $@, 'Called finish() ok' ); |
| 42 |
is( $sth->{mock_is_finished}, 'yes', |
| 43 |
'Finished flag set after finish()' ); |
| 44 |
} |
| 45 |
|
| 46 |
done_testing(); |