diff --git a/src/Generators/EntityGenerator.php b/src/Generators/EntityGenerator.php index 44c8cd8..74455dc 100644 --- a/src/Generators/EntityGenerator.php +++ b/src/Generators/EntityGenerator.php @@ -145,16 +145,18 @@ abstract public function generate(): void; protected function classExists(string $path, string $name, ?string $subFolder = null): bool { - $classPath = $this->getClassPath($path, $name, $subFolder); + $relativePath = $this->getClassPath($path, $name, $subFolder); - return file_exists($classPath); + $absolutePath = base_path($relativePath); + + return file_exists($absolutePath); } protected function getClassPath(string $path, string $name, ?string $subFolder = null): string { $path = $this->getPath($path, $subFolder); - return base_path("{$path}/{$name}.php"); + return "{$path}/{$name}.php"; } protected function saveClass($path, $name, $content, ?string $entityFolder = null): string diff --git a/src/Generators/NovaTestGenerator.php b/src/Generators/NovaTestGenerator.php index 033717f..5e97db1 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -6,7 +6,6 @@ use Laravel\Nova\NovaServiceProvider; use Laravel\Nova\Http\Requests\NovaRequest; use RonasIT\Support\Events\SuccessCreateMessage; -use RonasIT\Support\Exceptions\ClassAlreadyExistsException; use RonasIT\Support\Exceptions\ClassNotExistsException; use RonasIT\Support\Exceptions\EntityCreateException; use Generator; @@ -43,7 +42,6 @@ public function generate(): void } if (empty($novaResources)) { - // TODO: pass $this->modelSubfolder to Exception after refactoring in https://github.com/RonasIT/laravel-entity-generator/issues/179 $this->throwFailureException( ClassNotExistsException::class, "Cannot create Nova{$this->model}ResourceTest cause {$this->model} Nova resource does not exist.", diff --git a/tests/ControllerGeneratorTest.php b/tests/ControllerGeneratorTest.php index e37b358..6c6fa7d 100644 --- a/tests/ControllerGeneratorTest.php +++ b/tests/ControllerGeneratorTest.php @@ -30,7 +30,7 @@ public function testControllerAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostController cause it already exists. Remove vfs://root/app/Http/Controllers/PostController.php and run command again.', + message: 'Cannot create PostController cause it already exists. Remove app/Http/Controllers/PostController.php and run command again.', ); app(ControllerGenerator::class) diff --git a/tests/FactoryGeneratorTest.php b/tests/FactoryGeneratorTest.php index f96dced..60f4617 100644 --- a/tests/FactoryGeneratorTest.php +++ b/tests/FactoryGeneratorTest.php @@ -46,7 +46,7 @@ public function testFactoryClassExists() { $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostFactory cause it already exists. Remove vfs://root/database/factories/PostFactory.php and run command again.', + message: 'Cannot create PostFactory cause it already exists. Remove database/factories/PostFactory.php and run command again.', ); $this->mockFactoryGenerator( diff --git a/tests/ModelGeneratorTest.php b/tests/ModelGeneratorTest.php index 41eaddf..e2326b5 100644 --- a/tests/ModelGeneratorTest.php +++ b/tests/ModelGeneratorTest.php @@ -30,7 +30,7 @@ public function testModelAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create Post cause it already exists. Remove vfs://root/app/Models/Blog/Post.php and run command again.', + message: 'Cannot create Post cause it already exists. Remove app/Models/Blog/Post.php and run command again.', ); app(ModelGenerator::class) diff --git a/tests/NovaResourceGeneratorTest.php b/tests/NovaResourceGeneratorTest.php index d6882d3..4efd66c 100644 --- a/tests/NovaResourceGeneratorTest.php +++ b/tests/NovaResourceGeneratorTest.php @@ -63,7 +63,7 @@ public function testCreateNovaTestAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostResource cause it already exists. Remove vfs://root/app/Nova/PostResource.php and run command again.', + message: 'Cannot create PostResource cause it already exists. Remove app/Nova/PostResource.php and run command again.', ); app(NovaResourceGenerator::class) diff --git a/tests/NovaTestGeneratorTest.php b/tests/NovaTestGeneratorTest.php index 226de1e..84d1b59 100644 --- a/tests/NovaTestGeneratorTest.php +++ b/tests/NovaTestGeneratorTest.php @@ -72,7 +72,7 @@ public function testGenerateNovaTestAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: "Cannot create NovaPostResourceTest cause it already exists. Remove vfs://root/app/Nova/NovaPostResourceTest.php and run command again.", + message: "Cannot create NovaPostResourceTest cause it already exists. Remove app/Nova/NovaPostResourceTest.php and run command again.", ); app(NovaTestGenerator::class) diff --git a/tests/ResourceGeneratorTest.php b/tests/ResourceGeneratorTest.php index 1bb1c78..e5c1e07 100644 --- a/tests/ResourceGeneratorTest.php +++ b/tests/ResourceGeneratorTest.php @@ -20,7 +20,7 @@ public function testResourceAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostResource cause it already exists. Remove vfs://root/app/Http/Resources/PostResource.php and run command again.', + message: 'Cannot create PostResource cause it already exists. Remove app/Http/Resources/PostResource.php and run command again.', ); app(ResourceGenerator::class) @@ -37,7 +37,7 @@ public function testCollectionResourceAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostsCollectionResource cause it already exists. Remove vfs://root/app/Http/Resources/PostsCollectionResource.php and run command again.', + message: 'Cannot create PostsCollectionResource cause it already exists. Remove app/Http/Resources/PostsCollectionResource.php and run command again.', ); app(ResourceGenerator::class)