|
| 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