]> git.koha-community.org Git - koha.git/commit
Bug 28615: Add a simple way to mock Koha::Logger
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 28 Jun 2021 18:22:33 +0000 (15:22 -0300)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 29 Jun 2021 13:01:02 +0000 (10:01 -0300)
commit5754411d66dffe9563b5ee17527dc70e3a65d419
tree2462358ceb4bae1126ff6df8a365400ba9b11f55
parentce5d409cfd69bdfd45e1c116f9d8f13ed4696f85
Bug 28615: Add a simple way to mock Koha::Logger

This patch introduces a new way to mock and test Koha::Logger.

As the POD says, it is used by calling

    my $logger = t::lib::Mocks::Logger->new();

It then provides convenient methods for testing the logging itself per
log-level:

* warn_is
* warn_like
* debug_is
* debug_like
...

Methods for counting the logging activity and also for clearing the mock
buffer are provided as well. This is covered in the POD and also on the
follow-up, that makes use of this to fix Auth_with_shibboleth.t

To test:

1. Run:
   $ kshell
  k$ prove t/Auth_with_shibboleth.t
=> FAIL: Tests fail! It expects some warns but they are not returned by
the lib
2. Apply this patches
3. Repeat 1
=> SUCCESS: Tests pass! The tests now use the new lib, and they
correctly find the logging Auth_with_shibboleth.pm does on function
calls.
4. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
t/lib/Mocks/Logger.pm [new file with mode: 0644]