Pete Freitag Pete Freitag

Forcing CFC Documentation with Unit Tests

coldfusion

Here's a unit test I wrote today that makes sure every public CFC function has a hint attribute specified:

<cffunction name="testPublicFunctionHasHint">
 	<cfset var md = GetMetaData(variables.instance)>
 	<cfset var i = 0>
 	<cfset var f = "">
 	<cfif IsDefined("md.functions") AND ArrayLen(md.functions)>
 		<cfloop from="1" to="#ArrayLen(md.functions)#" index="i">
 			<cfif NOT StructKeyExists(md.functions[i], "access") OR LCase(md.functions[i].access) IS "public">
 				<cfset assertTrue("Missing hint on function: #md.functions[i].name#", StructKeyExists(md.functions[i], "hint"))>
 			</cfif>
 		</cfloop>
 	</cfif>
</cffunction>

You might need to replace the variables.instance with an instance of the component you are testing.


Like this? Follow me ↯

Forcing CFC Documentation with Unit Tests was first published on February 12, 2009.


FuseGuard Web App Firewall for ColdFusion

The FuseGuard Web Application Firewall for ColdFusion & CFML is a high performance, customizable engine that blocks various attacks against your ColdFusion applications.