From: Timo Tijhof Date: Wed, 2 Mar 2016 00:47:05 +0000 (+0000) Subject: MemoizedCallable: Add test for memoized closure X-Git-Tag: 1.31.0-rc.0~7706^2 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=221829c4c18835502d58bce918ef099c34143592;p=lhc%2Fweb%2Fwiklou.git MemoizedCallable: Add test for memoized closure Follows-up da3443bfa2a. It won't work across different requests due to use of uniqid() internally (so we may want to use a HashBagOStuff for closure instead to save memory in APC). But at least assert that it does and is intended to work. Change-Id: Id4b42e8717f62f733eee8fcc9a4ab6c0f5c1f2fe --- diff --git a/tests/phpunit/includes/libs/MemoizedCallableTest.php b/tests/phpunit/includes/libs/MemoizedCallableTest.php index 519c8c38de..6eb96b157e 100644 --- a/tests/phpunit/includes/libs/MemoizedCallableTest.php +++ b/tests/phpunit/includes/libs/MemoizedCallableTest.php @@ -4,7 +4,7 @@ * in an instance property rather than APC. */ class ArrayBackedMemoizedCallable extends MemoizedCallable { - public $cache = []; + private $cache = []; protected function fetchResult( $key, &$success ) { if ( array_key_exists( $key, $this->cache ) ) { @@ -112,6 +112,11 @@ class MemoizedCallableTest extends PHPUnit_Framework_TestCase { $this->readAttribute( $a, 'callableName' ), $this->readAttribute( $b, 'callableName' ) ); + + $c = new ArrayBackedMemoizedCallable( function () { + return rand(); + } ); + $this->assertEquals( $c->invokeArgs(), $c->invokeArgs(), 'memoized random' ); } /**