Mocking Methods

Normal Test.getData() = 5
NOT MOCKED: Method called -1 times
Mock Method called 0 times
Mocked Test.getData() = 1000
Mocked Test.getData() = 1000
Mock Method called 2 times Mock Call Logger Dump:
Struct
getData
Array
1
Scope Arguments
2
Scope Arguments
Mock Method called 0 times
Mocked Test.getData() = 1000
Mocked Test.getData() = 1000
Mock Method called 2 times Mock Call Logger Dump:
Struct
getData
Array
1
Scope Arguments
2
Scope Arguments

Mocking Virtual Methods

We will add a virtual method called virtualReturn Virtual Method called 0 times
Virtual Test.virtualReturn() = Virtual Called Baby!!
Virtual Method called 1 times Mock Call Logger Dump:
Struct
getData
Array
1
Scope Arguments
2
Scope Arguments
virtualReturn
Array
1
Scope Arguments

Mocking Properties

Original Reload property value: false
Mocked Reload Property value: true

Mocking Private Methods

Normal Test.getFullName() = Luis
Mocked Test.getFullName() = My Mock Name

Mocking State Machine of Results

Three results will be mocked, and they will be called 11 times. The results should recycle every 3 calls

Call #1 -> S1
Call #2 -> S2
Call #3 -> S3
Call #4 -> S1
Call #5 -> S2
Call #6 -> S3
Call #7 -> S1
Call #8 -> S2
Call #9 -> S3
Call #10 -> S1
Call #11 -> S2

Mocking Stubs

Create a stub object and add behavior:

Stub Fake Get Name: Luis Majano

Mocking Spy Methods

UnMocked Spy -> Test.getData() = 5
UnMocked Spy Call -> Test.spyTest() = 5
Mocked Spy Test.getData() = 1000
Mocked Spy Call -> Test.spyTest() = 0

Mocking With Specific ARguments

Unmocked getSetting() method:
AppMapping = /mockFactory
DebugMode = NOT FOUND

Mocking the getSetting() method:
AppMapping = mockbox.testing = mockbox.testing
DebugMode = true = true
Call Counts = 2 Mock Call Logger Dump:

Struct
getSetting
Array
1
Scope Arguments
11
stringAppMapping
2
Scope Arguments
11
stringDebugMode

Mock Call Logger Dump on Collaborator:
Struct
getDataFromDB
Array
Data Dump:
Query
Execution Time: 0 ms
Record Count: 0
Cached: No
Lazy: No
Query
Execution Time: 0 ms
Record Count: 0
Cached: No
Lazy: No
Struct
MOCKARGRESULTS
Struct
MOCKCALLBACKS
Struct
MOCKCALLLOGGERS
Struct
MOCKCALLLOGGINGACTIVE
booleantrue
MOCKGENERATIONPATH
string/testbox/system/stubs/
MOCKMETHODCALLCOUNTERS
Struct
MOCKORIGINALMD
Struct
Entries: 13
accessors
booleanfalse
extends
Struct
Entries: 13
accessors
booleanfalse
displayname
stringComponent
fullname
stringlucee.Component
functions
Array
hashCode
number1889111585
hint
stringThis is the Base Component
name
stringlucee.Component
path
stringC:\inetpub\wwwroot\WEB-INF\lucee\context\Component.cfc
persistent
booleanfalse
properties
Array
remoteAddress
stringhttp://18.232.214.160:80/lucee/Component.cfc?wsdl
synchronized
booleanfalse
type
stringcomponent
fullname
stringtestbox.tests.resources.Test
functions
Array
1
Struct
Entries: 12
access
stringpublic
closure
booleanfalse
description
string
modifier
string
name
stringcontainsTest
output
booleantrue
owner
stringC:\inetpub\wwwroot\testbox\tests\resources\Test.cfc
parameters
Array
1
Struct
name
stringmock
required
booleanfalse
type
stringany
position
Struct
end
number16
start
number13
returnFormat
stringwddx
returntype
stringany
static
booleanfalse
2
Struct
Entries: 13
access
stringpublic
closure
booleanfalse
description
string
hint
stringget data and send it back
modifier
string
name
stringdisplayData
output
booleanfalse
owner
stringC:\inetpub\wwwroot\testbox\tests\resources\Test.cfc
parameters
Array
position
Struct
end
number20
start
number18
returnFormat
stringwddx
returntype
stringquery
static
booleanfalse
3
Struct
Entries: 12
access
stringpublic
closure
booleanfalse
description
string
modifier
string
name
stringgetData
output
booleanfalse
owner
stringC:\inetpub\wwwroot\testbox\tests\resources\Test.cfc
parameters
Array
position
Struct
end
number34
start
number32
returnFormat
stringwddx
returntype
stringany
static
booleanfalse
4
Struct
Entries: 13
access
stringpublic
closure
booleanfalse
description
string
hint
stringGet Full Name
modifier
string
name
stringgetFullName
output
booleanfalse
owner
stringC:\inetpub\wwwroot\testbox\tests\resources\Test.cfc
parameters
Array
position
Struct
end
number43
start
number41
returnFormat
stringwddx
returntype
stringstring
static
booleanfalse
5
Struct
Entries: 13
access
stringprivate
closure
booleanfalse
description
string
hint
stringGet Name
modifier
string
name
stringgetName
output
booleanfalse
owner
stringC:\inetpub\wwwroot\testbox\tests\resources\Test.cfc
parameters
Array
position
Struct
end
number46
start
number44
returnFormat
stringwddx
returntype
stringstring
static
booleanfalse
6
Struct
Entries: 13
access
stringpublic
closure
booleanfalse
description
string
hint
stringGet a setting
modifier
string
name
stringgetSetting
output
booleantrue
owner
stringC:\inetpub\wwwroot\testbox\tests\resources\Test.cfc
parameters
Array
1
Struct
default
string
hint
stringName of setting
name
stringname
required
booleantrue
type
stringstring
2
Struct
name
stringtestArg
required
booleanfalse
type
stringstring
position
Struct
end
number72
start
number63
returnFormat
stringwddx
returntype
stringstring
static
booleanfalse
7
Struct
Entries: 13
access
stringpublic
closure
booleanfalse
description
string
hint
stringGet collaborator
modifier
string
name
stringgetcollaborator
output
booleanfalse
owner
stringC:\inetpub\wwwroot\testbox\tests\resources\Test.cfc
parameters
Array
position
Struct
end
number25
start
number23
returnFormat
stringwddx
returntype
stringany
static
booleanfalse
8
Struct
Entries: 12
access
stringpublic
closure
booleanfalse
description
string
modifier
string
name
stringgetreload
output
booleanfalse
owner
stringC:\inetpub\wwwroot\testbox\tests\resources\Test.cfc
parameters
Array
position
Struct
end
number38
start
number36
returnFormat
stringwddx
returntype
stringboolean
static
booleanfalse
9
Struct
Entries: 13
access
stringpublic
closure
booleanfalse
description
string
hint
stringSet collaborator
modifier
string
name
stringsetcollaborator
output
booleanfalse
owner
stringC:\inetpub\wwwroot\testbox\tests\resources\Test.cfc
parameters
Array
1
Struct
name
stringcollaborator
required
booleantrue
type
stringany
position
Struct
end
number29
start
number26
returnFormat
stringwddx
returntype
stringvoid
static
booleanfalse
10
Struct
Entries: 13
access
stringpublic
closure
booleanfalse
description
string
hint
stringSpy test
modifier
string
name
stringspyTest
output
booleanfalse
owner
stringC:\inetpub\wwwroot\testbox\tests\resources\Test.cfc
parameters
Array
position
Struct
end
number60
start
number50
returnFormat
stringwddx
returntype
stringany
static
booleanfalse
hashCode
number80044289
name
stringtestbox.tests.resources.Test
output
booleanfalse
path
stringC:\inetpub\wwwroot\testbox\tests\resources\Test.cfc
persistent
booleanfalse
properties
Array
remoteAddress
stringhttp://mrg.mind-over-data.com:80/testbox/tests/resources/Test.cfc?wsdl
synchronized
booleanfalse
type
stringcomponent
MOCKRESULTS
Struct