custom-d/unleash-helpers

helpers for Unleash

v2.3.2 2023-07-25 03:27 UTC

README

Installation

You can install the package via composer:

composer require custom-d/unleash-helpers

Usage

Unit Tests

to make your unit test where feature flags are within the testing object add the UsesFeatureFlag trait

example


use CustomD\UnleashHelpers\Traits\Testing\UsesFeatureFlags;

class MyFeatureTest extends TestCase
{
    use UsesFeatureFlags;

    public function testFlagsEnabled()
    {
        $this->setFeatureEnabled('test');
        $this->setFeatureDisabled('test2');

        $this->assertTrue(Unleash::isFeatureEnabled('test'));
        $this->assertTrue(Unleash::isFeatureDisabled('test2'));
    }

    public function testHasFeatureFlags()
    {
        //optional array of features
        $this->setUpFeatures([
            'flag' => true,
            'off' => false
        ]);
    }
    ...

Scheduler

you can tell the scheduler to trigger events based on the feature flag status: this will perform a check and only allow the scheduled event / job etc to run if the feature flag test passes. examples:

$schedule->job('xxx')->ifFeatureEnabled('feature');
$schedule->job('xxx')->ifFeatureDisabled('feature');

Validation

We have a validation rule set that can be called as follows

function rules() {
    'field' => 'requiredWithFeatureEnabled:my-feature', // field should be required if the feature flag is set on
    'field' => 'requiredWithFeatureDisabled:my-feature', // field should be required if the feature flag is set off or not set.
}

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email craig.smith@customd.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.