Does anyone have a somewhat more complete example of "Targeted Handler
Testing" beyond the "Basic Setup" shown at
http://wiki.coldbox.org/wiki/WhatsNew:3.0.0.cfm#New_Targeted_Handler_Testing?
I generated a test application using the Platform Utilities (Simple Template).
I verified that the generated integration test of the General handler worked.
I added a "Targeted Handler Test" (TargetedGeneraTest.cfc):
/**
* @handler Sample.handlers.General
* UDFLibraryFile ""
*/
component extends="coldbox.system.testing.BaseHandlerTest" {
function testindex(){
var rc = mockRequestContext.getCollection();
var prc = mockRequestContext.getCollection(private=true);
handler.index(mockRequestContext,rc,prc);
debug(rc);
assertEquals("Welcome to ColdBox!", rc.welcomeMessage, "Failed to
assert welcome message");
}
}
This works.
I added an event to my test application's General handler that invokes a model:
<cffunction name="add" returntype="void" output="false" hint="My main event">
<cfargument name="event">
<cfargument name="rc">
<cfargument name="prc">
<cfset rc.result = getmodel("Math").add(rc.arg1, rc.arg2)>
<cfset event.renderdata(data=rc.result)>
</cffunction>
The Math.add method adds arg1 and arg2 and returns the result.
I added a testadd method to my GeneralTest.cfc integration test:
<cffunction name="testadd" returntype="void" output="false">
<cfscript>
var event = "";
URL.arg1 = 2;
URL.arg2 = 3;
event = execute("general.add");
assertEquals(5, event.getValue("result",""), "Failed to assert result=5");
</cfscript>
</cffunction>
This works.
I added a testadd() method to TargetedGeneralTest.cfc:
function testadd(){
var rc = mockRequestContext.getCollection();
var prc = mockRequestContext.getCollection(private=true);
rc.arg1 = 2;
rc.arg2 = 3;
handler.add(mockRequestContext,rc,prc);
assertEquals(5, rc.result, "Failed to assert result=5");
}
This gets:
Variable CONTROLLER is undefined.
at line 116 of FrameworkSupertype.cfc which is the following line in
FrameworkSupertype.getModel:
<cfreturn controller.getWireBox().getInstance(argumentCollection=arguments)>
I took a stab at adding a controller reference to the handler via the
setup function:
void function setup(){
super.setup();
handler.$property("controller","variables",mockController);
}
Now, I get the following error:
The method getInstance was not found in component
C:\inetpub\wwwroot\coldbox\system\ioc\Injector.cfc.
I appears that my controller reference found getWireBox() which found
ioc/Injector.cfc which certainly defines getInstance() so I'm a little
baffled by this error.
Can anyone get me back on track?
Thanks,
Bob