Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Mocking Dependencies in local scope
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Richard Mueller  
View profile  
 More options Jun 20 2012, 8:08 pm
From: Richard Mueller <rbmuel...@gmail.com>
Date: Wed, 20 Jun 2012 17:08:46 -0700 (PDT)
Local: Wed, Jun 20 2012 8:08 pm
Subject: Mocking Dependencies in local scope

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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Holmes  
View profile  
 More options Jun 20 2012, 8:24 pm
From: James Holmes <james.hol...@gmail.com>
Date: Thu, 21 Jun 2012 10:24:49 +1000
Local: Wed, Jun 20 2012 8:24 pm
Subject: Re: [mxunit:3634] Mocking Dependencies in local scope

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.

--
Shu Ha Ri: Agile and .NET blog
http://www.bifrost.com.au/

On 21 June 2012 10:08, Richard Mueller <rbmuel...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marc Esher  
View profile  
 More options Jun 20 2012, 8:37 pm
From: Marc Esher <marc.es...@gmail.com>
Date: Wed, 20 Jun 2012 20:37:38 -0400
Local: Wed, Jun 20 2012 8:37 pm
Subject: Re: [mxunit:3635] Mocking Dependencies in local scope

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Mueller  
View profile  
 More options Jun 20 2012, 11:10 pm
From: Richard Mueller <rbmuel...@gmail.com>
Date: Wed, 20 Jun 2012 20:10:46 -0700 (PDT)
Local: Wed, Jun 20 2012 11:10 pm
Subject: Re: [mxunit:3635] Mocking Dependencies in local scope

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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marc Esher  
View profile  
 More options Jun 21 2012, 9:42 am
From: Marc Esher <marc.es...@gmail.com>
Date: Thu, 21 Jun 2012 09:42:58 -0400
Local: Thurs, Jun 21 2012 9:42 am
Subject: Re: [mxunit:3638] Mocking Dependencies in local scope
exactly


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »