[Koha-bugs] [Bug 28615] Add a simple way to mock Koha::Logger

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Tue Jun 22 22:58:10 CEST 2021


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=28615

--- Comment #1 from Tomás Cohen Arazi <tomascohen at gmail.com> ---
Created attachment 122306
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=122306&action=edit
Bug 28615: Add a simple way to mock Koha::Logger

This patch introduces a new method for mocking the Koha::Logger.

As the POD says, it is used by calling

    t::lib::Mocks::mock_logger({ warn => 1 });

The warn parameter is optional, and controls wether any use of the
logger will warn. The idea is that we can use that to write tests (that
catch those warnings and thus the codepaths that trigger the call are
properly tested, the same for the parameters to the call).

I did a

    $ git grep 'Koha::Logger->get->debug'
    $ git grep 'Koha::Logger->get->warn'

In order to find places in which we use the logger, and then find a test
that would trigger it... to provide a useful test case. But I didn't...

I tried with Overdues.t and Circulation.t and Export/Record.t but none
worked [1]. So this is my test plan:

1. Apply this patch
2. Add the following line to t/db_dependent/Search.t just below the
   imports:

t::lib::Mocks::mock_logger({ warn => 1 });

3. Run:
   $ kshell
  k$ prove t/db_dependent/Search.t
=> SUCCESS: Suddenly every call to the logger is printing the parameter
it got passed.
4. Sign off :-D

[1] This is actually frustrating, because it means those codepaths are
not traversed by the tests...

Signed-off-by: Tomas Cohen Arazi <tomascohen at theke.io>

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list