Created
August 20, 2010 17:35
-
-
Save draegtun/540782 to your computer and use it in GitHub Desktop.
Test::MockDBI issue from Stackoverflow question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
BEGIN { push @ARGV, "--dbitest=1"; } | |
use 5.012; | |
use warnings; | |
use Test::More; | |
use Test::MockDBI ':all'; | |
our $mock_dbi = Test::MockDBI::get_instance; | |
our $dbh = DBI->connect(q{}, q{}, q{}); | |
run_test( 'many entries', [ | |
{ username => '1234567' }, | |
{ username => '2345678' }, | |
]); | |
run_test( 'no entries', [] ); | |
done_testing; | |
sub run_test { | |
my ($msg, $data) = @_; | |
$mock_dbi->set_retval_scalar( | |
MOCKDBI_WILDCARD, | |
$msg, | |
$data, | |
); | |
is_deeply( get_mock_user($msg), get_data_user($data), $msg ); | |
} | |
sub get_mock_user { | |
$dbh->prepare( $_[0] ); | |
get_data_user( $dbh->fetchrow_arrayref ); | |
} | |
sub get_data_user { | |
[ map { $_->{username} } @{ $_[0] } ]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See: http://stackoverflow.com/questions/3511268/using-testmockdbi-multiple-times-with-different-results/3533053#3533053