Bugzilla – Attachment 64009 Details for
Bug 18226
Remove "use Test::DBIx::Class" instantiations' dangerous code duplication
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18226 - Remove "use Test::DBIx::Class" instantiations' dangerous code duplication. Replace mock_dbh 2
Bug-18226---Remove-use-TestDBIxClass-instantiation.patch (text/plain), 4.20 KB, created by
Jonathan Druart
on 2017-06-05 20:54:50 UTC
(
hide
)
Description:
Bug 18226 - Remove "use Test::DBIx::Class" instantiations' dangerous code duplication. Replace mock_dbh 2
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2017-06-05 20:54:50 UTC
Size:
4.20 KB
patch
obsolete
>From 00af5cdb8fb301e7ca410c0a82a294f08132acbd Mon Sep 17 00:00:00 2001 >From: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> >Date: Wed, 8 Mar 2017 17:34:28 +0200 >Subject: [PATCH] Bug 18226 - Remove "use Test::DBIx::Class" instantiations' > dangerous code duplication. Replace mock_dbh 2 > >Couldn't make the tests pass using Test::DBIx::Class, so reverted to the "usual way" since these tests are >in db_dependent anyway. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > t/db_dependent/Circulation/CalcDateDue.t | 40 ++++++++++++++------------------ > t/lib/Mocks.pm | 9 ------- > 2 files changed, 17 insertions(+), 32 deletions(-) > >diff --git a/t/db_dependent/Circulation/CalcDateDue.t b/t/db_dependent/Circulation/CalcDateDue.t >index d1f39de662..e533806da4 100644 >--- a/t/db_dependent/Circulation/CalcDateDue.t >+++ b/t/db_dependent/Circulation/CalcDateDue.t >@@ -7,31 +7,29 @@ use Test::MockModule; > use DBI; > use DateTime; > use t::lib::Mocks; >- >-BEGIN { >- t::lib::Mocks::mock_dbh; >-} >+use t::lib::TestBuilder; > > use_ok('C4::Circulation'); > >-my $dbh = C4::Context->dbh(); >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+my $builder = t::lib::TestBuilder->new; > >+my $categorycode = 'B'; >+my $itemtype = 'MX'; >+my $branchcode = 'FPL'; > my $issuelength = 10; > my $renewalperiod = 5; > my $lengthunit = 'days'; > >-my $mock_undef = [ >- [] >-]; >- >-my $mock_loan_length = [ >- ['issuelength', 'renewalperiod', 'lengthunit'], >- [$issuelength, $renewalperiod, $lengthunit] >-]; >- >-my $categorycode = 'B'; >-my $itemtype = 'MX'; >-my $branchcode = 'FPL'; >+Koha::Database->schema->resultset('Issuingrule')->create({ >+ categorycode => $categorycode, >+ itemtype => $itemtype, >+ branchcode => $branchcode, >+ issuelength => $issuelength, >+ renewalperiod => $renewalperiod, >+ lengthunit => $lengthunit, >+}); > > #Set syspref ReturnBeforeExpiry = 1 and useDaysMode = 'Days' > t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1); >@@ -41,10 +39,8 @@ my $dateexpiry = '2013-01-01'; > > my $borrower = {categorycode => 'B', dateexpiry => $dateexpiry}; > my $start_date = DateTime->new({year => 2013, month => 2, day => 9}); >-$dbh->{mock_add_resultset} = $mock_loan_length; > my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower ); > is($date, $dateexpiry . 'T23:59:00', 'date expiry'); >-$dbh->{mock_add_resultset} = $mock_loan_length; > $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 ); > > >@@ -54,11 +50,9 @@ t::lib::Mocks::mock_preference('useDaysMode', 'noDays'); > > $borrower = {categorycode => 'B', dateexpiry => $dateexpiry}; > $start_date = DateTime->new({year => 2013, month => 2, day => 9}); >-$dbh->{mock_add_resultset} = $mock_loan_length; > $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower ); > is($date, $dateexpiry . 'T23:59:00', 'date expiry'); > >-$dbh->{mock_add_resultset} = $mock_loan_length; > $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 ); > > >@@ -68,10 +62,10 @@ t::lib::Mocks::mock_preference('useDaysMode', 'Days'); > > $borrower = {categorycode => 'B', dateexpiry => $dateexpiry}; > $start_date = DateTime->new({year => 2013, month => 2, day => 9}); >-$dbh->{mock_add_resultset} = $mock_loan_length; > $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower ); > is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "date expiry ( 9 + $issuelength )"); > >-$dbh->{mock_add_resultset} = $mock_loan_length; > $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 ); > is($date, '2013-02-' . (9 + $renewalperiod) . 'T23:59:00', "date expiry ( 9 + $renewalperiod )"); >+ >+$schema->storage->txn_rollback; >diff --git a/t/lib/Mocks.pm b/t/lib/Mocks.pm >index 46a87cb799..da207399ce 100644 >--- a/t/lib/Mocks.pm >+++ b/t/lib/Mocks.pm >@@ -41,13 +41,4 @@ sub mock_preference { > }); > } > >-sub mock_dbh { >- our $context = new Test::MockModule('Koha::Database'); >- $context->mock( '_new_schema', sub { >- my $dbh = Koha::Schema->connect( 'DBI:Mock:', '', '' ); >- return $dbh; >- } ); >- return $context; >-} >- > 1; >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18226
:
60885
|
60886
|
60920
|
60923
|
62960
|
62961
|
62962
|
62968
|
62969
|
62970
|
63688
|
63689
|
63999
|
64008
| 64009 |
64010
|
64011
|
64012
|
64013