ColdBox Platform v3.8.0

coldbox.system.testing.mockutils
Class MockGenerator

WEB-INF.cftags.component
        extended by coldbox.system.testing.mockutils.MockGenerator

public class MockGenerator
extends WEB-INF.cftags.component

The guy in charge of creating mocks

Constructor Summary
init(any mockBox, [any removeStubs='true'])
          Constructor
 
Method Summary
private void $include(string templatePath)
          Mix in a template
 string generate(string method, [any returns], boolean preserveReturnType='true', [boolean throwException='false'], [string throwType=''], [string throwDetail=''], [string throwMessage=''], any metadata='', any targetObject, [boolean callLogging='false'], [boolean preserveArguments='false'])
          Generate a mock method and return the generated path
 any generateCFC([string extends=''], [string implements=''])
          Generate CFC's according to specs
private any generateMethodsFromMD(any buffer, any md)
          Generates methods from functions metadata
 boolean removeStub(string genPath)
          Remove a method generator stub
private void rethrowit(any throwObject)
          Rethrow an exception
 void writeStub(string genPath, string code)
          Write a method generator stub
 
Methods inherited from class WEB-INF.cftags.component
None
 

Constructor Detail

init

public init(any mockBox, [any removeStubs='true'])
Constructor

Parameters:
mockBox
removeStubs - Always remove stubs unless we are debugging
Method Detail

$include

private void $include(string templatePath)
Mix in a template

Parameters:
templatePath

generate

public string generate(string method, [any returns], boolean preserveReturnType='true', [boolean throwException='false'], [string throwType=''], [string throwDetail=''], [string throwMessage=''], any metadata='', any targetObject, [boolean callLogging='false'], [boolean preserveArguments='false'])
Generate a mock method and return the generated path

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
metadata - The function metadata
targetObject - The target object to mix in
callLogging - Will add the machinery to also log the incoming arguments to each subsequent calls to this method
preserveArguments - 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.

generateCFC

public any generateCFC([string extends=''], [string implements=''])
Generate CFC's according to specs

Parameters:
extends - The class the CFC should extend
implements - The class(es) the CFC should implement

generateMethodsFromMD

private any generateMethodsFromMD(any buffer, any md)
Generates methods from functions metadata

Parameters:
buffer - The string buffer to append stuff to
md - The metadata to generate

removeStub

public boolean removeStub(string genPath)
Remove a method generator stub

Parameters:
genPath

rethrowit

private void rethrowit(any throwObject)
Rethrow an exception

Parameters:
throwObject - The exception object

writeStub

public void writeStub(string genPath, string code)
Write a method generator stub

Parameters:
genPath
code

ColdBox Platform v3.8.0