mockbox and private methods

Haven’t done this for so long…

Anyway I am trying to test a private method, but while it is private I get an error thrown. If it is public the test passes.

I have searched the docs, and can’t see any place in mockbox wiki where I can test a private method.

Andrew Scott

There should not be any difference Andrew, you mock any scope,
are you calling it directly?


Luis F. Majano
Ortus Solutions, Corp

ColdBox Platform:
Linked In:
IECFUG Manager:


It is a private method, no scope no variable.

model.myFunction(); //fails in test

It turns out that I forgot you need to do this

makePubli(model, “myFunction”);

So all is good now anyway.


Nope, I thought that was what I needed to do but it isn’t

Here is the test case

makePublic(model, “establishCSRFStateToken”);
model.$property(propertyName = “state”, propertyScope = “this”, mock = ‘’);
asserttrue( model.$once(‘setPersistentData’) );

Here is the method

public void function establishCSRFStateToken() {
if (this.state == “”) {
this.state = hash(createUUID());
setPersistentData(“state”, this.state);

Now I know this is running, as the setPersistentData is basically just setting a session variable and if I debug the session I can see it sitting there. So if I go by the wiki docs, the test case should actually return true as it is only being run once.

Any one have an idea why the $once is saying it hasn’t been run at all? I thought it might be because the function is private, but making it public either in the test or the model makes no difference.


So no one knows why!!


Now I get it.

You have not mocked the method. Just the scope right?

Luis Majano
Ortus Solutions, Corp
Toll Free/Fax: 1-888-557-8057
Direct: 909-248-3408
Twitter: @lmajano, @ortussolutions

Luis, are you hinting that the method needs to be mocked?

If I remember correctly then yes. I think only mocked methods are tracked