Skip to content

Commit 145c4d5

Browse files
authored
Merge pull request #209 from RonasIT/throw-directly-ResourceAlreadyExistsException
fix: usage relative file path in ResourceAlreadyExistsException
2 parents 16d5d20 + 8a28f40 commit 145c4d5

File tree

8 files changed

+12
-12
lines changed

8 files changed

+12
-12
lines changed

src/Generators/EntityGenerator.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,18 @@ abstract public function generate(): void;
145145

146146
protected function classExists(string $path, string $name, ?string $subFolder = null): bool
147147
{
148-
$classPath = $this->getClassPath($path, $name, $subFolder);
148+
$relativePath = $this->getClassPath($path, $name, $subFolder);
149149

150-
return file_exists($classPath);
150+
$absolutePath = base_path($relativePath);
151+
152+
return file_exists($absolutePath);
151153
}
152154

153155
protected function getClassPath(string $path, string $name, ?string $subFolder = null): string
154156
{
155157
$path = $this->getPath($path, $subFolder);
156158

157-
return base_path("{$path}/{$name}.php");
159+
return "{$path}/{$name}.php";
158160
}
159161

160162
protected function saveClass($path, $name, $content, ?string $entityFolder = null): string

src/Generators/NovaTestGenerator.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Laravel\Nova\NovaServiceProvider;
77
use Laravel\Nova\Http\Requests\NovaRequest;
88
use RonasIT\Support\Events\SuccessCreateMessage;
9-
use RonasIT\Support\Exceptions\ClassAlreadyExistsException;
109
use RonasIT\Support\Exceptions\ClassNotExistsException;
1110
use RonasIT\Support\Exceptions\EntityCreateException;
1211
use Generator;
@@ -43,7 +42,6 @@ public function generate(): void
4342
}
4443

4544
if (empty($novaResources)) {
46-
// TODO: pass $this->modelSubfolder to Exception after refactoring in https://github.com/RonasIT/laravel-entity-generator/issues/179
4745
$this->throwFailureException(
4846
ClassNotExistsException::class,
4947
"Cannot create Nova{$this->model}ResourceTest cause {$this->model} Nova resource does not exist.",

tests/ControllerGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testControllerAlreadyExists()
3030

3131
$this->assertExceptionThrew(
3232
className: ResourceAlreadyExistsException::class,
33-
message: 'Cannot create PostController cause it already exists. Remove vfs://root/app/Http/Controllers/PostController.php and run command again.',
33+
message: 'Cannot create PostController cause it already exists. Remove app/Http/Controllers/PostController.php and run command again.',
3434
);
3535

3636
app(ControllerGenerator::class)

tests/FactoryGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function testFactoryClassExists()
4646
{
4747
$this->assertExceptionThrew(
4848
className: ResourceAlreadyExistsException::class,
49-
message: 'Cannot create PostFactory cause it already exists. Remove vfs://root/database/factories/PostFactory.php and run command again.',
49+
message: 'Cannot create PostFactory cause it already exists. Remove database/factories/PostFactory.php and run command again.',
5050
);
5151

5252
$this->mockFactoryGenerator(

tests/ModelGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testModelAlreadyExists()
3030

3131
$this->assertExceptionThrew(
3232
className: ResourceAlreadyExistsException::class,
33-
message: 'Cannot create Post cause it already exists. Remove vfs://root/app/Models/Blog/Post.php and run command again.',
33+
message: 'Cannot create Post cause it already exists. Remove app/Models/Blog/Post.php and run command again.',
3434
);
3535

3636
app(ModelGenerator::class)

tests/NovaResourceGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testCreateNovaTestAlreadyExists()
6363

6464
$this->assertExceptionThrew(
6565
className: ResourceAlreadyExistsException::class,
66-
message: 'Cannot create PostResource cause it already exists. Remove vfs://root/app/Nova/PostResource.php and run command again.',
66+
message: 'Cannot create PostResource cause it already exists. Remove app/Nova/PostResource.php and run command again.',
6767
);
6868

6969
app(NovaResourceGenerator::class)

tests/NovaTestGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function testGenerateNovaTestAlreadyExists()
7272

7373
$this->assertExceptionThrew(
7474
className: ResourceAlreadyExistsException::class,
75-
message: "Cannot create NovaPostResourceTest cause it already exists. Remove vfs://root/app/Nova/NovaPostResourceTest.php and run command again.",
75+
message: "Cannot create NovaPostResourceTest cause it already exists. Remove app/Nova/NovaPostResourceTest.php and run command again.",
7676
);
7777

7878
app(NovaTestGenerator::class)

tests/ResourceGeneratorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function testResourceAlreadyExists()
2020

2121
$this->assertExceptionThrew(
2222
className: ResourceAlreadyExistsException::class,
23-
message: 'Cannot create PostResource cause it already exists. Remove vfs://root/app/Http/Resources/PostResource.php and run command again.',
23+
message: 'Cannot create PostResource cause it already exists. Remove app/Http/Resources/PostResource.php and run command again.',
2424
);
2525

2626
app(ResourceGenerator::class)
@@ -37,7 +37,7 @@ public function testCollectionResourceAlreadyExists()
3737

3838
$this->assertExceptionThrew(
3939
className: ResourceAlreadyExistsException::class,
40-
message: 'Cannot create PostsCollectionResource cause it already exists. Remove vfs://root/app/Http/Resources/PostsCollectionResource.php and run command again.',
40+
message: 'Cannot create PostsCollectionResource cause it already exists. Remove app/Http/Resources/PostsCollectionResource.php and run command again.',
4141
);
4242

4343
app(ResourceGenerator::class)

0 commit comments

Comments
 (0)