ColdBox Platform Version 2.6.4

coldbox.system.testing
Class MockBox

WEB-INF.cftags.component
        extended by coldbox.system.testing.MockBox

public class MockBox
extends WEB-INF.cftags.component

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 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'])
          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()
private Util getUtil()
          Create and return a util object
 string getVersion()
          Get the current mock factory version
 any mockArgs()
          Use this method to mock specific arguments when calling a mocked method
 struct mockCallLog()
          Retrieve the method call logger structure
private struct mockDebug()
          Debugging method for MockBox
 any mockMethod(string method, [any returns], boolean preserveReturnType='true', [boolean throwException='false'], [string throwType=''], [string throwDetail=''], [string throwMessage=''], [boolean callLogging='false'])
          Mock a Method, very simply, no fancy stuff
 numeric mockMethodCallCount([string methodName=''])
          I return the number of times the specified mock method has been called or ALL mock methods have been called
 any mockProperty(string propertyName, [string propertyScope='variables'], any mock)
          Mock a property inside of an object in any scope
 any mockResults()
          Use this method to mock more than 1 result as passed in arguments
 boolean mockVerifyCallCount(numeric count, [string methodName=''])
          Assert how many calls have been made to the mock or a specific mock method
 any prepareMock([any object], [boolean callLogging='true'])
          Prepares an object to act as a mock for spying
 query querySim(string queryData)
          First line are the query columns separated by commas
 void setGenerationPath(string generationPath)
          Override the generation path
 
Methods inherited from class WEB-INF.cftags.component
 

Constructor Detail

init

public init([string generationPath=''])
Create an instance of MockBox

Parameters:
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

createEmptyMock

public any createEmptyMock([string className], [any object], [boolean callLogging='true'])
Creates an empty mock object. By empty we mean we remove all methods so you can mock them.

Parameters:
className - The class name of the object to mock. The mock factory will instantiate it for you
object - The object to mock, already instantiated
callLogging - Add method call logging for all mocked methods. Defaults to true

createMock

public 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.

Parameters:
className - The class name of the object to mock. The mock factory will instantiate it for you
object - The object to mock, already instantiated
clearMethods - 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 false
callLogging - Add method call logging for all mocked methods. Defaults to true

createStub

public any createStub([boolean callLogging='true'])
Create an empty stub object that you can use for mocking.

Parameters:
callLogging - Add method call logging for all mocked methods

decorateMock

private void decorateMock(any target)
Decorate a mock object

Parameters:
target - The target object

getGenerationPath

public string getGenerationPath()
Get the current generation path


getMockGenerator

public MockGenerator getMockGenerator()


getUtil

private Util getUtil()
Create and return a util object


getVersion

public string getVersion()
Get the current mock factory version


mockArgs

public any mockArgs()
Use this method to mock specific arguments when calling a mocked method. Can only be called when chained to a mockMethod() call. If a method is called with arguments and no match, it defaults to the base results defined. Method Alias: $args()


mockCallLog

public struct mockCallLog()
Retrieve the method call logger structure. Method Alias: $callLog()


mockDebug

private struct mockDebug()
Debugging method for MockBox


mockMethod

public any mockMethod(string method, [any returns], boolean preserveReturnType='true', [boolean throwException='false'], [string throwType=''], [string throwDetail=''], [string throwMessage=''], [boolean callLogging='false'])
Mock a Method, very simply, no fancy stuff. Method Alias: $()

Parameters:
method - The method you want to mock or spy on
returns - The results it must return, if not passed it returns void or you will have to do the mockResults() chain
preserveReturnType - If false, the mock will make the returntype of the method equal to ANY
throwException - If you want the method call to throw an exception
throwType - The type of the exception to throw
throwDetail - The detail of the exception to throw
throwMessage - The message of the exception to throw
callLogging - Will add the machinery to also log the incoming arguments to each subsequent calls to this method

mockMethodCallCount

public numeric mockMethodCallCount([string methodName=''])
I return the number of times the specified mock method has been called or ALL mock methods have been called. If the mock method has not been defined the results is a -1. Method Alias = $count()

Parameters:
methodName - Name of the method to get calls from

mockProperty

public any mockProperty(string propertyName, [string propertyScope='variables'], any mock)
Mock a property inside of an object in any scope. Methods Alias = $property()

Parameters:
propertyName - The name of the property to mock
propertyScope - The scope where the property lives in. By default we will use the variables scope.
mock - The object or data to inject

mockResults

public any mockResults()
Use this method to mock more than 1 result as passed in arguments. Can only be called when chained to a mockMethod(),$() or $().mockArgs() call. Results will be recycled on a multiple of their lengths according to how many times they are called, simulating a state-machine algorithm. Method Alias: $results()


mockVerifyCallCount

public boolean mockVerifyCallCount(numeric count, [string methodName=''])
Assert how many calls have been made to the mock or a specific mock method

Parameters:
count - The number of calls made
methodName - Name of the method to verify the calls from

prepareMock

public any prepareMock([any object], [boolean callLogging='true'])
Prepares an object to act as a mock for spying.

Parameters:
object - The already instantiated object to prepare for mocking
callLogging - Add method call logging for all mocked methods

querySim

public query querySim(string queryData)
First line are the query columns separated by commas. Then do a consecuent rows separated by line breaks separated by | to denote columns.

Parameters:
queryData - The data to create queries

setGenerationPath

public void setGenerationPath(string generationPath)
Override the generation path

Parameters:
generationPath

ColdBox Platform Version 2.6.4