[testbox] mock cache

21 views
Skip to first unread message

Peter Boughton

unread,
Mar 23, 2015, 6:51:49 AM3/23/15
to col...@googlegroups.com
Some of our services have caches injected using Wirebox.

When trying to run the test harness, this errors with the message "The DSL Definition ... did not produce any resulting dependency"

The DSL Definition {JAVACAST={null},NAME={cache},ARGNAME={},DSL={cachebox:clientDB},VALUE={null},REQUIRED={true},SCOPE={variables},REF={null}} did not produce any resulting dependency



I can't find any examples of how to mock a cache - I tried adding the following to beforeAll in the base testcase:

Variables.Cachebox = getController().getCacheBox();

if ( NOT ArrayFind(Cachebox.getCacheNames(),'clientDB') )
{
var cache = new coldbox.system.cache.providers.MockProvider();
cache.setName('clientDB');
Cachebox.addCache(cache);
}

That doesn't do anything - same error.

How do I fix it?

Peter Boughton

unread,
Mar 23, 2015, 7:13:29 AM3/23/15
to col...@googlegroups.com
I've worked around this by updating a couple of core files:

/coldbox/system/ioc/dsl/CacheBoxDSL.cfc after line 46:

else if (true)
{
return new coldbox.system.cache.providers.MockProvider();
}

Meaning the MockProvider is returned for any unknown DSL.

That mostly worked, but I then had to wrap StructKeyExists around the MockProvider.cfc get return, to receive nulls when the key doesn't exist.

<cfif StructKeyExists(instance.cache,arguments.objectKey)>
<cfreturn instance.cache[ arguments.objectKey ]>
</cfif>


Not a solution, but at least it allows me to check the tests are passing.

Peter Boughton

unread,
Mar 30, 2015, 5:26:02 AM3/30/15
to col...@googlegroups.com
Our Coldbox app has a cache injected via Wirebox:

    property name="cache" inject="cachebox:clientDB"

This works fine in the application, but in Testbox it errors with the message:

> The DSL Definition ... did not produce any resulting dependency

What needs to be done with Mockbox to create a mock cache so the tests can run?
Reply all
Reply to author
Forward
0 new messages