[Wp-unit-tests] [576] wp-testlib/base.php: Use static variable for isTracTicketClosed cached.

Kurt Payne kpayne+wordpress+tests at gmail.com
Wed Mar 14 15:12:09 UTC 2012


Nacin,

This doesn't work for me.  I started by using a static var.  I added
some debug output at the top of the function and the cache was not
behaving as desired.

If I had to conjecture about what was going on .... the
"isTracTicketClosed" function is part of a class which gets extended.
Any static scope is associated with the instantiated class name as
well as the method name.

For example, TestSanitizeUser::isTracTicketClosed vs.
TestSanitizeTitleWithDashes::isTracTicketClosed

Can you reproduce?

--Kurt


On Wed, Mar 14, 2012 at 6:27 AM,  <noreply at wordpress.org> wrote:
> Revision 576 Author nacin Date 2012-03-14 13:27:19 +0000 (Wed, 14 Mar 2012)
>
> Log Message
>
> Use static variable for isTracTicketClosed cached. see [572].
>
> Modified Paths
>
> wp-testlib/base.php
>
> Diff
>
> Modified: wp-testlib/base.php (575 => 576)
>
> --- wp-testlib/base.php	2012-03-14 00:24:07 UTC (rev 575)
> +++ wp-testlib/base.php	2012-03-14 13:27:19 UTC (rev 576)
> @@ -395,9 +395,8 @@
>  	 * @return bool|null true if the ticket is resolved, false if not
> resolved, null on error
>  	 */
>  	function isTracTicketClosed($trac_url, $ticket_id) {
> -		global $trac_ticket_cache;
> -		if ( !isset( $trac_ticket_cache ) || !is_array( $trac_ticket_cache ))
> -			$trac_ticket_cache = array();
> +		static $trac_ticket_cache = array();
> +
>  		$trac_url = rtrim($trac_url, '/');
>  		$url = "$trac_url/ticket/$ticket_id?format=tab";		
>  		if ( array_key_exists( $url, $trac_ticket_cache ) ) {
>
>
> _______________________________________________
> wp-unit-tests mailing list
> wp-unit-tests at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/wp-unit-tests
>


More information about the wp-unit-tests mailing list