I have a function “foo” with an argument where type=“binary”. In that function, it passes the binary object on to another method “bar” on an object “baz” I’m mocking with mockbox in my “foo” unit test. When “foo” is called in the unit test it will hit the call to the mocked “bar” method, try to pass in the binary object, and hit an exception:
Application: JSON serialization failure: Unable to serialize binary data to JSON.
It’s reporting that this happens in coldbox/system/testing/MockBox.cfc: 478
I can’t really alter the fact that I need to pass around binary, or that I need to mock the dependency (it sends emails, which I don’t want it to do every time the test is run).
Can you show the stack trace of the error? Where at in the framework is the issue? I’m guessing it might be related to the automatic tracking of method params inside MockBox.
Can you show the stack trace of the error? Where at in the framework is the issue? I’m guessing it might be related to the automatic tracking of method params inside MockBox.
I’m not sure how to get the full stack trace or tag context, but the component and line number are:
coldbox/system/testing/MockBox.cfc line 478
which is
`
serializedArgs &= serializeJSON(argOrderedTree[arg]);
`
in the normalizeArguments function.
Here’s a test case.
The unit test component:
component extends=“coldbox.system.testing.BaseTestCase” {
public void function testFoo() {
local.myModel = variables.mockBox.createMock(“model.myModel”);
local.myModel.$(“bar”);
// file (it just expects something binary, so we’ll mock away)
local.file = toBinary(toBase64(“Open the pod bay doors, Hal!”));
local.myModel.foo(local.file); // here’s where the wheels come off
}
}
And the actual cfc I’m writing the test for (model/myModel):
component
{
public function foo(
required binary file
) {
// do some stuff
local.result = bar(arguments.file);
// do other stuff
}
public function bar(
required binary file
) {
// do things
}
}