On Wed, Jun 20, 2012 at 8:24 PM, James Holmes <james.hol...
> Can you consider altering the architecture so that the object (or at least
> the method) takes in the instance of someOtherObj? If you need new instances
> each time, perhaps the object can take in a factory that creates them
> instead. This will give you loose coupling and allow for easy testing.
Right on: if it's a dependency, make it injectable, either directly or
via a factory
Failing that, the next best thing is to mimic the factory approach and
do something like this:
<cfset local.bar = getBar() />
<cfreturn CreateObject("component", "someOtherObj")>
And then in your test, you can use injectMethod() to override the
getBar method to have it return the object you want.
But the fact that you need to do that is a huge red flag that
dependency injection is the answer here.