Skip to content

Commit 641c026

Browse files
committed
Correct view path
1 parent 6199844 commit 641c026

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/Generators/Statements/ViewGenerator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@ public function output(array $tree): array
3434
$path = $this->getPath($statement->view());
3535

3636
if ($this->files->exists($path)) {
37+
// TODO: mark skipped...
3738
continue;
3839
}
3940

41+
if (!$this->files->exists(dirname($path))) {
42+
$this->files->makeDirectory(dirname($path));
43+
}
44+
4045
$this->files->put(
4146
$path,
4247
$this->populateStub($stub, $statement)
@@ -51,7 +56,7 @@ public function output(array $tree): array
5156

5257
protected function getPath(string $view)
5358
{
54-
return 'resources/' . str_replace('.', DIRECTORY_SEPARATOR, $view) . '.blade.php';
59+
return 'resources/views/' . str_replace('.', DIRECTORY_SEPARATOR, $view) . '.blade.php';
5560
}
5661

5762
protected function populateStub(string $stub, RenderStatement $renderStatement)

tests/Feature/Generator/Statements/ViewGeneratorTest.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,28 +72,38 @@ public function output_writes_views_for_render_statements()
7272
->with('stubs/view.stub')
7373
->andReturn($template);
7474

75+
$this->files->shouldReceive('exists')
76+
->times(2)
77+
->with('resources/views/user')
78+
->andReturnTrue();
7579
$this->files->expects('exists')
76-
->with('resources/user/index.blade.php')
80+
->with('resources/views/user/index.blade.php')
7781
->andReturnFalse();
7882
$this->files->expects('put')
79-
->with('resources/user/index.blade.php', str_replace('DummyView', 'user.index', $template));
83+
->with('resources/views/user/index.blade.php', str_replace('DummyView', 'user.index', $template));
8084

8185
$this->files->expects('exists')
82-
->with('resources/user/create.blade.php')
86+
->with('resources/views/user/create.blade.php')
8387
->andReturnFalse();
8488
$this->files->expects('put')
85-
->with('resources/user/create.blade.php', str_replace('DummyView', 'user.create', $template));
89+
->with('resources/views/user/create.blade.php', str_replace('DummyView', 'user.create', $template));
8690

8791
$this->files->expects('exists')
88-
->with('resources/post/show.blade.php')
92+
->with('resources/views/post')
93+
->andReturns(false, true);
94+
$this->files->expects('exists')
95+
->with('resources/views/post/show.blade.php')
96+
->andReturnFalse();
97+
$this->files->expects('makeDirectory')
98+
->with('resources/views/post')
8999
->andReturnFalse();
90100
$this->files->expects('put')
91-
->with('resources/post/show.blade.php', str_replace('DummyView', 'post.show', $template));
101+
->with('resources/views/post/show.blade.php', str_replace('DummyView', 'post.show', $template));
92102

93103
$tokens = $this->blueprint->parse($this->fixture('definitions/render-statements.bp'));
94104
$tree = $this->blueprint->analyze($tokens);
95105

96-
$this->assertEquals(['created' => ['resources/user/index.blade.php', 'resources/user/create.blade.php', 'resources/post/show.blade.php']], $this->subject->output($tree));
106+
$this->assertEquals(['created' => ['resources/views/user/index.blade.php', 'resources/views/user/create.blade.php', 'resources/views/post/show.blade.php']], $this->subject->output($tree));
97107
}
98108

99109
/**
@@ -106,13 +116,13 @@ public function it_only_outputs_new_views()
106116
->andReturn(file_get_contents('stubs/view.stub'));
107117

108118
$this->files->expects('exists')
109-
->with('resources/user/index.blade.php')
119+
->with('resources/views/user/index.blade.php')
110120
->andReturnTrue();
111121
$this->files->expects('exists')
112-
->with('resources/user/create.blade.php')
122+
->with('resources/views/user/create.blade.php')
113123
->andReturnTrue();
114124
$this->files->expects('exists')
115-
->with('resources/post/show.blade.php')
125+
->with('resources/views/post/show.blade.php')
116126
->andReturnTrue();
117127

118128
$tokens = $this->blueprint->parse($this->fixture('definitions/render-statements.bp'));

0 commit comments

Comments
 (0)