Skip to content

Commit dfc683a

Browse files
committed
Ensure directories exist
1 parent 031b803 commit dfc683a

File tree

8 files changed

+40
-0
lines changed

8 files changed

+40
-0
lines changed

src/Generators/Statements/EventGenerator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public function output(array $tree): array
4141
continue;
4242
}
4343

44+
if (!$this->files->exists(dirname($path))) {
45+
$this->files->makeDirectory(dirname($path));
46+
}
47+
4448
$this->files->put(
4549
$path,
4650
$this->populateStub($stub, $statement)

src/Generators/Statements/FormRequestGenerator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public function output(array $tree): array
4747
continue;
4848
}
4949

50+
if (!$this->files->exists(dirname($path))) {
51+
$this->files->makeDirectory(dirname($path));
52+
}
53+
5054
$this->files->put(
5155
$path,
5256
$this->populateStub($stub, $name, $context, $statement)

src/Generators/Statements/JobGenerator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public function output(array $tree): array
3737
continue;
3838
}
3939

40+
if (!$this->files->exists(dirname($path))) {
41+
$this->files->makeDirectory(dirname($path));
42+
}
43+
4044
$this->files->put(
4145
$path,
4246
$this->populateStub($stub, $statement)

src/Generators/Statements/MailGenerator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public function output(array $tree): array
3737
continue;
3838
}
3939

40+
if (!$this->files->exists(dirname($path))) {
41+
$this->files->makeDirectory(dirname($path));
42+
}
43+
4044
$this->files->put(
4145
$path,
4246
$this->populateStub($stub, $statement)

tests/Feature/Generator/Statements/EventGeneratorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,15 @@ public function output_writes_events()
7575
->with('stubs/partials/constructor.stub')
7676
->andReturn(file_get_contents('stubs/partials/constructor.stub'));
7777

78+
$this->files->shouldReceive('exists')
79+
->twice()
80+
->with('app/Events')
81+
->andReturns(false, true);
7882
$this->files->expects('exists')
7983
->with('app/Events/UserCreated.php')
8084
->andReturnFalse();
85+
$this->files->expects('makeDirectory')
86+
->with('app/Events');
8187
$this->files->expects('put')
8288
->with('app/Events/UserCreated.php', $this->fixture('events/user-created.php'));
8389

tests/Feature/Generator/Statements/FormRequestGeneratorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,15 @@ public function output_writes_form_requests()
7272
->with('stubs/form-request.stub')
7373
->andReturn(file_get_contents('stubs/form-request.stub'));
7474

75+
$this->files->shouldReceive('exists')
76+
->times(3)
77+
->with('app/Http/Requests')
78+
->andReturns(false, true, true);
7579
$this->files->expects('exists')
7680
->with('app/Http/Requests/PostIndexRequest.php')
7781
->andReturnFalse();
82+
$this->files->expects('makeDirectory')
83+
->with('app/Http/Requests');
7884
$this->files->expects('put')
7985
->with('app/Http/Requests/PostIndexRequest.php', $this->fixture('form-requests/post-index.php'));
8086

tests/Feature/Generator/Statements/JobGeneratorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,15 @@ public function output_writes_jobs()
7575
->with('stubs/partials/constructor.stub')
7676
->andReturn(file_get_contents('stubs/partials/constructor.stub'));
7777

78+
$this->files->shouldReceive('exists')
79+
->twice()
80+
->with('app/Jobs')
81+
->andReturns(false, true);
7882
$this->files->expects('exists')
7983
->with('app/Jobs/CreateUser.php')
8084
->andReturnFalse();
85+
$this->files->expects('makeDirectory')
86+
->with('app/Jobs');
8187
$this->files->expects('put')
8288
->with('app/Jobs/CreateUser.php', $this->fixture('jobs/create-user.php'));
8389

tests/Feature/Generator/Statements/MailGeneratorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,15 @@ public function output_writes_mails()
7575
->with('stubs/partials/constructor.stub')
7676
->andReturn(file_get_contents('stubs/partials/constructor.stub'));
7777

78+
$this->files->shouldReceive('exists')
79+
->twice()
80+
->with('app/Mail')
81+
->andReturns(false, true);
7882
$this->files->expects('exists')
7983
->with('app/Mail/ReviewPost.php')
8084
->andReturnFalse();
85+
$this->files->expects('makeDirectory')
86+
->with('app/Mail');
8187
$this->files->expects('put')
8288
->with('app/Mail/ReviewPost.php', $this->fixture('mailables/review-post.php'));
8389

0 commit comments

Comments
 (0)