Skip to content

Commit 044a172

Browse files
committed
Add a percentage rollout command
1 parent e19794c commit 044a172

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

src/Console/PercentageCommand.php

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

src/ServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Jaspaul\LaravelRollout\Console\AddUserCommand;
1111
use Jaspaul\LaravelRollout\Console\EveryoneCommand;
1212
use Jaspaul\LaravelRollout\Console\DeactivateCommand;
13+
use Jaspaul\LaravelRollout\Console\PercentageCommand;
1314
use Jaspaul\LaravelRollout\Console\RemoveUserCommand;
1415
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
1516

@@ -33,6 +34,7 @@ public function boot()
3334
DeleteCommand::class,
3435
EveryoneCommand::class,
3536
ListCommand::class,
37+
PercentageCommand::class,
3638
RemoveUserCommand::class
3739
]);
3840
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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\Drivers\Cache;
9+
10+
class PercentageCommandTest extends TestCase
11+
{
12+
/**
13+
* @test
14+
*/
15+
function running_the_command_will_update_the_percentage_to_the_provided_value()
16+
{
17+
Artisan::call('rollout:percentage', [
18+
'feature' => 'derp',
19+
'percentage' => 88
20+
]);
21+
22+
$store = app()->make('cache.store')->getStore();
23+
24+
$this->assertEquals('derp', $store->get('rollout.feature:__features__'));
25+
$this->assertEquals('88|||', $store->get('rollout.feature:derp'));
26+
}
27+
}

tests/ServiceProviderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Jaspaul\LaravelRollout\Console\AddUserCommand;
1414
use Jaspaul\LaravelRollout\Console\EveryoneCommand;
1515
use Jaspaul\LaravelRollout\Console\DeactivateCommand;
16+
use Jaspaul\LaravelRollout\Console\PercentageCommand;
1617
use Jaspaul\LaravelRollout\Console\RemoveUserCommand;
1718
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
1819

@@ -74,6 +75,7 @@ function booting_registers_our_commands()
7475
DeleteCommand::class,
7576
EveryoneCommand::class,
7677
ListCommand::class,
78+
PercentageCommand::class,
7779
RemoveUserCommand::class
7880
],
7981
$serviceProvider->commands

0 commit comments

Comments
 (0)