diff --git a/src/Generators/Statements/EventGenerator.php b/src/Generators/Statements/EventGenerator.php index a79a86ca..a9bd9ffd 100644 --- a/src/Generators/Statements/EventGenerator.php +++ b/src/Generators/Statements/EventGenerator.php @@ -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) diff --git a/src/Generators/Statements/FormRequestGenerator.php b/src/Generators/Statements/FormRequestGenerator.php index 3718e060..b95973bb 100644 --- a/src/Generators/Statements/FormRequestGenerator.php +++ b/src/Generators/Statements/FormRequestGenerator.php @@ -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) diff --git a/src/Generators/Statements/JobGenerator.php b/src/Generators/Statements/JobGenerator.php index 24aa9543..e852cc01 100644 --- a/src/Generators/Statements/JobGenerator.php +++ b/src/Generators/Statements/JobGenerator.php @@ -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) diff --git a/src/Generators/Statements/MailGenerator.php b/src/Generators/Statements/MailGenerator.php index 14ef7e66..c1b5e150 100644 --- a/src/Generators/Statements/MailGenerator.php +++ b/src/Generators/Statements/MailGenerator.php @@ -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) diff --git a/tests/Feature/Generator/Statements/EventGeneratorTest.php b/tests/Feature/Generator/Statements/EventGeneratorTest.php index 1adee63c..501a897c 100644 --- a/tests/Feature/Generator/Statements/EventGeneratorTest.php +++ b/tests/Feature/Generator/Statements/EventGeneratorTest.php @@ -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')); diff --git a/tests/Feature/Generator/Statements/FormRequestGeneratorTest.php b/tests/Feature/Generator/Statements/FormRequestGeneratorTest.php index b9ba8f28..88d31478 100644 --- a/tests/Feature/Generator/Statements/FormRequestGeneratorTest.php +++ b/tests/Feature/Generator/Statements/FormRequestGeneratorTest.php @@ -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')); diff --git a/tests/Feature/Generator/Statements/JobGeneratorTest.php b/tests/Feature/Generator/Statements/JobGeneratorTest.php index 981a2bcd..1f1fb348 100644 --- a/tests/Feature/Generator/Statements/JobGeneratorTest.php +++ b/tests/Feature/Generator/Statements/JobGeneratorTest.php @@ -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')); diff --git a/tests/Feature/Generator/Statements/MailGeneratorTest.php b/tests/Feature/Generator/Statements/MailGeneratorTest.php index 7c6a6db6..5c28185d 100644 --- a/tests/Feature/Generator/Statements/MailGeneratorTest.php +++ b/tests/Feature/Generator/Statements/MailGeneratorTest.php @@ -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'));