Skip to content

Commit 615a161

Browse files
committed
Update the FeatureTable to be self rendering
1 parent c00d68d commit 615a161

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

src/Console/ListCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ public function handle()
3434
return new FeaturePresenter($this->rollout->get($feature));
3535
});
3636

37-
$table = new FeatureTable($presenters);
38-
39-
$this->table($table->getHeaders()->toArray(), $table->getRows());
37+
(new FeatureTable($presenters))->render($this);
4038
}
4139
}

src/Helpers/FeatureTable.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Jaspaul\LaravelRollout\Helpers;
44

55
use Opensoft\Rollout\Feature;
6+
use Illuminate\Console\Command;
67
use Illuminate\Support\Collection;
78
use Jaspaul\LaravelRollout\FeaturePresenter;
89

@@ -50,4 +51,17 @@ public function getRows() : Collection
5051
return $feature->toArray();
5152
});
5253
}
54+
55+
/**
56+
* Renders itself as a table through the provided command.
57+
*
58+
* @param \Illuminate\Console\Command $command
59+
* The command to render the table into.
60+
*
61+
* @return void
62+
*/
63+
public function render(Command $command)
64+
{
65+
$command->table($this->getHeaders()->toArray(), $this->getRows()->toArray());
66+
}
5367
}

tests/Helpers/FeatureTableTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace Tests\Helpers;
44

5+
use Mockery;
56
use Tests\TestCase;
67
use Opensoft\Rollout\Feature;
8+
use Illuminate\Console\Command;
79
use Illuminate\Support\Collection;
810
use Jaspaul\LaravelRollout\FeaturePresenter;
911
use Jaspaul\LaravelRollout\Helpers\FeatureTable;
@@ -35,4 +37,27 @@ function get_rows_will_only_return_rows_for_feature_presenters_in_the_collection
3537
$this->assertEquals(1, $table->getRows()->count());
3638
$this->assertSame($presenter->toArray(), $table->getRows()->first());
3739
}
40+
41+
/**
42+
* @test
43+
*/
44+
function render_renders_a_table_with_the_tables_rows_and_headers()
45+
{
46+
$presenter = new FeaturePresenter(new Feature('test'));
47+
$collection = new Collection([$presenter, [], 'hi', 'alpha']);
48+
49+
$table = new FeatureTable($collection);
50+
51+
$command = Mockery::mock(Command::class);
52+
$command->shouldReceive('table')
53+
->with(Mockery::on(function (array $keys) use ($presenter) {
54+
$this->assertSame(array_keys($presenter->toArray()), $keys);
55+
return true;
56+
}), Mockery::on(function (array $rows) use ($presenter) {
57+
$this->assertSame([$presenter->toArray()], $rows);
58+
return true;
59+
}))->once();
60+
61+
$table->render($command);
62+
}
3863
}

tests/TestCase.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ protected function getPackageProviders($app)
2828
ServiceProvider::class,
2929
];
3030
}
31+
32+
/**
33+
* @after
34+
*/
35+
protected function close_mockery()
36+
{
37+
Mockery::close();
38+
}
3139
}

0 commit comments

Comments
 (0)