Forcing CFC Documentation with Unit Tests

February 12, 2009

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"))>

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

2 people found this page useful, what do you think?

Recent Entries


did you hack my cf?