[Phpmyadmin-devel] Local static variable and unit testing

Ayush Chaudhary ayushchd at gmail.com
Sat Mar 23 13:47:09 CET 2013


Hi,  

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. 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. 

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)?
-- 
Ayush Chaudhary

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.phpmyadmin.net/pipermail/developers/attachments/20130323/d59cab20/attachment.html>


More information about the Developers mailing list