Skip to content

Commit 2056d46

Browse files
committed
TDP-1887 Improve documentation.
1 parent e889959 commit 2056d46

File tree

6 files changed

+89
-2
lines changed

6 files changed

+89
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ Homestead.json
2323
.phpunit.result.cache
2424

2525
/.vscode/
26+
junit.xml

README.md

+44-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,44 @@
1-
# laravel-feature-toggle
1+
# Abstract Feature Flags from Providers
2+
This package allows you to implement feature flags in Laravel. Right now the only supported implementation is split.io.
3+
4+
## Basic Usage
5+
### Change Behavior Based on a Flag
6+
use PartechGSS\Laravel\FeatureToggle\Contracts\FeatureToggleClient;
7+
8+
$client = resolve(FeatureToggleClient::class);
9+
switch ($client->getTreatment('my_flag')) {
10+
case "on":
11+
do_a_thing();
12+
break;
13+
14+
default:
15+
do_another_thing();
16+
break;
17+
}
18+
19+
### Retrieve Configuration Attached to a Treatment
20+
$treatmentWithConfig = $client->getTreatmentWithConfig('my_flag');
21+
$treatment = $treatmentWithConfig['treatment'];
22+
$config = $treatmentWithConfig['config'];
23+
set_some_css_options($config);
24+
25+
### Retrieve Multiple Flags in a Batch
26+
$treatments = $client->getTreatments(['my_flag', 'another_flag']);
27+
switch($treatments['my_flag']) {
28+
...
29+
}
30+
31+
### Retrieve Configurations in a Batch
32+
$treatmentsWithConfig = $client->getTreatmentsWithConfig('my_flag');
33+
$treatment = $treatmentsWithConfig['my_flag']['treatment'];
34+
$config = $treatmentsWithConfig['my_flgag']['config'];
35+
set_some_css_options($config);
36+
37+
## Installation
38+
You can install the package via Composer:
39+
40+
composer require partechgss/laravel-feature-toggles
41+
42+
## Testing
43+
44+
composer test

composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
"orchestra/testbench": "^5.3",
1616
"phpunit/phpunit": "^9.2"
1717
},
18+
"scripts": {
19+
"test": "phpunit"
20+
},
1821
"extra": {
1922
"laravel": {
2023
"providers": [

config/feature-toggle.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
]
2323
],
2424

25-
'log' => ['adapter' => 'stdout', 'level' => 'error']
25+
'log' => ['adapter' => 'syslog', 'level' => 'error']
2626
]
2727
]
2828
];

phpunit.xml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false">
11+
<testsuites>
12+
<testsuite name="Unit">
13+
<directory suffix="Test.php">./tests</directory>
14+
</testsuite>
15+
</testsuites>
16+
<php>
17+
<server name="APP_ENV" value="testing"/>
18+
<server name="BCRYPT_ROUNDS" value="4"/>
19+
<server name="CACHE_DRIVER" value="array"/>
20+
<server name="MAIL_DRIVER" value="array"/>
21+
<server name="QUEUE_CONNECTION" value="sync"/>
22+
<server name="SESSION_DRIVER" value="array"/>
23+
</php>
24+
<logging>
25+
<log type="junit" target="./junit.xml"/>
26+
</logging>
27+
</phpunit>

tests/SplitIOTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,29 @@ protected function getPackageProviders($app)
2323
*/
2424
public function it_renders_the_control_treatment() {
2525
$toggleClient = app(FeatureToggleClient::class);
26+
$toggleClient->setKey("[email protected]");
2627
$this->assertEquals("control", $toggleClient->getTreatment("AintNoSuchFlag"));
2728
}
2829

30+
/**
31+
* Test that the control treatment is returned when the user has not been set.
32+
* @test
33+
* @return void
34+
*/
35+
public function it_renders_the_control_treatment_without_key() {
36+
config()->set('feature-toggle.splitio.factory.log.adapter', 'void');
37+
$toggleClient = app(FeatureToggleClient::class);
38+
$this->assertEquals("control", $toggleClient->getTreatment("FancyFeatureFlag"));
39+
}
40+
2941
/**
3042
* Test that an 'off' treatment can be returned.
3143
* @test
3244
* @return void
3345
*/
3446
public function it_renders_an_off_treatment() {
3547
$toggleClient = app(FeatureToggleClient::class);
48+
$toggleClient->setKey("[email protected]");
3649
$this->assertEquals("off", $toggleClient->getTreatment("FancyFeatureFlag"));
3750
}
3851

0 commit comments

Comments
 (0)