Skip to content

Commit 1e0e9d1

Browse files
committed
Add a basic feature create command
1 parent e87d82f commit 1e0e9d1

File tree

7 files changed

+115
-3
lines changed

7 files changed

+115
-3
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"require-dev": {
2121
"illuminate/container": "^5.3|^5.4",
2222
"mockery/mockery": "^0.9.9",
23+
"orchestra/testbench": "^3.4",
2324
"phpunit/phpunit": "^6.0",
2425
"satooshi/php-coveralls": "^1.0",
2526
"squizlabs/php_codesniffer": "^2.8"

src/Console/CreateCommand.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Jaspaul\LaravelRollout\Console;
4+
5+
use Opensoft\Rollout\Rollout;
6+
use Illuminate\Console\Command;
7+
8+
class CreateCommand extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'rollout:create {feature}';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Creates a feature with the provided name.';
23+
24+
/**
25+
* The rollout service.
26+
*
27+
* @var \Opensoft\Rollout\Rollout
28+
*/
29+
protected $rollout;
30+
31+
/**
32+
* Initialize our create feature command with an instance of the rollout
33+
* service.
34+
*
35+
* @param \Opensoft\Rollout\Rollout $rollout
36+
* The rollout service.
37+
*/
38+
public function __construct(Rollout $rollout)
39+
{
40+
parent::__construct();
41+
$this->rollout = $rollout;
42+
}
43+
44+
/**
45+
* Creates the provided feature.
46+
*
47+
* @return void
48+
*/
49+
public function handle()
50+
{
51+
$name = $this->argument('feature');
52+
$this->rollout->get($name);
53+
}
54+
}

src/Console/ListCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ListCommand extends Command
3737
*/
3838
public function __construct(Rollout $rollout)
3939
{
40+
parent::__construct();
4041
$this->rollout = $rollout;
4142
}
4243

src/ServiceProvider.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Opensoft\Rollout\Rollout;
66
use Jaspaul\LaravelRollout\Drivers\Cache;
77
use Jaspaul\LaravelRollout\Console\ListCommand;
8+
use Jaspaul\LaravelRollout\Console\CreateCommand;
89
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
910

1011
class ServiceProvider extends IlluminateServiceProvider
@@ -20,6 +21,9 @@ public function boot()
2021
return new Rollout(new Cache($app->make('cache.store')));
2122
});
2223

23-
$this->commands([ListCommand::class]);
24+
$this->commands([
25+
CreateCommand::class,
26+
ListCommand::class
27+
]);
2428
}
2529
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Tests\Drivers;
4+
5+
use Mockery;
6+
use Tests\TestCase;
7+
use Opensoft\Rollout\Rollout;
8+
use Illuminate\Cache\ArrayStore;
9+
use Illuminate\Cache\Repository;
10+
use Illuminate\Support\Facades\Artisan;
11+
use Jaspaul\LaravelRollout\Drivers\Cache;
12+
use Symfony\Component\Console\Input\Input;
13+
use Symfony\Component\Console\Output\Output;
14+
use Jaspaul\LaravelRollout\Console\CreateCommand;
15+
use Symfony\Component\Console\Input\InputInterface;
16+
use Symfony\Component\Console\Output\OutputInterface;
17+
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
18+
19+
class CreateCommandTest extends TestCase
20+
{
21+
/**
22+
* @test
23+
*/
24+
function running_the_command_with_a_feature_will_create_the_corresponding_feature()
25+
{
26+
Artisan::call('rollout:create', [
27+
'feature' => 'derp'
28+
]);
29+
30+
$store = app()->make('cache.store')->getStore();
31+
32+
$this->assertEquals('derp', $store->get('rollout.feature:__features__'));
33+
$this->assertEquals('0|||', $store->get('rollout.feature:derp'));
34+
}
35+
}

tests/ServiceProviderTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Contracts\Cache\Repository;
99
use Jaspaul\LaravelRollout\ServiceProvider;
1010
use Jaspaul\LaravelRollout\Console\ListCommand;
11+
use Jaspaul\LaravelRollout\Console\CreateCommand;
1112
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
1213

1314
class ServiceProviderTest extends TestCase
@@ -60,7 +61,10 @@ function booting_registers_our_commands()
6061
$serviceProvider = new TestServiceProvider($this->container);
6162
$serviceProvider->boot();
6263

63-
$this->assertEquals([ListCommand::class], $serviceProvider->commands);
64+
$this->assertEquals(
65+
[CreateCommand::class, ListCommand::class],
66+
$serviceProvider->commands
67+
);
6468
}
6569
}
6670

tests/TestCase.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace Tests;
44

55
use Mockery;
6-
use PHPUnit\Framework\TestCase as Base;
6+
use Orchestra\Testbench\TestCase as Base;
7+
use Jaspaul\LaravelRollout\ServiceProvider;
78

89
abstract class TestCase extends Base
910
{
@@ -15,4 +16,16 @@ protected function setUpMockery()
1516
Mockery::getConfiguration()->allowMockingNonExistentMethods(false);
1617
Mockery::getConfiguration()->allowMockingMethodsUnnecessarily(false);
1718
}
19+
20+
/**
21+
* @param \Illuminate\Foundation\Application $app
22+
*
23+
* @return array
24+
*/
25+
protected function getPackageProviders($app)
26+
{
27+
return [
28+
ServiceProvider::class,
29+
];
30+
}
1831
}

0 commit comments

Comments
 (0)