WEB-INF.cftags.component testbox.system.MockBox
A unit testing mocking/stubing factory for ColdFusion 7 and above and any CFML Engine
Constructor Summary | |
---|---|
init([string generationPath=''])
Create an instance of MockBox. |
Method Summary | |
---|---|
any
|
$(string method, [any returns], boolean preserveReturnType='true', [boolean throwException='false'], [string throwType=''], [string throwDetail=''], [string throwMessage=''], [boolean callLogging='false'], [boolean preserveArguments='false'], [any callback])
Mock a Method, simple but magical Injected as: $(). |
any
|
$args()
Use this method to mock specific arguments when calling a mocked method. |
boolean
|
$atLeast(numeric minNumberOfInvocations, [string methodName=''])
Assert that at least a certain number of calls have been made on the mock or a specific mock method. |
boolean
|
$atMost(numeric maxNumberOfInvocations, [string methodName=''])
Assert that at most a certain number of calls have been made on the mock or a specific mock method. |
struct
|
$callLog()
Retrieve the method call logger structures. |
any
|
$callback(any target)
Use this method to mock more than 1 result as passed in arguments. |
numeric
|
$count([string methodName=''])
I return the number of times the specified mock object's methods have been called or a specific method has been called. |
struct
|
$debug()
Debugging method for MockBox enabled mocks/stubs, useful to find out things about your mocks. |
any
|
$getProperty(any name, [any scope='variables'], [any default])
Gets an internal mocked object property. |
boolean
|
$never([string methodName=''])
Assert that no interactions have been made to the mock or a specific mock method: Alias to $times(0). |
boolean
|
$once([string methodName=''])
Assert that only 1 call has been made on the mock or a specific mock method. |
any
|
$property(string propertyName, [string propertyScope='variables'], any mock)
Mock a property inside of an object in any scope. |
any
|
$reset()
Reset all mock counters and logs on the targeted mock. |
any
|
$results()
Use this method to mock more than 1 result as passed in arguments. |
boolean
|
$times(numeric count, [string methodName=''])
Assert how many calls have been made to the mock or a specific mock method: Injected as $verifyCallCount() and $times(). |
any
|
createEmptyMock([string className], [any object], [boolean callLogging='true'])
Creates an empty mock object. |
any
|
createMock([string className], [any object], [boolean clearMethods='false'], [boolean callLogging='true'])
Create a mock object or prepares an object to act as a mock for spying. |
any
|
createStub([boolean callLogging='true'], [string extends=''], [string implements=''])
Create an empty stub object that you can use for mocking. |
private void
|
decorateMock(any target)
Decorate a mock object. |
string
|
getGenerationPath()
Get the current generation path. |
MockGenerator
|
getMockGenerator()
Get the Mock Generator Utility. |
private Util
|
getUtil()
Create and return a util object. |
string
|
getVersion()
Get the MockBox version. |
any
|
normalizeArguments(any args)
Normalize argument values on method calls. |
any
|
prepareMock([any object], [boolean callLogging='true'])
Prepares an already instantiated object to act as a mock for spying and much more. |
query
|
querySim(string queryData)
First line are the query columns separated by commas. |
void
|
setGenerationPath(string generationPath)
Override the mocks generation path. |
Methods inherited from class WEB-INF.cftags.component |
---|
None |
Constructor Detail |
---|
Create an instance of MockBox
generationPath
- The mocking generation relative path. If not defined, then the factory will use its internal tmp path. Just make sure that this folder is accessible from an include.Method Detail |
---|
Mock a Method, simple but magical Injected as: $()
method
- The method you want to mock or spy onreturns
- The results it must return, if not passed it returns void or you will have to do the mockResults() chainpreserveReturnType
- If false, the mock will make the returntype of the method equal to ANYthrowException
- If you want the method call to throw an exceptionthrowType
- The type of the exception to throwthrowDetail
- The detail of the exception to throwthrowMessage
- The message of the exception to throwcallLogging
- Will add the machinery to also log the incoming arguments to each subsequent calls to this methodpreserveArguments
- If true, argument signatures are kept, else they are ignored. If true, BEWARE with $args() matching as default values and missing arguments need to be passed too.callback
- A callback to execute that should return the desired results, this can be a UDF or closure.Use this method to mock specific arguments when calling a mocked method. Can only be called when chained to a $() call. If a method is called with arguments and no match, it defaults to the base results defined. Injected as: $args()
Assert that at least a certain number of calls have been made on the mock or a specific mock method. Injected as $atLeast()
minNumberOfInvocations
- The min number of calls to assertmethodName
- Name of the method to verify the calls from, if blank, from the entire mockAssert that at most a certain number of calls have been made on the mock or a specific mock method. Injected as $atMost()
maxNumberOfInvocations
- The max number of calls to assertmethodName
- Name of the method to verify the calls from, if blank, from the entire mockRetrieve the method call logger structures. Injected as: $callLog()
Use this method to mock more than 1 result as passed in arguments. Can only be called when chained to a $() or $().$args() call. Results will be determined by the callback sent in. Basically the method will call this callback and return its results)
target
- The UDF or closure to execute as a callbackI return the number of times the specified mock object's methods have been called or a specific method has been called. If the mock method has not been defined the results is a -1
methodName
- Name of the method to get the total made calls from. If not passed, then we count all methods in this mock objectDebugging method for MockBox enabled mocks/stubs, useful to find out things about your mocks. Injected as $debug()
Gets an internal mocked object property
name
- The name of the property to retrieve.scope
- The scope to which to retrieve the property from. Defaults to 'variables' scope.default
- Default value to return if property does not existAssert that no interactions have been made to the mock or a specific mock method: Alias to $times(0). Injected as $never()
methodName
- Name of the method to verify the calls fromAssert that only 1 call has been made on the mock or a specific mock method. Injected as $once()
methodName
- Name of the method to verify the calls from, if blank, from the entire mockMock a property inside of an object in any scope. Injected as = $property()
propertyName
- The name of the property to mockpropertyScope
- The scope where the property lives in. By default we will use the variables scope.mock
- The object or data to injectReset all mock counters and logs on the targeted mock. Injected as $reset
Use this method to mock more than 1 result as passed in arguments. Can only be called when chained to a $() or $().$args() call. Results will be recycled on a multiple of their lengths according to how many times they are called, simulating a state-machine algorithm. Injected as: $results()
Assert how many calls have been made to the mock or a specific mock method: Injected as $verifyCallCount() and $times()
count
- The number of calls to assertmethodName
- Name of the method to verify the calls from, if not passed it asserts all mocked method callsCreates an empty mock object. By empty we mean we remove all methods so you can mock them.
className
- The class name of the object to mock. The mock factory will instantiate it for youobject
- The object to mock, already instantiatedcallLogging
- Add method call logging for all mocked methods. Defaults to trueCreate a mock object or prepares an object to act as a mock for spying.
className
- The class name of the object to mock. The mock factory will instantiate it for youobject
- The object to mock, already instantiatedclearMethods
- If true, all methods in the target mock object will be removed. You can then mock only the methods that you want to mock. Defaults to falsecallLogging
- Add method call logging for all mocked methods. Defaults to trueCreate an empty stub object that you can use for mocking.
callLogging
- Add method call logging for all mocked methodsextends
- Make the stub extend from certain CFCimplements
- Make the stub adhere to an interfaceDecorate a mock object
target
- The target objectGet the current generation path
Get the Mock Generator Utility
Create and return a util object
Get the MockBox version
Normalize argument values on method calls
args
- The arguments structure to normalizePrepares an already instantiated object to act as a mock for spying and much more.
object
- The already instantiated object to prepare for mockingcallLogging
- Add method call logging for all mocked methodsFirst line are the query columns separated by commas. Then do a consecuent rows separated by line breaks separated by | to denote columns.
queryData
- The data to create queriesOverride the mocks generation path
generationPath