File tree 6 files changed +89
-2
lines changed
6 files changed +89
-2
lines changed Original file line number Diff line number Diff line change @@ -23,3 +23,4 @@ Homestead.json
23
23
.phpunit.result.cache
24
24
25
25
/.vscode /
26
+ junit.xml
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 15
15
"orchestra/testbench" : " ^5.3" ,
16
16
"phpunit/phpunit" : " ^9.2"
17
17
},
18
+ "scripts" : {
19
+ "test" : " phpunit"
20
+ },
18
21
"extra" : {
19
22
"laravel" : {
20
23
"providers" : [
Original file line number Diff line number Diff line change 22
22
]
23
23
],
24
24
25
- 'log ' => ['adapter ' => 'stdout ' , 'level ' => 'error ' ]
25
+ 'log ' => ['adapter ' => 'syslog ' , 'level ' => 'error ' ]
26
26
]
27
27
]
28
28
];
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change @@ -23,16 +23,29 @@ protected function getPackageProviders($app)
23
23
*/
24
24
public function it_renders_the_control_treatment () {
25
25
$ toggleClient = app (FeatureToggleClient::class);
26
+ $ toggleClient->
setKey (
"[email protected] " );
26
27
$ this ->assertEquals ("control " , $ toggleClient ->getTreatment ("AintNoSuchFlag " ));
27
28
}
28
29
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
+
29
41
/**
30
42
* Test that an 'off' treatment can be returned.
31
43
* @test
32
44
* @return void
33
45
*/
34
46
public function it_renders_an_off_treatment () {
35
47
$ toggleClient = app (FeatureToggleClient::class);
48
+ $ toggleClient->
setKey (
"[email protected] " );
36
49
$ this ->assertEquals ("off " , $ toggleClient ->getTreatment ("FancyFeatureFlag " ));
37
50
}
38
51
You can’t perform that action at this time.
0 commit comments