The singleton class is singleton in PHPUNIT testing. classA has a staticpublic $ CI attribute and a staticpublicfunction & amp; get_ci () {if (! Self: $ CI) {self: $ CI & amp; get_instance ();} r PHPUNIT test involves singleton class issues
Class A is singleton, has A static public $ CI; attribute, and has
Static public function & get_ci ()
{
If (! Self: $ CI)
{
Self: $ CI = & get_instance ();
}
Return self: $ CI;
}
Method.
Class B calls class
Class A $ CI to class B
Then, because phpunit executes multiple test cases consecutively.
Therefore, $ CI of classA remains unchanged.
Class C calls class
The returned $ CI is also an instance of class B.
Because class B has a $ abc attribute, it is 123 when class B is called.
Class C also has A $ abc attribute, which is already 456, but when class C calls class A, $ CI-> abc or 123 in class
But I expect him to be 456.
This problem occurs only when phpunit is used, because all variable objects are not cleared after a test case is completed. this problem will not occur if the test process is normal, because class C won't call class B before.
------ Solution --------------------
Discussion
In fact, there are several class D, E, F are all singleton and $ CI in it is protected or private, so it cannot be manually cleared.