My favorites | Sign in
Project Home Downloads Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 145 attachment: mxunit-issue-145-patch-with-tests.diff (9.0 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
Index: framework/PublicProxyMaker.cfc
===================================================================
--- framework/PublicProxyMaker.cfc (revision 955)
+++ framework/PublicProxyMaker.cfc (working copy)
@@ -8,11 +8,11 @@


<cffunction name="makePublic" access="public" hint="creates a public method proxy for the indicated private method for the passed-in object" returntype="WEB-INF.cftags.component">
-
+
<cfargument name="ObjectUnderTest" required="true" type="WEB-INF.cftags.component" hint="an instance of the object with a private method to be proxied">
<cfargument name="privateMethodName" required="true" type="string" hint="name of the private method to be proxied">
<cfargument name="proxyMethodName" required="false" type="string" default="" hint="name of the proxy method name to be used; if not passed, defaults to the name of the private method prefixed with an underscore">
-
+
<cfset var md = getMetadata(ObjectUnderTest)>
<cfset var methodStruct = findMethodStruct(md,privateMethodName)>
<cfset var output = "">
@@ -28,44 +28,44 @@
<cfif StructIsEmpty(methodStruct)>
<cfthrow message="Attempting to make public proxy for private method: method named #privateMethodName# did not exist in object of type #md.name#">
</cfif>
-
+
<cfif NOT len(trim(proxyMethodName))>
<cfset arguments.proxyMethodName = "#privateMethodName#">
</cfif>
-
+
<cfset cfcnotation = arguments.proxyMethodName & "_#createUUID()#">
<cfset file = cfcnotation & ".cfc">
<cfif StructKeyExists(methodStruct,"returntype") and methodStruct.returntype eq "void">
<cfset componentReturnTag = "set">
</cfif>
-
+
<!--- for now, it seems safest to just do this every time, even if it's technically overkill --->
<cfif not DirectoryExists(dir)>
<cfdirectory action="create" directory="#dir#">
</cfif>
-
+
<!--- generate a CFC that contains a public method. this method will call the private method we want to call --->
- <cfset s_args = constructArgumentsTags(methodStruct)>
+ <cfset s_argTags = constructArgumentsTags(methodStruct)>

<cfoutput>
<cfsavecontent variable="output">
- <%cfcomponent% extends="#md.name#">
+ <%cfcomponent extends="#md.name#"%>

<%cffunction name="#arguments.proxyMethodName#" access="public"%>
- #s_args.tags#
- <%cf#componentReturnTag# #renamedExistingMethod#(#s_args.args#)%>
+ #s_argTags#
+ <%cf#componentReturnTag# #renamedExistingMethod#(argumentCollection=arguments)%>
<%/cffunction%>
-
+
<%/cfcomponent%>
</cfsavecontent>
</cfoutput>
<cfset cfcode = replace(output,"%","","all")>
<cffile action="write" file="#dir##file#" output="#cfcode#">
-
+
<!--- now, create an instance of that generated object --->
<cfset proxy = createObject("component","mxunit.framework.generated.#cfcnotation#")>
<!--- NOTE: all of this rejiggering is so that we can call the private method directly rather than having to call a differently-named proxy method! --->
-
+
<!--- move the current privateMethod into a newly named method --->
<cfset blender._mixinAll(arguments.ObjectUnderTest,blender)>
<cfset arguments.ObjectUnderTest._mixin(renamedExistingMethod,arguments.ObjectUnderTest._getComponentVariable(privateMethodName))>
@@ -73,7 +73,7 @@
<cfset arguments.ObjectUnderTest._mixin(arguments.proxyMethodName,proxy[arguments.proxyMethodName])>

<!--- cleanup; i doubt this will be enough so we'll need some way of periodically cleaning out that directory I suspect --->
- <cffile action="delete" file="#dir##file#">
+ <cffile action="delete" file="#dir##file#">
<cfreturn ObjectUnderTest>
</cffunction>

@@ -104,29 +104,26 @@

</cffunction>

- <cffunction name="constructArgumentsTags" returntype="struct" access="private" hint="creates the cfargument tags, the method call to the private method, and the return statement for the component">
+ <cffunction name="constructArgumentsTags" returntype="string" access="private" hint="creates the cfargument tags, the method call to the private method, and the return statement for the component">
<cfargument name="privateMethodStruct" type="struct" hint="the structure of metadata for the private method under consideration">
- <cfset var strArgs = "">
<cfset var strArgTags = "">
<cfset var thisParamString = "">
<cfset var thisTagString = "">
<cfset var a_params = privateMethodStruct.Parameters>
<cfset var p = 1>
<cfset var pCount = ArrayLen(a_params)>
- <cfset var s_return = StructNew()>
-
+
<cfloop from="1" to="#pCount#" index="p">
- <cfparam name="a_params[p].default" default="">
<cfparam name="a_params[p].required" default="false">
- <cfset thisTagString = "<cfargument name='#a_params[p].name#' required='#a_params[p].required#' default='#a_params[p].default#'>">
+ <cfset thisTagString = "<cfargument name='#a_params[p].name#' required='#a_params[p].required#'">
+ <cfif structKeyExists(a_params[p], 'default')>
+ <cfset thisTagString = thisTagString & " default='#a_params[p].default#'">
+ </cfif>
+ <cfset thisTagString = thisTagString & ">">
<cfset thisParamString = a_params[p].name & " = arguments.#a_params[p].name#">
<cfset strArgTags = ListAppend(strArgTags, thisTagString, lineSep)>
- <cfset strArgs = ListAppend(strArgs, thisParamString)>
</cfloop>
- <cfset s_return.tags = strArgTags>
- <cfset s_return.args = strArgs>
- <cfreturn s_return>
- <!--- <cfreturn strArgTags & lineSep & "<cfreturn #privateMethodStruct.name#(#strArgs#)>"> --->
+ <cfreturn strArgTags>
</cffunction>

</cfcomponent>
\ No newline at end of file
Index: tests/framework/fixture/ComponentWithPrivateMethods.cfc
===================================================================
--- tests/framework/fixture/ComponentWithPrivateMethods.cfc (revision 955)
+++ tests/framework/fixture/ComponentWithPrivateMethods.cfc (working copy)
@@ -24,6 +24,23 @@
<cffunction name="aPrivateMethodReturnArray2" returntype="array" access="private">
<cfreturn ArrayNew(1)>
</cffunction>
+
+ <cffunction name="aPrivateMethodVariedArguments" returntype="struct" access="private" output="false" hint="I return a struct matching arguments passed and/or defined by default attribute.">
+ <cfargument name="arg1" type="string" required="true">
+ <cfargument name="arg2" type="string" required="false" default="arg2_val">
+ <cfargument name="arg3" type="string" required="false">
+
+ <cfset var args = structNew()>
+ <cfset var key = "">
+
+ <cfloop collection="#arguments#" item="key">
+ <cfif structKeyExists(arguments, key)><!--- all cfargument tags have a struct key in arguments, even when not passed and no default --->
+ <cfset args[key] = arguments[key]>
+ </cfif>
+ </cfloop>
+
+ <cfreturn args>
+ </cffunction>

<!--- this will run as constructor code --->
<cfset this.x = 1>
Index: tests/framework/PublicProxyMakerTest.cfc
===================================================================
--- tests/framework/PublicProxyMakerTest.cfc (revision 955)
+++ tests/framework/PublicProxyMakerTest.cfc (working copy)
@@ -161,4 +161,57 @@
<cfset result = obj.aPrivateMethod()>
<cfset assertTrue(result)>
</cffunction>
+
+
+ <!--- Test combinations of arguments passed, to ensure proxy method preserves arguments and properties of proxied method... --->
+
+ <cffunction name="testMakePublicAllArgsPassed">
+ <cfset var actual = "">
+ <cfset var expected = structNew()>
+
+ <cfset this.maker.makePublic(this.objectWithPrivateMethod,"aPrivateMethodVariedArguments")>
+
+ <cfset expected.arg1 = "arg1_val">
+ <cfset expected.arg2 = "arg2_val">
+ <cfset expected.arg3 = "arg3_val">
+
+ <cfset actual = this.objectWithPrivateMethod.aPrivateMethodVariedArguments("arg1_val", "arg2_val", "arg3_val")>
+
+ <cfset assertEquals(expected,actual)>
+ </cffunction>
+
+ <cffunction name="testMakePublicArgDefault" hint="Test not passing arg2 argument, which has a default attribute.">
+ <cfset var actual = "">
+ <cfset var expected = structNew()>
+
+ <cfset this.maker.makePublic(this.objectWithPrivateMethod,"aPrivateMethodVariedArguments")>
+
+ <cfset expected.arg1 = "arg1_val">
+ <cfset expected.arg2 = "arg2_val">
+ <cfset expected.arg3 = "arg3_val">
+
+ <cfset actual = this.objectWithPrivateMethod.aPrivateMethodVariedArguments(arg1="arg1_val", arg3="arg3_val")>
+
+ <cfset assertEquals(expected,actual)>
+ </cffunction>
+
+ <cffunction name="testMakePublicMissingRequiredArg" mxunit:expectedException="Application">
+ <cfset this.maker.makePublic(this.objectWithPrivateMethod,"aPrivateMethodVariedArguments")>
+ <cfset this.objectWithPrivateMethod.aPrivateMethodVariedArguments()>
+ </cffunction>
+
+ <cffunction name="testMakePublicRequiredArgOnly">
+ <cfset var actual = "">
+ <cfset var expected = structNew()>
+
+ <cfset this.maker.makePublic(this.objectWithPrivateMethod,"aPrivateMethodVariedArguments")>
+
+ <cfset expected.arg1 = "arg1_val">
+ <cfset expected.arg2 = "arg2_val">
+
+ <cfset actual = this.objectWithPrivateMethod.aPrivateMethodVariedArguments("arg1_val")>
+
+ <cfset assertEquals(expected,actual)>
+ </cffunction>
+
</cfcomponent>
\ No newline at end of file
Powered by Google Project Hosting