How do I unit test component methods that use the logger?

by glenatron   Last Updated July 12, 2019 15:10 PM

I have unit tests running for my component ( using a bootstrap file to get the usual requirements ) but as soon as I add any logging I start seeing Class '\Joomla\CMS\Log\Log' not found errors. I have tried mocking out the log class, but I don't know how to assign my mock to the global JLog namespace. My tests were passing before I added logging to the methods, so I know that the bootstrap is good in principle, it just seems to be the log that is throwing it.

My setup looks like this:

       public function setUp():void {
            $this->channel_store = $this->createMock('ChannelStore');
            $this->application = $this->getMockBuilder(JApplication::class)
                                ->setMethods(['get', 'set'])
            JFactory::$application = $this->application;

            $this->log = $this->getMockBuilder(JLog::class)

            //  JLog = $this->log; ???

What do I need to do in order to mock out JLog correctly?

Related Questions

Unit-testing controllers

Updated February 16, 2017 14:10 PM

Overwrite the global database driver

Updated July 31, 2017 12:10 PM

How to test a Joomla 2.5 component

Updated August 19, 2015 17:04 PM

Make a checkbox group disappear

Updated March 21, 2017 23:10 PM

Adding Additional Fields to Admin Component

Updated January 14, 2019 16:10 PM