I’m still working at wrapping my head around mockbox and have made lots of progress. I have it working except when I add the logbox injector to the model that I’m testing. Everything falls apart and I’m not sure of the best way to put it back together.
Specifically I’m trying to inject logbox to help the debugging process.
I see to options but I’m not sure how to get either to work. Option 1 being the preferred option.
Made the injected logbox methods work as expected.
Mock the logbox functions such as logger.info(), etc… so that they at least fail gracefully.
Thank you for any guidance.
When unit testing you must mock all dependencies of the method you are testing. That means you want to provide that component with a logbox property with a fake info method that does nothing. In fact, ensuring the info method was called can be one of your tests.
And a quick followup-- I haven’t tested this-- but creating the mock and injecting it will looking something like this in your test setup:
// Create empty mock of a logger and give it a dummy into() method.
mockLogger = createEmptyMock(“coldbox.system.logging.logger”).$(“info”)
// Inject the mock into the model being tested.
model.$property(propertyName=“logger”,mock=mockLogger);