Bug 13274: Mock new_dbh in t::lib::Mocks
This patch suggests to create a routine to mock C4::Context::_new_dbh.
NOTE: Works the same with and without this secondary patch.
koha-qa tests fine. Less cutting and pasting in the future.
Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
parent
340e23ece5
commit
428a744843
12
t/00-load.t
12
t/00-load.t
|
|
@ -20,8 +20,8 @@ use Modern::Perl;
|
|||
use Test::More;
|
||||
use File::Spec;
|
||||
use File::Find;
|
||||
use Test::MockModule;
|
||||
use DBD::Mock;
|
||||
|
||||
use t::lib::Mocks;
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
|
|
@ -29,13 +29,7 @@ use DBD::Mock;
|
|||
|
||||
=cut
|
||||
|
||||
# Mock the DB connexion and C4::Context
|
||||
my $context = new Test::MockModule('C4::Context');
|
||||
$context->mock( '_new_dbh', sub {
|
||||
my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
|
||||
|| die "Cannot create handle: $DBI::errstr\n";
|
||||
return $dbh;
|
||||
});
|
||||
my $context_module = t::lib::Mocks::mock_dbh;
|
||||
|
||||
# Loop through the C4:: modules
|
||||
my $lib = File::Spec->rel2abs('C4');
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package t::lib::Mocks;
|
|||
|
||||
use Modern::Perl;
|
||||
use C4::Context;
|
||||
|
||||
use DBD::Mock;
|
||||
use Test::MockModule;
|
||||
|
||||
my %configs;
|
||||
|
|
@ -36,4 +38,14 @@ sub mock_preference {
|
|||
});
|
||||
}
|
||||
|
||||
sub mock_dbh {
|
||||
my $context = new Test::MockModule('C4::Context');
|
||||
$context->mock( '_new_dbh', sub {
|
||||
my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
|
||||
|| die "Cannot create handle: $DBI::errstr\n";
|
||||
return $dbh;
|
||||
} );
|
||||
return $context;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue