testbox.system.mockutils

Class MockGenerator

lucee.Component
        extended by testbox.system.mockutils.MockGenerator
Class Attributes:
  • output : false
  •  
  • synchronized : false
  •  
  • accessors : false
  •  
  • persistent : false
  •  

    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=''], [string throwErrorCode=''], any metadata='', any targetObject, [boolean callLogging='false'], [boolean preserveArguments='false'], [any callback])
         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.
    void writeStub(string genPath, string code)
         Write a method generator stub.
     
    Methods inherited from class lucee.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=''], [string throwErrorCode=''], any metadata='', any targetObject, [boolean callLogging='false'], [boolean preserveArguments='false'], [any callback])

    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
    throwErrorCode - The errorCode 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.
    callback - A callback to execute that should return the desired results, this can be a UDF or closure.

    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

    writeStub

    public void writeStub(string genPath, string code)

    Write a method generator stub

    Parameters:
    genPath
    code