[Phpmyadmin-devel] Local static variable and unit testing
Marc Delisle
marc at infomarc.info
Sat Mar 23 15:54:00 CET 2013
Le 2013-03-23 08:47, Ayush Chaudhary a écrit :
> Hi,
Hello,
>
> I was going through the existing tests. The test 'testIsHttps' under
> test/classes/PMA_Config_test.php looks wrong as isHttps() should be
> returning true for the second test case. However, the function
> isHttps() uses a local static variable, which is why the test is
> passing as in the construct, the PmaAbsoluteUri is initialised with
> null and isHttps() is hence returning false in all subsequent calls.
>
> I am not sure why a local static variable was used here.
To avoid retesting the condition for nothing?
> A better
> test for this method would be if we could reset the static variable
> before each assertion. Since its a local static variable, I couldn't
> find a proper way to reset the static variable. Should we not move
> the static variable in the scope of the class? In fact, even if we
> don't use a static variable, we could just make is_https a class
> member and initialise it to NULL in the constructor. This would
> eventually achieve the same result in a neater way.
Makes sense, but watch out: isHttps() and detectHttps() are both using
$is_https, for different goals.
>
> Also, what approach do we take for resetting static variables if
> needed for unit testing? One thing I came across was using
> Reflection_Helper::set_static_variable($class, $name, $new_value)?
Yes, this approach seems interesting :
http://tech.blog.box.com/2012/07/unit-testing-with-static-variables/
--
Marc Delisle
http://infomarc.info
More information about the Developers
mailing list