Skip to content

Commit ce06156

Browse files
committed
Add deactivate command
1 parent 2378602 commit ce06156

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

src/Console/DeactivateCommand.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Jaspaul\LaravelRollout\Console;
4+
5+
use Jaspaul\LaravelRollout\Helpers\User;
6+
7+
class DeactivateCommand extends RolloutCommand
8+
{
9+
/**
10+
* The name and signature of the console command.
11+
*
12+
* @var string
13+
*/
14+
protected $signature = 'rollout:deactivate {feature}';
15+
16+
/**
17+
* The console command description.
18+
*
19+
* @var string
20+
*/
21+
protected $description = 'Deactivates the provided feature for everyone at once.';
22+
23+
/**
24+
* Deactivates the feature for everyone.
25+
*
26+
* @return void
27+
*/
28+
public function handle()
29+
{
30+
$name = $this->argument('feature');
31+
$this->rollout->deactivate($name);
32+
}
33+
}

src/ServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Jaspaul\LaravelRollout\Console\DeleteCommand;
1010
use Jaspaul\LaravelRollout\Console\AddUserCommand;
1111
use Jaspaul\LaravelRollout\Console\EveryoneCommand;
12+
use Jaspaul\LaravelRollout\Console\DeactivateCommand;
1213
use Jaspaul\LaravelRollout\Console\RemoveUserCommand;
1314
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
1415

@@ -28,6 +29,7 @@ public function boot()
2829
$this->commands([
2930
AddUserCommand::class,
3031
CreateCommand::class,
32+
DeactivateCommand::class,
3133
DeleteCommand::class,
3234
EveryoneCommand::class,
3335
ListCommand::class,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Tests\Drivers;
4+
5+
use Tests\TestCase;
6+
use Opensoft\Rollout\Rollout;
7+
use Illuminate\Support\Facades\Artisan;
8+
use Jaspaul\LaravelRollout\Helpers\User;
9+
use Jaspaul\LaravelRollout\Drivers\Cache;
10+
11+
class DeactivateCommandTest extends TestCase
12+
{
13+
/**
14+
* @test
15+
*/
16+
function running_the_command_will_deactivate_the_feature_for_all_users()
17+
{
18+
$store = app()->make('cache.store')->getStore();
19+
20+
$rollout = app()->make(Rollout::class);
21+
$rollout->activateUser('derp', new User("1"));
22+
$rollout->activatePercentage('derp', 82);
23+
24+
$this->assertEquals('derp', $store->get('rollout.feature:__features__'));
25+
$this->assertEquals('82|1||', $store->get('rollout.feature:derp'));
26+
27+
Artisan::call('rollout:deactivate', [
28+
'feature' => 'derp'
29+
]);
30+
31+
$store = app()->make('cache.store')->getStore();
32+
33+
$this->assertEquals('derp', $store->get('rollout.feature:__features__'));
34+
$this->assertEquals('0|||', $store->get('rollout.feature:derp'));
35+
}
36+
}

tests/ServiceProviderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Jaspaul\LaravelRollout\Console\DeleteCommand;
1313
use Jaspaul\LaravelRollout\Console\AddUserCommand;
1414
use Jaspaul\LaravelRollout\Console\EveryoneCommand;
15+
use Jaspaul\LaravelRollout\Console\DeactivateCommand;
1516
use Jaspaul\LaravelRollout\Console\RemoveUserCommand;
1617
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
1718

@@ -69,6 +70,7 @@ function booting_registers_our_commands()
6970
[
7071
AddUserCommand::class,
7172
CreateCommand::class,
73+
DeactivateCommand::class,
7274
DeleteCommand::class,
7375
EveryoneCommand::class,
7476
ListCommand::class,

0 commit comments

Comments
 (0)