Skip to content

Commit

Permalink
Ensure directories exist
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmccreary committed Dec 2, 2019
1 parent 031b803 commit dfc683a
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Generators/Statements/EventGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public function output(array $tree): array
continue;
}

if (!$this->files->exists(dirname($path))) {
$this->files->makeDirectory(dirname($path));
}

$this->files->put(
$path,
$this->populateStub($stub, $statement)
Expand Down
4 changes: 4 additions & 0 deletions src/Generators/Statements/FormRequestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public function output(array $tree): array
continue;
}

if (!$this->files->exists(dirname($path))) {
$this->files->makeDirectory(dirname($path));
}

$this->files->put(
$path,
$this->populateStub($stub, $name, $context, $statement)
Expand Down
4 changes: 4 additions & 0 deletions src/Generators/Statements/JobGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public function output(array $tree): array
continue;
}

if (!$this->files->exists(dirname($path))) {
$this->files->makeDirectory(dirname($path));
}

$this->files->put(
$path,
$this->populateStub($stub, $statement)
Expand Down
4 changes: 4 additions & 0 deletions src/Generators/Statements/MailGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public function output(array $tree): array
continue;
}

if (!$this->files->exists(dirname($path))) {
$this->files->makeDirectory(dirname($path));
}

$this->files->put(
$path,
$this->populateStub($stub, $statement)
Expand Down
6 changes: 6 additions & 0 deletions tests/Feature/Generator/Statements/EventGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,15 @@ public function output_writes_events()
->with('stubs/partials/constructor.stub')
->andReturn(file_get_contents('stubs/partials/constructor.stub'));

$this->files->shouldReceive('exists')
->twice()
->with('app/Events')
->andReturns(false, true);
$this->files->expects('exists')
->with('app/Events/UserCreated.php')
->andReturnFalse();
$this->files->expects('makeDirectory')
->with('app/Events');
$this->files->expects('put')
->with('app/Events/UserCreated.php', $this->fixture('events/user-created.php'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ public function output_writes_form_requests()
->with('stubs/form-request.stub')
->andReturn(file_get_contents('stubs/form-request.stub'));

$this->files->shouldReceive('exists')
->times(3)
->with('app/Http/Requests')
->andReturns(false, true, true);
$this->files->expects('exists')
->with('app/Http/Requests/PostIndexRequest.php')
->andReturnFalse();
$this->files->expects('makeDirectory')
->with('app/Http/Requests');
$this->files->expects('put')
->with('app/Http/Requests/PostIndexRequest.php', $this->fixture('form-requests/post-index.php'));

Expand Down
6 changes: 6 additions & 0 deletions tests/Feature/Generator/Statements/JobGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,15 @@ public function output_writes_jobs()
->with('stubs/partials/constructor.stub')
->andReturn(file_get_contents('stubs/partials/constructor.stub'));

$this->files->shouldReceive('exists')
->twice()
->with('app/Jobs')
->andReturns(false, true);
$this->files->expects('exists')
->with('app/Jobs/CreateUser.php')
->andReturnFalse();
$this->files->expects('makeDirectory')
->with('app/Jobs');
$this->files->expects('put')
->with('app/Jobs/CreateUser.php', $this->fixture('jobs/create-user.php'));

Expand Down
6 changes: 6 additions & 0 deletions tests/Feature/Generator/Statements/MailGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,15 @@ public function output_writes_mails()
->with('stubs/partials/constructor.stub')
->andReturn(file_get_contents('stubs/partials/constructor.stub'));

$this->files->shouldReceive('exists')
->twice()
->with('app/Mail')
->andReturns(false, true);
$this->files->expects('exists')
->with('app/Mail/ReviewPost.php')
->andReturnFalse();
$this->files->expects('makeDirectory')
->with('app/Mail');
$this->files->expects('put')
->with('app/Mail/ReviewPost.php', $this->fixture('mailables/review-post.php'));

Expand Down

0 comments on commit dfc683a

Please sign in to comment.