Simple feature toggle library
composer require treehouselabs/feature-toggle
$features = new FeatureToggleCollection();
$features->registerToggle(
'feature-x',
new BooleanFeatureToggle(true)
);
if ($features->isEnabled('feature-x')) {
// perform stuff for feature-x
}
# behat.yml
default:
suites:
default:
contexts:
- TreeHouse\FeatureToggle\Bridge\Behat\FeatureToggleContext:
cacheItemPool: '@cache_item_pool' #PSR-6 cache item pool
<?php
class Feature
{
private $features;
public function __construct(FeatureToggleCollectionInterface $features) {
$this->features = $features;
}
public function indexAction()
{
if ($this->features->isEnabled('feature-y')) {
return 'Enabled!';
}
return 'Disabled!';
}
}
$toggleCollection = new CacheFeatureToggleCollection();
$toggleCollection->setCacheItemPool($psr6CacheItemPool);
// Overwrite the FeatureToggleCollection with the CacheFeatureToggleCollection in test env
new Feature($toggleCollection);
# feature-y.feature
Feature: Feature-Y
Scenario: Feature-Y is enabled
Given the feature toggle "feature-y" is enabled
And I am on the homepage
Then I should see "Enabled!"
Scenario: Feature-Y is disabled
# Given the feature toggle "feature-y" is disabled (default)
Given I am on the homepage
Then I should see "Disabled!"
composer test
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.