Bug 21086 - Wrong mock of DateTime->now in tests
Summary: Wrong mock of DateTime->now in tests
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Test Suite (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low normal (vote)
Assignee: Jonathan Druart
QA Contact: Josef Moravec
URL:
Keywords:
Depends on: 19705 20287
Blocks:
  Show dependency treegraph
 
Reported: 2018-07-18 21:11 UTC by Jonathan Druart
Modified: 2019-10-14 19:58 UTC (History)
3 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 21086: Fix wrong mock of DateTime->now (2.56 KB, patch)
2018-07-18 21:14 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 21086: Fix wrong mock of DateTime->now (2.60 KB, patch)
2018-07-19 06:04 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 21086: Fix wrong mock of DateTime->now (2.66 KB, patch)
2018-07-19 11:29 UTC, Josef Moravec
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2018-07-18 21:11:27 UTC
prove t/db_dependent/DecreaseLoanHighHolds.t
t/db_dependent/DecreaseLoanHighHolds.t .. 1/17 Can't locate object method "truncate" via package "80" (perhaps you forgot to load "80"?) at /home/vagrant/kohaclone/C4/Circulation.pm line 3497.

What is happening:
We mock DateTime->now in the script to avoid the date comparaisons to fail on slow servers (see bug 19705).

  my $now_value       = DateTime->now();
  my $mocked_datetime = Test::MockModule->new('DateTime');
  $mocked_datetime->mock( 'now', sub { return $now_value; } );


Since bug 20287, we have the following calls:
Koha::Patron->store => Koha::Patron::Category->get_expiry_date

which does:
221         return $date->add( months => $self->enrolmentperiod, end_of_month => 'limit' );    

as enrolmentperiod is generated by t::lib::TestBuilder, it can be quite big, and so the date change from one call to the others.

The failure is actually coming from the date becoming > 9999, which is not handled correctly, on purpose, by Koha::DateUtils (infinite)
Comment 1 Jonathan Druart 2018-07-18 21:14:21 UTC
Created attachment 77093 [details] [review]
Bug 21086: Fix wrong mock of DateTime->now

prove t/db_dependent/DecreaseLoanHighHolds.t
t/db_dependent/DecreaseLoanHighHolds.t .. 1/17 Can't locate object method
 "truncate" via package "80" (perhaps you forgot to load "80"?) at /home/vagrant/kohaclone/C4/Circulation.pm line 3497.

What is happening:
We mock DateTime->now in the script to avoid the date comparaisons to fail on
slow servers (see bug 19705).

  my $now_value       = DateTime->now();
  my $mocked_datetime = Test::MockModule->new('DateTime');
  $mocked_datetime->mock( 'now', sub { return $now_value; } );

Since bug 20287, we have the following calls:
Koha::Patron->store => Koha::Patron::Category->get_expiry_date

which does:
221         return $date->add( months => $self->enrolmentperiod, end_of_month => 'limit' );

as enrolmentperiod is generated by t::lib::TestBuilder, it can be quite big, and so
the date change from one call to the others.

The failure is actually coming from the date becoming > 9999, which is not handled correctly,
on purpose, by Koha::DateUtils (infinite)

On the way this patch fixes the other occurrence, in Sitemapper.t (just in case)

Test plan:
Make sure the tests pass now.
Comment 2 Katrin Fischer 2018-07-19 06:04:40 UTC
Created attachment 77098 [details] [review]
Bug 21086: Fix wrong mock of DateTime->now

prove t/db_dependent/DecreaseLoanHighHolds.t
t/db_dependent/DecreaseLoanHighHolds.t .. 1/17 Can't locate object method
 "truncate" via package "80" (perhaps you forgot to load "80"?) at /home/vagrant/kohaclone/C4/Circulation.pm line 3497.

What is happening:
We mock DateTime->now in the script to avoid the date comparaisons to fail on
slow servers (see bug 19705).

  my $now_value       = DateTime->now();
  my $mocked_datetime = Test::MockModule->new('DateTime');
  $mocked_datetime->mock( 'now', sub { return $now_value; } );

Since bug 20287, we have the following calls:
Koha::Patron->store => Koha::Patron::Category->get_expiry_date

which does:
221         return $date->add( months => $self->enrolmentperiod, end_of_month => 'limit' );

as enrolmentperiod is generated by t::lib::TestBuilder, it can be quite big, and so
the date change from one call to the others.

The failure is actually coming from the date becoming > 9999, which is not handled correctly,
on purpose, by Koha::DateUtils (infinite)

On the way this patch fixes the other occurrence, in Sitemapper.t (just in case)

Test plan:
Make sure the tests pass now.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 3 Josef Moravec 2018-07-19 11:29:25 UTC
Created attachment 77101 [details] [review]
Bug 21086: Fix wrong mock of DateTime->now

prove t/db_dependent/DecreaseLoanHighHolds.t
t/db_dependent/DecreaseLoanHighHolds.t .. 1/17 Can't locate object method
 "truncate" via package "80" (perhaps you forgot to load "80"?) at /home/vagrant/kohaclone/C4/Circulation.pm line 3497.

What is happening:
We mock DateTime->now in the script to avoid the date comparaisons to fail on
slow servers (see bug 19705).

  my $now_value       = DateTime->now();
  my $mocked_datetime = Test::MockModule->new('DateTime');
  $mocked_datetime->mock( 'now', sub { return $now_value; } );

Since bug 20287, we have the following calls:
Koha::Patron->store => Koha::Patron::Category->get_expiry_date

which does:
221         return $date->add( months => $self->enrolmentperiod, end_of_month => 'limit' );

as enrolmentperiod is generated by t::lib::TestBuilder, it can be quite big, and so
the date change from one call to the others.

The failure is actually coming from the date becoming > 9999, which is not handled correctly,
on purpose, by Koha::DateUtils (infinite)

On the way this patch fixes the other occurrence, in Sitemapper.t (just in case)

Test plan:
Make sure the tests pass now.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 4 Nick Clemens 2018-07-19 17:37:15 UTC
Awesome work all!

Pushed to master for 18.11
Comment 5 Martin Renvoize 2018-08-02 13:47:39 UTC
Depends on bug 20287 not in 18.05.x series, will not be backported.