Skip to content

Commit cc903e8

Browse files
committed
Add renderFeatureAsTable method
1 parent 615a161 commit cc903e8

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

src/Console/RolloutCommand.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Opensoft\Rollout\Rollout;
66
use Illuminate\Console\Command;
7+
use Illuminate\Support\Collection;
8+
use Jaspaul\LaravelRollout\FeaturePresenter;
9+
use Jaspaul\LaravelRollout\Helpers\FeatureTable;
710

811
abstract class RolloutCommand extends Command
912
{
@@ -27,6 +30,24 @@ public function __construct(Rollout $rollout)
2730
$this->rollout = $rollout;
2831
}
2932

33+
/**
34+
* Renders the feature as a table.
35+
*
36+
* @param string $name
37+
* The name of the feature.
38+
*
39+
* @return void
40+
*/
41+
public function renderFeatureAsTable(string $name)
42+
{
43+
$presenters = (new Collection([$name]))
44+
->map(function ($feature) {
45+
return new FeaturePresenter($this->rollout->get($feature));
46+
});
47+
48+
(new FeatureTable($presenters))->render($this);
49+
}
50+
3051
/**
3152
* Performs the logic for the command.
3253
*
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Tests\Console;
4+
5+
use Mockery;
6+
use Tests\TestCase;
7+
use Opensoft\Rollout\Feature;
8+
use Opensoft\Rollout\Rollout;
9+
use Illuminate\Support\Facades\Artisan;
10+
use Illuminate\Support\ServiceProvider;
11+
use Illuminate\Contracts\Console\Kernel;
12+
use Jaspaul\LaravelRollout\Drivers\Cache;
13+
use Jaspaul\LaravelRollout\FeaturePresenter;
14+
use Jaspaul\LaravelRollout\Console\RolloutCommand;
15+
16+
class RolloutCommandTest extends TestCase
17+
{
18+
/**
19+
* @param \Illuminate\Foundation\Application $app
20+
*
21+
* @return array
22+
*/
23+
protected function getPackageProviders($app)
24+
{
25+
return [
26+
TestServiceProvider::class,
27+
];
28+
}
29+
30+
/**
31+
* @test
32+
*/
33+
function render_feature_as_a_table_renders_the_feature_as_a_table()
34+
{
35+
Artisan::call('rollout:test', [
36+
'feature' => 'derp'
37+
]);
38+
39+
$output = $this->app[Kernel::class]->output();
40+
41+
$this->assertContains('derp', $output);
42+
}
43+
}
44+
45+
class TestCommand extends RolloutCommand
46+
{
47+
protected $signature = 'rollout:test {feature}';
48+
protected $description = 'A simple helper for testing.';
49+
50+
public function handle()
51+
{
52+
$name = $this->argument('feature');
53+
$this->renderFeatureAsTable($name);
54+
}
55+
}
56+
57+
class TestServiceProvider extends ServiceProvider
58+
{
59+
/**
60+
* Boot the service provider.
61+
*
62+
* @return void
63+
*/
64+
public function boot()
65+
{
66+
$this->app->singleton(Rollout::class, function ($app) {
67+
return new Rollout(new Cache($app->make('cache.store')));
68+
});
69+
70+
$this->commands([
71+
TestCommand::class
72+
]);
73+
}
74+
}

0 commit comments

Comments
 (0)