It is possible to use Dependency Injection to mock the Feature Parameters for development org or for beta packages.
Let's create Feature
class and include this in the basic package
@namespaceAccessible
public with sharing class Feature {
@namespaceAccessible public enum Display {Label, ApiName}
@namespaceAccessible public interface DisplayProvider{
Display getDisplay();
}
@testVisible static DisplayProvider provider = new FeatureManagementProvider();
public static DisplayProvider getProvider() {
return Type.forName('MockFeatureProvider') != null ? (DisplayProvider) Type.forName('MockFeatureProvider').newInstance() : provider;
}
public class FeatureManagementProvider implements DisplayProvider{
public Display getDisplay() {
return Display.values()[System.FeatureManagement.checkPackageIntegerValue('Display')];
}
}
public static Display getDisplay() {
return getProvider().getDisplay();
}
}
Create custom settings FeatureParameterMock__c
with DateValue__c
, BoolValue__c
, IntegerValue__c
.
Create custom setting record with Name
having Display
value and IntegerValue__c
having desired value for Feature Parameter
.
Create a class MockFeatureProvider
and include this class and the custom settings into extension package with the same namespace and call this extension mock
@namespaceAccessible public with sharing class MockFeatureProvider implements Feature.DisplayProvider {
public Feature.Display getDisplay() {
return Feature.Display.values()[FeatureParameterMock__c.getAll()?.get('Display')?.IntegerValue__c];
}
}
Then install the Mock package extension and manipulate the data in custom setting record to change the value of Feature Parameter.
In the code where you need to check the value of the Feature Parameter
, call Feature.getDisplay()
, this method would return the mocked value from the custom settings for beta package or actual value on subscriber org where no mock is present.