Skip to content

Commit

Permalink
Add more parameters to the output for the list command
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaspaul committed Mar 29, 2017
1 parent 2f4355e commit 795a0cf
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/Console/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public function getRows() : array

$rows[] = [
'name' => $feature->getName(),
'status' => $feature->getDisplayStatus()
'status' => $feature->getDisplayStatus(),
'request-parameter' => $feature->getRequestParameter(),
'percentage' => $feature->getPercentage(),
'users' => $feature->getUsers()
];
}

Expand All @@ -73,7 +76,7 @@ public function getRows() : array
*/
public function handle()
{
$headers = ['name', 'status'];
$headers = ['name', 'status', 'request-parameter', 'percentage', 'users'];
$rows = $this->getRows();

$this->table($headers, $rows);
Expand Down
33 changes: 33 additions & 0 deletions src/FeaturePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,37 @@ public function getDisplayStatus() : string

return self::$statuses['disabled'];
}

/**
* Returns the request parameter if one is available for enabling the
* feature.
*
* @return string
* The request parameter if it's available, empty string otherwise.
*/
public function getRequestParameter() : string
{
return $this->feature->getRequestParam() ?: '';
}

/**
* Returns the percentage the feature is enabled for.
*
* @return int
* The whole percentage of users that have the feature enabled.
*/
public function getPercentage() : int
{
return (int) $this->feature->getPercentage();
}

/**
* Returns a list of the users that have this feature enabled.
*
* @return string
*/
public function getUsers() : string
{
return implode(', ', $this->feature->getUsers());
}
}
5 changes: 4 additions & 1 deletion tests/Console/ListCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class ListCommandTest extends TestCase
*/
function it_returns_an_empty_table_if_there_are_no_stored_features()
{
$expected = "+------+--------+\n| name | status |\n+------+--------+\n";
$expected = "+------+--------+-------------------+------------+-------+
| name | status | request-parameter | percentage | users |
+------+--------+-------------------+------------+-------+
";

Artisan::call('rollout:list', []);

Expand Down
60 changes: 60 additions & 0 deletions tests/FeaturePresenterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,64 @@ function get_display_status_returns_the_whitelist_message_if_it_is_enabled_for_u

$this->assertEquals(FeaturePresenter::$statuses['whitelist'], $presenter->getDisplayStatus());
}

/**
* @test
*/
function get_request_parameter_returns_an_emtpy_string_if_a_request_parameter_is_not_set_on_the_feature()
{
$feature = new Feature('name');
$presenter = new FeaturePresenter($feature);

$this->assertEquals('', $presenter->getRequestParameter());
}

/**
* @test
*/
function get_request_parameter_returns_the_request_parameter_when_one_is_set()
{
$feature = new Feature('name', '0|a|d|param');
$presenter = new FeaturePresenter($feature);

$this->assertEquals('param', $presenter->getRequestParameter());
}

/**
* @test
*/
function get_percentage_returns_the_percentage_of_users_the_feature_is_enabled_for()
{
$feature = new Feature('name');
$presenter = new FeaturePresenter($feature);

$this->assertEquals(0, $presenter->getPercentage());

$feature = new Feature('name', '88|a|d|param');
$presenter = new FeaturePresenter($feature);

$this->assertEquals(88, $presenter->getPercentage());
}

/**
* @test
*/
function get_users_returns_an_empty_string_by_default()
{
$feature = new Feature('name');
$presenter = new FeaturePresenter($feature);

$this->assertEmpty($presenter->getUsers());
}

/**
* @test
*/
function get_users_returns_a_comma_seperated_string_of_users()
{
$feature = new Feature('name', '0|user_1,user_2,user_3||param');
$presenter = new FeaturePresenter($feature);

$this->assertEquals('user_1, user_2, user_3', $presenter->getUsers());
}
}

0 comments on commit 795a0cf

Please sign in to comment.