On Wed, Jun 20, 2012 at 11:10 PM, Richard Mueller <rbmuel
...@gmail.com> wrote:
> We are not using and IoC framework just yet so is it feasible to just set
> accessors="true" then create a someOtherObj property.
> Then before the original obj init, use myObject.setSomeOtherObj (
> CreateObject("component", "someOtherObj") ) ? Making foo look a little more
> like
> <cffunction name="foo">
> <cfset local.bar = variables.someOtherObj.doSomething() />
> </cffunction>
> Otherwise I think the init may get a bit messy with objects never being
> used.
> On Wednesday, June 20, 2012 7:37:38 PM UTC-5, Marc Esher wrote:
>> On Wed, Jun 20, 2012 at 8:24 PM, James Holmes <james.hol...@gmail.com>
>> wrote:
>> > 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:
>> <cffunction name="foo">
>> <cfset local.bar = getBar() />
>> </cffunction>
>> <cffunction name="getBar">
>> <cfreturn CreateObject("component", "someOtherObj")>
>> </cffunction>
>> 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.
>> Marc
>> > --
>> > Shu Ha Ri: Agile and .NET blog
>> > http://www.bifrost.com.au/
>> > On 21 June 2012 10:08, Richard Mueller <rbmuel...@gmail.com> wrote:
>> >> Hi - I'm trying to mock a dependency in one of my methods, which is
>> >> currently assigned to the local scope, and I'm having trouble using the
>> >> injectProperty method to achieve this. I'm fairly new to Mighty Mock
>> >> so I
>> >> can't be certain I'm missing something obvious.
>> >> <cffunction name="foo">
>> >> <cfset local.bar = CreateObject("component", "someOtherObj") />
>> >> //or how about?
>> >> <cfset someOtherFunction(CreateObject("component", "myOtherObj") />
>> >> </cffunction>
>> >> Any thoughts/techniques on either of these?
>> >> Thanks
>> >> Richard
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "mxunit" group.
>> >> To view this discussion on the web visit
>> >> https://groups.google.com/d/msg/mxunit/-/ZQKKIiyG-i4J.
>> >> To post to this group, send email to mxunit@googlegroups.com.
>> >> To unsubscribe from this group, send email to
>> >> mxunit+unsubscribe@googlegroups.com.
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/mxunit?hl=en.
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "mxunit" group.
>> > To post to this group, send email to mxunit@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > mxunit+unsubscribe@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/mxunit?hl=en.
> --
> You received this message because you are subscribed to the Google Groups
> "mxunit" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mxunit/-/r_8y3Z91n7EJ.
> To post to this group, send email to mxunit@googlegroups.com.
> To unsubscribe from this group, send email to
> mxunit+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mxunit?hl=en.