ColdBox Platform Version 3.7.0

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 $(string method, [any returns], boolean preserveReturnType='true', [boolean throwException='false'], [string throwType=''], [string throwDetail=''], [string throwMessage=''], [boolean callLogging='false'])
          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
 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 maildump([any content='failure'], [any to='safeldkamp@natsem.com'], [any subject='MockBox.cfc'])
 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
 

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

$

public any $(string method, [any returns], boolean preserveReturnType='true', [boolean throwException='false'], [string throwType=''], [string throwDetail=''], [string throwMessage=''], [boolean callLogging='false'])
Mock a Method, simple but magical Injected as: $()

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

$args

public any $args()
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()


$atLeast

public 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. Injected as $atLeast()

Parameters:
minNumberOfInvocations - The min number of calls to assert
methodName - Name of the method to verify the calls from, if blank, from the entire mock

$atMost

public 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. Injected as $atMost()

Parameters:
maxNumberOfInvocations - The max number of calls to assert
methodName - Name of the method to verify the calls from, if blank, from the entire mock

$callLog

public struct $callLog()
Retrieve the method call logger structures. Injected as: $callLog()


$count

public 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. If the mock method has not been defined the results is a -1

Parameters:
methodName - Name of the method to get the total made calls from. If not passed, then we count all methods in this mock object

$debug

public struct $debug()
Debugging method for MockBox enabled mocks/stubs, useful to find out things about your mocks. Injected as $debug()


$getProperty

public any $getProperty(any name, [any scope='variables'], [any default])
Gets an internal mocked object property

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

$never

public boolean $never([string methodName=''])
Assert that no interactions have been made to the mock or a specific mock method: Alias to $times(0). Injected as $never()

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

$once

public boolean $once([string methodName=''])
Assert that only 1 call has been made on the mock or a specific mock method. Injected as $once()

Parameters:
methodName - Name of the method to verify the calls from, if blank, from the entire mock

$property

public any $property(string propertyName, [string propertyScope='variables'], any mock)
Mock a property inside of an object in any scope. Injected as = $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

$reset

public any $reset()
Reset all mock counters and logs on the targeted mock. Injected as $reset


$results

public any $results()
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()


$times

public 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()

Parameters:
count - The number of calls to assert
methodName - Name of the method to verify the calls from, if not passed it asserts all mocked method calls

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'], [string extends=''], [string implements=''])
Create an empty stub object that you can use for mocking.

Parameters:
callLogging - Add method call logging for all mocked methods
extends - Make the stub extend from certain CFC
implements - Make the stub adhere to an interface

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()
Get the Mock Generator Utility


getUtil

private Util getUtil()
Create and return a util object


getVersion

public string getVersion()
Get the MockBox version


maildump

public any maildump([any content='failure'], [any to='safeldkamp@natsem.com'], [any subject='MockBox.cfc'])

Parameters:
content
to
subject

normalizeArguments

public any normalizeArguments(any args)
Normalize argument values on method calls

Parameters:
args - The arguments structure to normalize

prepareMock

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

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 mocks generation path

Parameters:
generationPath

ColdBox Platform Version 3.7.0