getMockBuilder( ApiBase::class ) ->setConstructorArgs( [ $main, $name ] ) ->onlyMethods( [ 'execute' ] ) ->getMock(); $module->method( 'execute' ) ->willReturnCallback( function () use ( $module, $resultData, $throwException ) { if ( $throwException ) { throw $throwException; } $res = $module->getResult(); foreach ( $resultData as $key => $value ) { $res->addValue( null, $key, $value ); } } ); return $module; } }