New method to retrieve private variables: getProperty()

Description

Calling makePublic on a private array variable does not make the variable public - it creates a methodProxy function.

If the method is only for functions it should verify that the target is a function and throw an error when used for something else.

Alternatively, it would be handy if it could be made to work for non-function variables (or as a separate function), but it would of course need to create a reference to the variable and not simply copy it, which might present issues.

Gliffy Diagrams

Activity

Show:

Peter BoughtonMarch 6, 2014 at 4:16 PM
Edited

I'm not saying every method should be added - though it's not thousands(!), there's 11, of which 6 are already available... but actually why not have those remaining five available? Not all the verification stuff, just the stuff under mocking methods.

I don't really see the distinction between what is available and what requires going into MockBox for, and if it makes it more convenient for quick single-access situations, why not make it more convenient?

In any case, the TestBox side of the docs definitely need updating - even if it's just a line saying "To access the variables scope use MockBox $getProperty docs"

Making the order of the methods alphabetical would probably also help. (I didn't see prepareMock in there originally, and the MockBox docs have it with the getMockBox() part, hence why I assumed it was needed.)

Luis MajanoMarch 6, 2014 at 3:54 PM

I see value in throwing an exception if the target is not a UDF

Luis MajanoMarch 6, 2014 at 3:51 PM
Edited

You can actually just say:

Which does not seem long winded. I cannot add all methods to base spec just for adding them. I added makePublic as a compat issue. In reality I wanted to separate mocking like methdos completely into their object counterparts. If not, I would end up with a CFC with 1000 methods.

Peter BoughtonMarch 6, 2014 at 3:44 PM

The bug is because makePublic accepts non-method inputs instead of throwing an error.

The making it work with variables (or having a makePublicVariable) part was a feature request, but I didn't see the benefit in splitting it out into a separate issue.

I don't see anything in the Testbox docs about Mockbox being able to do this - it would be useful to provide a reference (at the very least it should be mentioned in the list of available methods).

Looking at the Mockbox docs, it seems $getProperty is the way to do this, but it seems long-winded to do:

getMockBox().prepareMock( Obj ).$getProperty('VarName')

A useful shortcut would be:

getPrivateVariable( Obj , 'VarName' )

I've raised that as

Luis MajanoMarch 6, 2014 at 3:11 PM

I see more as a feature request than a bug Peter. Make public was meant for
methods only.

Mockbox comes with the ability to expose and retrieve properties ready

On Thursday, March 6, 2014, Peter Boughton (JIRA) <


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

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

Sentry

Created March 6, 2014 at 10:58 AM
Updated May 8, 2014 at 11:19 PM
Resolved April 21, 2014 at 8:10 PM