<?php
/**
* A MemoizedCallable subclass that stores function return values
- * in an instance property rather than APC.
+ * in an instance property rather than APC or APCu.
*/
class ArrayBackedMemoizedCallable extends MemoizedCallable {
- public $cache = [];
+ private $cache = [];
protected function fetchResult( $key, &$success ) {
if ( array_key_exists( $key, $this->cache ) ) {
* PHP Unit tests for MemoizedCallable class.
* @covers MemoizedCallable
*/
-class MemoizedCallableTest extends PHPUnit_Framework_TestCase {
+class MemoizedCallableTest extends PHPUnit\Framework\TestCase {
+
+ use MediaWikiCoversValidator;
/**
* The memoized callable should relate inputs to outputs in the same
* way as the original underlying callable.
*/
public function testReturnValuePassedThrough() {
- $mock = $this->getMock( 'stdClass', [ 'reverse' ] );
+ $mock = $this->getMockBuilder( stdClass::class )
+ ->setMethods( [ 'reverse' ] )->getMock();
$mock->expects( $this->any() )
->method( 'reverse' )
->will( $this->returnCallback( 'strrev' ) );
* Consecutive calls to the memoized callable with the same arguments
* should result in just one invocation of the underlying callable.
*
- * @requires function apc_store
+ * @requires function apc_store/apcu_store
*/
public function testCallableMemoized() {
- $observer = $this->getMock( 'stdClass', [ 'computeSomething' ] );
+ $observer = $this->getMockBuilder( stdClass::class )
+ ->setMethods( [ 'computeSomething' ] )->getMock();
$observer->expects( $this->once() )
->method( 'computeSomething' )
->will( $this->returnValue( 'ok' ) );
$this->readAttribute( $a, 'callableName' ),
$this->readAttribute( $b, 'callableName' )
);
+
+ $c = new ArrayBackedMemoizedCallable( function () {
+ return rand();
+ } );
+ $this->assertEquals( $c->invokeArgs(), $c->invokeArgs(), 'memoized random' );
}
/**