Skip to content

Commit

Permalink
Add deactivate command
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaspaul committed Mar 30, 2017
1 parent 2378602 commit ce06156
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Console/DeactivateCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Jaspaul\LaravelRollout\Console;

use Jaspaul\LaravelRollout\Helpers\User;

class DeactivateCommand extends RolloutCommand
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rollout:deactivate {feature}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Deactivates the provided feature for everyone at once.';

/**
* Deactivates the feature for everyone.
*
* @return void
*/
public function handle()
{
$name = $this->argument('feature');
$this->rollout->deactivate($name);
}
}
2 changes: 2 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Jaspaul\LaravelRollout\Console\DeleteCommand;
use Jaspaul\LaravelRollout\Console\AddUserCommand;
use Jaspaul\LaravelRollout\Console\EveryoneCommand;
use Jaspaul\LaravelRollout\Console\DeactivateCommand;
use Jaspaul\LaravelRollout\Console\RemoveUserCommand;
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;

Expand All @@ -28,6 +29,7 @@ public function boot()
$this->commands([
AddUserCommand::class,
CreateCommand::class,
DeactivateCommand::class,
DeleteCommand::class,
EveryoneCommand::class,
ListCommand::class,
Expand Down
36 changes: 36 additions & 0 deletions tests/Console/DeactivateCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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 DeactivateCommandTest extends TestCase
{
/**
* @test
*/
function running_the_command_will_deactivate_the_feature_for_all_users()
{
$store = app()->make('cache.store')->getStore();

$rollout = app()->make(Rollout::class);
$rollout->activateUser('derp', new User("1"));
$rollout->activatePercentage('derp', 82);

$this->assertEquals('derp', $store->get('rollout.feature:__features__'));
$this->assertEquals('82|1||', $store->get('rollout.feature:derp'));

Artisan::call('rollout:deactivate', [
'feature' => 'derp'
]);

$store = app()->make('cache.store')->getStore();

$this->assertEquals('derp', $store->get('rollout.feature:__features__'));
$this->assertEquals('0|||', $store->get('rollout.feature:derp'));
}
}
2 changes: 2 additions & 0 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Jaspaul\LaravelRollout\Console\DeleteCommand;
use Jaspaul\LaravelRollout\Console\AddUserCommand;
use Jaspaul\LaravelRollout\Console\EveryoneCommand;
use Jaspaul\LaravelRollout\Console\DeactivateCommand;
use Jaspaul\LaravelRollout\Console\RemoveUserCommand;
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;

Expand Down Expand Up @@ -69,6 +70,7 @@ function booting_registers_our_commands()
[
AddUserCommand::class,
CreateCommand::class,
DeactivateCommand::class,
DeleteCommand::class,
EveryoneCommand::class,
ListCommand::class,
Expand Down

0 comments on commit ce06156

Please sign in to comment.