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.

Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/
Google+: http://plus.google.com/113032480415921517411

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

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

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.

signature0.jpg

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 = ‘’);
model.establishCSRFStateToken();
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.

signature0.jpg

So no one knows why!!

signature0.jpg

Now I get it.

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

Luis Majano
CEO
Ortus Solutions, Corp
Toll Free/Fax: 1-888-557-8057
Direct: 909-248-3408
www.ortussolutions.com
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