We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
blueprint:new
1 parent 4d930ba commit 5282450Copy full SHA for 5282450
src/BlueprintServiceProvider.php
@@ -4,6 +4,7 @@
4
5
use Blueprint\Commands\BlueprintCommand;
6
use Blueprint\Commands\EraseCommand;
7
+use Blueprint\Commands\NewCommand;
8
use Blueprint\Commands\TraceCommand;
9
use Illuminate\Contracts\Support\DeferrableProvider;
10
use Illuminate\Support\Facades\File;
@@ -55,6 +56,11 @@ function ($app) {
55
56
return new TraceCommand($app['files']);
57
}
58
);
59
+ $this->app->bind('command.blueprint.new',
60
+ function ($app) {
61
+ return new NewCommand($app['files']);
62
+ }
63
+ );
64
65
$this->app->singleton(Blueprint::class, function ($app) {
66
$blueprint = new Blueprint();
@@ -83,6 +89,7 @@ function ($app) {
83
89
'command.blueprint.build',
84
90
'command.blueprint.erase',
85
91
'command.blueprint.trace',
92
+ 'command.blueprint.new',
86
93
]);
87
94
88
95
@@ -97,6 +104,7 @@ public function provides()
97
104
98
105
99
106
107
100
108
Blueprint::class,
101
109
];
102
110
src/Commands/NewCommand.php
@@ -0,0 +1,52 @@
1
+<?php
2
+
3
+namespace Blueprint\Commands;
+use Illuminate\Console\Command;
+use Illuminate\Filesystem\Filesystem;
+class NewCommand extends Command
+{
+ /**
11
+ * The name and signature of the console command.
12
+ *
13
+ * @var string
14
+ */
15
+ protected $signature = 'blueprint:new';
16
17
18
+ * The console command description.
19
20
21
22
+ protected $description = 'Create a draft.yaml file and load existing models';
23
24
+ /** @var Filesystem $files */
25
+ protected $files;
26
27
28
+ * @param Filesystem $files
29
30
+ public function __construct(Filesystem $files)
31
+ {
32
+ parent::__construct();
33
34
+ $this->files = $files;
35
36
37
38
+ * Execute the console command.
39
40
+ * @return mixed
41
42
+ public function handle()
43
44
+ if (!$this->files->exists('draft.yaml')) {
45
+ $this->files->put('draft.yaml', $this->files->stub('draft.stub'));
46
47
+ $this->info('Created example draft.yaml');
48
49
50
+ $this->call('blueprint:trace');
51
52
+}
stubs/draft.stub
@@ -0,0 +1,5 @@
+models:
+ # ...
+controllers:
tests/Feature/Commands/StartCommandTest.php
@@ -0,0 +1,53 @@
+namespace Tests\Feature\Commands;
+use Illuminate\Support\Facades\Artisan;
+use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
+use Tests\TestCase;
+/**
+ * @covers \Blueprint\Commands\NewCommand;
+class StartCommandTest extends TestCase
+ use MockeryPHPUnitIntegration;
+ * @test
+ public function it_creates_a_draft_file_from_stub_if_none_exists()
+ $filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial();
+ $this->swap('files', $filesystem);
+ $filesystem->shouldReceive('exists')
+ ->with('draft.yaml')
+ ->andReturnFalse();
+ $filesystem->shouldReceive('stub')
+ ->with('draft.stub')
+ ->andReturn('stub');
+ $filesystem->shouldReceive('put')
+ ->with('draft.yaml', 'stub');
+ $this->artisan('blueprint:new')
+ ->assertExitCode(0);
+ public function it_does_not_create_a_draft_file_if_one_exists_already()
+ ->andReturnTrue();
+ $filesystem->shouldNotReceive('put');
53
tests/TestCase.php
@@ -2,6 +2,8 @@
namespace Tests;
+use Blueprint\BlueprintServiceProvider;
class TestCase extends \Orchestra\Testbench\TestCase
{
protected function getEnvironmentSetUp($app)
@@ -19,4 +21,11 @@ public function fixture(string $path)
return file_get_contents(__DIR__ . '/' . 'fixtures' . '/' . ltrim($path, '/'));
+ protected function getPackageProviders($app)
+ return [
+ BlueprintServiceProvider::class,
+ ];
0 commit comments