-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Introduces the ability to define groups for rollout (#14)
* Introduces the ability to define groups for rollout
- Loading branch information
Showing
12 changed files
with
380 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Jaspaul\LaravelRollout\Console; | ||
|
||
class AddGroupCommand extends RolloutCommand | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'rollout:add-group {feature} {group}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Enables the provided feature for the group.'; | ||
|
||
/** | ||
* Adds the provided group to the requested feature. Note this will create | ||
* the feature as a side effect. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$name = $this->argument('feature'); | ||
$group = $this->argument('group'); | ||
|
||
$this->rollout->activateGroup($name, $group); | ||
|
||
$this->renderFeatureAsTable($name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Jaspaul\LaravelRollout\Console; | ||
|
||
use Jaspaul\LaravelRollout\Helpers\User; | ||
|
||
class RemoveGroupCommand extends RolloutCommand | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'rollout:remove-group {feature} {group}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Removes the provided group from the feature.'; | ||
|
||
/** | ||
* Removes the provided user from the feature. Note this will create | ||
* the feature as a side effect. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$name = $this->argument('feature'); | ||
$group = $this->argument('group'); | ||
|
||
$this->rollout->deactivateGroup($name, $group); | ||
|
||
$this->renderFeatureAsTable($name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Jaspaul\LaravelRollout\Contracts; | ||
|
||
use Opensoft\Rollout\RolloutUserInterface; | ||
|
||
interface Group | ||
{ | ||
/** | ||
* The name of the group. | ||
* | ||
* @return string | ||
*/ | ||
public function getName(): string; | ||
|
||
/** | ||
* Checks if the given user is a member of this group. | ||
* | ||
* @param mixed $user | ||
* | ||
* @return boolean | ||
*/ | ||
public function hasMember($user = null): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Tests\Drivers; | ||
|
||
use Tests\TestCase; | ||
use Opensoft\Rollout\Rollout; | ||
use Tests\Doubles\SampleGroup; | ||
use Illuminate\Support\Facades\Artisan; | ||
use Jaspaul\LaravelRollout\Helpers\User; | ||
use Jaspaul\LaravelRollout\Drivers\Cache; | ||
|
||
class AddGroupCommandTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function running_the_command_with_a_feature_will_create_the_corresponding_feature() | ||
{ | ||
Artisan::call('rollout:add-group', [ | ||
'feature' => 'derp', | ||
'group' => 'ballers' | ||
]); | ||
|
||
$store = app()->make('cache.store')->getStore(); | ||
|
||
$this->assertEquals('derp', $store->get('rollout.feature:__features__')); | ||
$this->assertEquals('0||ballers|', $store->get('rollout.feature:derp')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function rollout_will_flag_a_user_as_active_if_the_group_returns_true() | ||
{ | ||
config(['laravel-rollout.groups' => [SampleGroup::class]]); | ||
|
||
$this->assertFalse(app()->make(Rollout::class)->isActive('derp', new User('id'))); | ||
|
||
Artisan::call('rollout:add-group', [ | ||
'feature' => 'derp', | ||
'group' => 'sample-group' | ||
]); | ||
|
||
$this->assertTrue(app()->make(Rollout::class)->isActive('derp', new User('id'))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Tests\Drivers; | ||
|
||
use Tests\TestCase; | ||
use Opensoft\Rollout\Rollout; | ||
use Illuminate\Support\Facades\Artisan; | ||
use Jaspaul\LaravelRollout\Helpers\User; | ||
use Jaspaul\LaravelRollout\Drivers\Cache; | ||
|
||
class RemoveGroupCommandTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function running_the_command_with_a_feature_will_remove_the_corresponding_user() | ||
{ | ||
$store = app()->make('cache.store')->getStore(); | ||
|
||
$rollout = app()->make(Rollout::class); | ||
$rollout->activateGroup('derp', 'ballers'); | ||
|
||
$this->assertEquals('derp', $store->get('rollout.feature:__features__')); | ||
$this->assertEquals('0||ballers|', $store->get('rollout.feature:derp')); | ||
|
||
Artisan::call('rollout:remove-group', [ | ||
'feature' => 'derp', | ||
'group' => 'ballers' | ||
]); | ||
|
||
$this->assertEquals('derp', $store->get('rollout.feature:__features__')); | ||
$this->assertEquals('0|||', $store->get('rollout.feature:derp')); | ||
} | ||
} |
Oops, something went wrong.