Skip to content

Commit dbc5dc9

Browse files
committed
Add the ability to remove a user from rollout
1 parent e085746 commit dbc5dc9

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-2
lines changed

src/Console/RemoveUserCommand.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Jaspaul\LaravelRollout\Console;
4+
5+
use Jaspaul\LaravelRollout\Helpers\User;
6+
7+
class RemoveUserCommand extends RolloutCommand
8+
{
9+
/**
10+
* The name and signature of the console command.
11+
*
12+
* @var string
13+
*/
14+
protected $signature = 'rollout:remove-user {feature} {user}';
15+
16+
/**
17+
* The console command description.
18+
*
19+
* @var string
20+
*/
21+
protected $description = 'Removes the provided user id from the feature.';
22+
23+
/**
24+
* Removes the provided user from the feature. Note this will create
25+
* the feature as a side effect.
26+
*
27+
* @return void
28+
*/
29+
public function handle()
30+
{
31+
$name = $this->argument('feature');
32+
$userIdentifier = $this->argument('user');
33+
34+
$this->rollout->deactivateUser($name, new User($userIdentifier));
35+
}
36+
}

src/ServiceProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Jaspaul\LaravelRollout\Console\ListCommand;
88
use Jaspaul\LaravelRollout\Console\CreateCommand;
99
use Jaspaul\LaravelRollout\Console\AddUserCommand;
10+
use Jaspaul\LaravelRollout\Console\RemoveUserCommand;
1011
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
1112

1213
class ServiceProvider extends IlluminateServiceProvider
@@ -25,7 +26,8 @@ public function boot()
2526
$this->commands([
2627
AddUserCommand::class,
2728
CreateCommand::class,
28-
ListCommand::class
29+
ListCommand::class,
30+
RemoveUserCommand::class
2931
]);
3032
}
3133
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Tests\Drivers;
4+
5+
use Mockery;
6+
use Tests\TestCase;
7+
use Opensoft\Rollout\Rollout;
8+
use Illuminate\Cache\ArrayStore;
9+
use Illuminate\Cache\Repository;
10+
use Illuminate\Support\Facades\Artisan;
11+
use Jaspaul\LaravelRollout\Helpers\User;
12+
use Jaspaul\LaravelRollout\Drivers\Cache;
13+
use Symfony\Component\Console\Input\Input;
14+
use Symfony\Component\Console\Output\Output;
15+
use Jaspaul\LaravelRollout\Console\CreateCommand;
16+
use Symfony\Component\Console\Input\InputInterface;
17+
use Symfony\Component\Console\Output\OutputInterface;
18+
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
19+
20+
class RemoveUserCommandTest extends TestCase
21+
{
22+
/**
23+
* @test
24+
*/
25+
function running_the_command_with_a_feature_will_create_the_corresponding_feature()
26+
{
27+
$store = app()->make('cache.store')->getStore();
28+
29+
$rollout = app()->make(Rollout::class);
30+
$rollout->activateUser('derp', new User('1'));
31+
32+
$this->assertEquals('derp', $store->get('rollout.feature:__features__'));
33+
$this->assertEquals('0|1||', $store->get('rollout.feature:derp'));
34+
35+
Artisan::call('rollout:remove-user', [
36+
'feature' => 'derp',
37+
'user' => 1
38+
]);
39+
40+
$this->assertEquals('derp', $store->get('rollout.feature:__features__'));
41+
$this->assertEquals('0|||', $store->get('rollout.feature:derp'));
42+
}
43+
}

tests/ServiceProviderTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Jaspaul\LaravelRollout\Console\ListCommand;
1111
use Jaspaul\LaravelRollout\Console\CreateCommand;
1212
use Jaspaul\LaravelRollout\Console\AddUserCommand;
13+
use Jaspaul\LaravelRollout\Console\RemoveUserCommand;
1314
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
1415

1516
class ServiceProviderTest extends TestCase
@@ -63,7 +64,12 @@ function booting_registers_our_commands()
6364
$serviceProvider->boot();
6465

6566
$this->assertEquals(
66-
[AddUserCommand::class, CreateCommand::class, ListCommand::class],
67+
[
68+
AddUserCommand::class,
69+
CreateCommand::class,
70+
ListCommand::class,
71+
RemoveUserCommand::class
72+
],
6773
$serviceProvider->commands
6874
);
6975
}

0 commit comments

Comments
 (0)