travaux-com / variantretriever
Installs: 10 200
Dependents: 0
Suggesters: 0
Security: 0
Stars: 22
Watchers: 4
Forks: 4
Open Issues: 0
Requires
- php: >=7.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- pestphp/pest: ^0.2.4
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-12-27 15:15:51 UTC
README
VariantRetriever
VariantRetriever is a minimalist package for feature flagging. It's fast, database free and idempotent library to choose over a set of variants.
Getting Started
First of all, you need to define an Experiment with a name and it variants. Variant requires 2 arguments, a name and a rollout percentage (50% by default). Then create a variant retriever with this experiment and variants, and ask it to retrieve a variant for a resource (in the following code, it's for a user uuid).
$variantRetriever = new VariantRetriever(); $experiment = new Experiment('my-ab-test', ...[new Variant('control1'), new Variant('variant2')]); $variantRetriever->addExperiment($experiment); $affectedVariant = $variantRetriever->getVariantForExperiment(new Experiment('my-ab-test'), '77d8a1d5-97ba-42db-a4a7-3b9562f0ff22'); var_dump((string) $affectedVariant); // string(7) "variant2"
Running the Test Suite
VariantRetriever uses Pest PHP as testing framework. Once you have all dependencies installed via composer install
, you can run the test suite with:
./vendor/bin/pest
To obtain the code coverage report, you'll need to have xdebug
installed. Then, you can run:
./vendor/bin/pest --coverage
And this will give you detailed information about code coverage.
What about speed
VariantRetriever is fast. In our test, we ensure that the retriever is able to get 50 000 variants to randomly generate different identifiables in less than 1 second. Local dev machine can run 500 000 runs in less than a second.