This repository was archived by the owner on Jun 23, 2025. It is now read-only.
Add variant and mocking support. Refactor to use value objects. #39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First, let me apologize for the size of this PR… it started as a need to remove the static methods in the
Feature
facade to enable mocking and then it yak shaved away from me. I was unable to untangle it into a sane commit history. I highly recommend reading the updated README, in particular the sections on Variants and Mocking. There is also copious amounts of new tests.I recognize that the refactor around value object is a fundamental change to the package, so If this is not desired I understand, but I consider it required for mocking, and it was helpful for implementing variant support too.
[NEW] Mocking can now be achieved easily using
Unleash::fake()
similar to Laravel'sEvent::fake()
orBus::fake()
. This is achieved usingUnleashFake
.[NEW] Variant support. Get the correct variant based on the flag configuration using
Unleash::variant('flag-name', 'default-value');
[CHANGE] To better support mocking and variants, the package has been updated to use value objects. This should be backwards compatible for the most part, with the implementation fo
ArrayAccess
, except for checks usingis_array()
.[CHANGE] The Laravel-like
enabled()
,disabled()
,get()
andall()
methods are now the primary, with the standard Unleash methods as aliases[CHANGE] Tests have been updated to better handle Config mocking, simplifying some of them dramatically.