-
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.
Add the ability to whitelist a feature for a user
- Loading branch information
Showing
6 changed files
with
155 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Jaspaul\LaravelRollout\Console; | ||
|
||
use Opensoft\Rollout\Rollout; | ||
use Illuminate\Console\Command; | ||
use Jaspaul\LaravelRollout\Helpers\User; | ||
|
||
class AddUserCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'rollout:add-user {feature} {user}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Adds the provided user id to the feature.'; | ||
|
||
/** | ||
* The rollout service. | ||
* | ||
* @var \Opensoft\Rollout\Rollout | ||
*/ | ||
protected $rollout; | ||
|
||
/** | ||
* Initialize our create feature command with an instance of the rollout | ||
* service. | ||
* | ||
* @param \Opensoft\Rollout\Rollout $rollout | ||
* The rollout service. | ||
*/ | ||
public function __construct(Rollout $rollout) | ||
{ | ||
parent::__construct(); | ||
$this->rollout = $rollout; | ||
} | ||
|
||
/** | ||
* Creates the provided feature. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$name = $this->argument('feature'); | ||
$id = $this->argument('user'); | ||
|
||
$feature = $this->rollout->activateUser($name, 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,37 @@ | ||
<?php | ||
|
||
namespace Jaspaul\LaravelRollout\Helpers; | ||
|
||
use Jaspaul\LaravelRollout\Contracts\User as Contract; | ||
|
||
class User implements Contract | ||
{ | ||
/** | ||
* The id of the user. | ||
* | ||
* @var string | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* Constructs our user helper with an id. | ||
* | ||
* @param string $id | ||
* The id of the user. | ||
*/ | ||
public function __construct(string $id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
/** | ||
* The identifier to use with rollout. | ||
* | ||
* @return string | ||
* The id. | ||
*/ | ||
public function getRolloutIdentifier() | ||
{ | ||
return $this->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
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 Tests\Drivers; | ||
|
||
use Mockery; | ||
use Tests\TestCase; | ||
use Opensoft\Rollout\Rollout; | ||
use Illuminate\Cache\ArrayStore; | ||
use Illuminate\Cache\Repository; | ||
use Illuminate\Support\Facades\Artisan; | ||
use Jaspaul\LaravelRollout\Drivers\Cache; | ||
use Symfony\Component\Console\Input\Input; | ||
use Symfony\Component\Console\Output\Output; | ||
use Jaspaul\LaravelRollout\Console\CreateCommand; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Formatter\OutputFormatterInterface; | ||
|
||
class AddUserCommandTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
function running_the_command_with_a_feature_will_create_the_corresponding_feature() | ||
{ | ||
Artisan::call('rollout:add-user', [ | ||
'feature' => 'derp', | ||
'user' => 1 | ||
]); | ||
|
||
$store = app()->make('cache.store')->getStore(); | ||
|
||
$this->assertEquals('derp', $store->get('rollout.feature:__features__')); | ||
$this->assertEquals('0|1||', $store->get('rollout.feature:derp')); | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Tests\Helpers; | ||
|
||
use Tests\TestCase; | ||
use Jaspaul\LaravelRollout\Helpers\User; | ||
|
||
class UserTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
function get_rollout_identifier_returns_the_id_the_user_was_constructed_with() | ||
{ | ||
$id = "id"; | ||
|
||
$user = new User($id); | ||
|
||
$this->assertEquals($id, $user->getRolloutIdentifier()); | ||
} | ||
} |
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