Skip to content

Wildcard Pattern Matching

Randy Merrill edited this page Feb 9, 2012 · 1 revision

A lot of times, especially while creating stubs, you will just want to mimic some desired behavior and not be concerned about about what parameters are being passed to the mock. This is easily accomplished by using wildcard patterns. Example:

{*} is 0 or more parameters of any type and {+} is one or more parameters of any type.

<cfset myMock.doSomething (‘{*}’).returns(myQuery) />

This says that any call made to doSomething that has zero or more parameters will return myQuery. Likewise,

<cfset myMock.doSomething (‘{+}’).returns(myQuery) />

Says that any call made to doSomething with one or more parameters will return myQuery.

It’s important to note that the distinction of this call:

<cfset myMock.doSomething () />

This means that doSomthing() expects exactly 0 parameters.

Clone this wiki locally