[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
Wed Jun 23 04:33:47 CEST 2021


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

--- Comment #10 from David Cook <dcook at prosentient.com.au> ---
(In reply to Tomás Cohen Arazi from comment #9)
> My goal is to make it trivial for devs to test behavior. There's nothing
> intrinsically bad about mocking the logger. Or doing it your way.
> 
> You are actually mocking some other part of the same thing (the
> configuration) and manually capturing STDOUT/STDERR instead of 'the warn
> trick'.

I wouldn't refer to configuration as mocking. And you don't have to manually
capture STDOUT/STDERR. You can use brian d foy's module Test::Output. I use
that on other Perl projects for my unit tests. Koha doesn't require it, so I
couldn't use it for my tests.

> Your code is correct, and makes my point. Compare that boilerplate for just
> testing the logger is called, to just calling:

I was in a hurry to get that unit test done that day, but Test::Output can be
used so that you don't have all that boiler plate.

Using Test::Output and Test::Warn would be a more accurate test of how the code
actually works in production. 

> Anyways, I always like different opinions and am open about this.

Same. I like to avoid mocks wherever possible and use the real thing, but I
figure code speaks louder than words, and I'm not planning on working on my
logging testing any time soon or adding Test::Output as a dependency. I thought
that I would offer an alternative though, especially since I think we really
should stop using Log4Perl to log to files and instead log to STDERR. It'll
solve log file permission issues and allow us to leverage built-in web server
functionality for logging.

But that's just my opinion.

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


More information about the Koha-bugs mailing list