[Owncloud] Making internal methods public for unit testing

Beni Buess beni at benel.net
Tue Jun 12 18:42:24 UTC 2012


On Fri, 01 Jun 2012 18:38:12 +0100
Sam Tuke <samtuke at fsfe.org> wrote:

> OCP\User currently provides access to user-related methods commonly
> used by apps. For unit testing however, access to more methods are
> required, such as useBackend(), in order to make use of the dummy
> OC_User_Dummy user management backend.
> 
> I imagine that other methods will also require access via a public
> interface for unit testing other functionality (not just relating to
> user.php).
> 
> Therefore, although I can provide access to unit tests by simply
> adding wrappers for methods like useBackend() to OCP\User, I wonder
> whether there is a better option which doesn't result in a slew of
> new wrappers duplicating input and output?

You can use PHP's Reflection API. Using ReflectionMethod::setAccessible
you can make a private Method callable from outside [1]

[1] http://ch2.php.net/manual/en/reflectionmethod.setaccessible.php

Beni




More information about the Owncloud mailing list