<cfcomponent displayname="ComponentTester" extends="mxunit.framework.TestCase> <cffunction name="MockForExternalFunction"> ..... </cffunction> <cffunction name=TestComponent> <cfset componentUnderTest = CreateObject("ComponentUnderTest")> <cfset injectMethod(componentUnderTest, this, "MockForExternalFunction", "FunctionUnderTest") /> <cfset componentUnderTest.FunctionUnderTest()> </cffunction> </cfcomponent>
Input method
<cffunction name="injectMethod" output="false" access="public" returntype="void" hint="injects the method from giver into receiver. This is helpful for quick and dirty mocking"> <cfargument name="Receiver" type="any" required="true" hint="the object receiving the method"/> <cfargument name="Giver" type="any" required="true" hint="the object giving the method"/> <cfargument name="FunctionName" type="string" required="true" hint="the function to be injected from the giver into the receiver"/> <cfargument name="FunctionNameInReceiver" type="string" required="false" default="#arguments.functionName#" hint="the function name that you will call. this is useful when you want to inject giver.someFunctionXXX but have it be called as someFunction in your receiver object"> </cffunction>
source share