From ae0b5527f8b1206e768cc31cf8a8a96334d5ef07 Mon Sep 17 00:00:00 2001 From: Konstantin Lapkovsky Date: Thu, 21 Dec 2023 13:53:42 +0400 Subject: [PATCH 01/12] test: add repository generator test skeleton. --- tests/RepositoryGeneratorTest.php | 71 +++++++++++++++++++ .../Repository/RepositoryMockTrait.php | 10 +++ 2 files changed, 81 insertions(+) create mode 100644 tests/RepositoryGeneratorTest.php create mode 100644 tests/Support/Repository/RepositoryMockTrait.php diff --git a/tests/RepositoryGeneratorTest.php b/tests/RepositoryGeneratorTest.php new file mode 100644 index 00000000..5bd69f1b --- /dev/null +++ b/tests/RepositoryGeneratorTest.php @@ -0,0 +1,71 @@ +mockGeneratorForExistingModel(); + + $this->expectException(ClassAlreadyExistsException::class); + $this->expectErrorMessage('Cannot create Post Model cause Post Model already exists. Remove Post Model.'); + + app(ModelGenerator::class) + ->setModel('Post') + ->generate(); + } + + public function testRelationModelMissing() + { + $this->mockGeneratorForMissingRelationModel(); + + $this->expectException(ClassNotExistsException::class); + $this->expectErrorMessage("Cannot create Post Model cause relation model Comment does not exist. " + . "Create the Comment Model by himself or run command 'php artisan make:entity Comment --only-model'."); + + app(ModelGenerator::class) + ->setModel('Post') + ->setRelations([ + 'hasOne' => ['Comment'], + 'hasMany' => [], + 'belongsTo' => [], + 'belongsToMany' => [], + ]) + ->generate(); + } + + public function testCreateModel() + { + $this->setupConfigurations(); + $this->mockViewsNamespace(); + $this->mockFilesystem(); + + app(ModelGenerator::class) + ->setModel('Post') + ->setfields([ + 'integer-required' => ['media_id'], + 'boolean-required' => ['is_published'], + ]) + ->setRelations([ + 'hasOne' => ['Comment'], + 'hasMany' => ['User'], + 'belongsTo' => [], + 'belongsToMany' => [], + ]) + ->generate(); + + $this->rollbackToDefaultBasePath(); + + $this->assertGeneratedFileEquals('new_model.php', 'app/Models/Post.php'); + $this->assertGeneratedFileEquals('comment_relation_model.php', 'app/Models/Comment.php'); + $this->assertGeneratedFileEquals('user_relation_model.php', 'app/Models/User.php'); + } +} diff --git a/tests/Support/Repository/RepositoryMockTrait.php b/tests/Support/Repository/RepositoryMockTrait.php new file mode 100644 index 00000000..262083d8 --- /dev/null +++ b/tests/Support/Repository/RepositoryMockTrait.php @@ -0,0 +1,10 @@ + Date: Thu, 21 Dec 2023 19:15:31 +0400 Subject: [PATCH 02/12] chore: correct tests. --- tests/Support/NovaTest/NovaTestMockTrait.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/Support/NovaTest/NovaTestMockTrait.php b/tests/Support/NovaTest/NovaTestMockTrait.php index a2322556..fd2e71bf 100644 --- a/tests/Support/NovaTest/NovaTestMockTrait.php +++ b/tests/Support/NovaTest/NovaTestMockTrait.php @@ -70,7 +70,17 @@ public function mockTestGeneratorForNonExistingNovaResource(): void $this->mockClass(NovaTestGenerator::class, [ [ 'method' => 'classExists', - 'arguments' => [], + 'arguments' => ['nova', 'PostNovaResource'], + 'result' => false + ], + [ + 'method' => 'classExists', + 'arguments' => ['nova', 'PostResource'], + 'result' => false + ], + [ + 'method' => 'classExists', + 'arguments' => ['nova', 'Post'], 'result' => false ] ]); @@ -81,7 +91,7 @@ public function mockGeneratorForExistingNovaTest(): void $this->mockClass(NovaTestGenerator::class, [ [ 'method' => 'classExists', - 'arguments' => ['nova', 'Post'], + 'arguments' => ['nova', 'PostNovaResource'], 'result' => true ], [ From 6071edaf4d4fbb1668021e9b95d868a13790f405 Mon Sep 17 00:00:00 2001 From: Konstantin Lapkovsky Date: Thu, 21 Dec 2023 20:18:44 +0400 Subject: [PATCH 03/12] test: add tests for repository generator. --- tests/RepositoryGeneratorTest.php | 51 ++++--------------- .../Repository/RepositoryMockTrait.php | 38 ++++++++++++++ .../RepositoryGeneratorTest/repository.php | 17 +++++++ 3 files changed, 65 insertions(+), 41 deletions(-) create mode 100644 tests/fixtures/RepositoryGeneratorTest/repository.php diff --git a/tests/RepositoryGeneratorTest.php b/tests/RepositoryGeneratorTest.php index 5bd69f1b..2cadf493 100644 --- a/tests/RepositoryGeneratorTest.php +++ b/tests/RepositoryGeneratorTest.php @@ -2,70 +2,39 @@ namespace RonasIT\Support\Tests; -use RonasIT\Support\Exceptions\ClassAlreadyExistsException; use RonasIT\Support\Exceptions\ClassNotExistsException; -use RonasIT\Support\Generators\ModelGenerator; +use RonasIT\Support\Generators\RepositoryGenerator; use RonasIT\Support\Tests\Support\Repository\RepositoryMockTrait; class RepositoryGeneratorTest extends TestCase { use RepositoryMockTrait; - public function testModelAlreadyExists() + public function testModelDoesntExists() { - $this->mockGeneratorForExistingModel(); - - $this->expectException(ClassAlreadyExistsException::class); - $this->expectErrorMessage('Cannot create Post Model cause Post Model already exists. Remove Post Model.'); - - app(ModelGenerator::class) - ->setModel('Post') - ->generate(); - } - - public function testRelationModelMissing() - { - $this->mockGeneratorForMissingRelationModel(); + $this->mockGeneratorForMissingModel(); $this->expectException(ClassNotExistsException::class); - $this->expectErrorMessage("Cannot create Post Model cause relation model Comment does not exist. " - . "Create the Comment Model by himself or run command 'php artisan make:entity Comment --only-model'."); + $this->expectErrorMessage("Cannot create Post Model cause Post Model does not exists. " + . "Create a Post Model by himself or run command 'php artisan make:entity Post --only-model'."); - app(ModelGenerator::class) + app(RepositoryGenerator::class) ->setModel('Post') - ->setRelations([ - 'hasOne' => ['Comment'], - 'hasMany' => [], - 'belongsTo' => [], - 'belongsToMany' => [], - ]) ->generate(); } - public function testCreateModel() + public function testCreateRepository() { - $this->setupConfigurations(); + $this->mockConfigurations(); $this->mockViewsNamespace(); $this->mockFilesystem(); - app(ModelGenerator::class) + app(RepositoryGenerator::class) ->setModel('Post') - ->setfields([ - 'integer-required' => ['media_id'], - 'boolean-required' => ['is_published'], - ]) - ->setRelations([ - 'hasOne' => ['Comment'], - 'hasMany' => ['User'], - 'belongsTo' => [], - 'belongsToMany' => [], - ]) ->generate(); $this->rollbackToDefaultBasePath(); - $this->assertGeneratedFileEquals('new_model.php', 'app/Models/Post.php'); - $this->assertGeneratedFileEquals('comment_relation_model.php', 'app/Models/Comment.php'); - $this->assertGeneratedFileEquals('user_relation_model.php', 'app/Models/User.php'); + $this->assertGeneratedFileEquals('repository.php', 'app/Repositories/PostRepository.php'); } } diff --git a/tests/Support/Repository/RepositoryMockTrait.php b/tests/Support/Repository/RepositoryMockTrait.php index 262083d8..aa1b6114 100644 --- a/tests/Support/Repository/RepositoryMockTrait.php +++ b/tests/Support/Repository/RepositoryMockTrait.php @@ -2,9 +2,47 @@ namespace RonasIT\Support\Tests\Support\Repository; +use org\bovigo\vfs\vfsStream; +use RonasIT\Support\Generators\RepositoryGenerator; use RonasIT\Support\Tests\Support\Shared\GeneratorMockTrait; trait RepositoryMockTrait { use GeneratorMockTrait; + + public function mockGeneratorForMissingModel(): void + { + $this->mockClass(RepositoryGenerator::class, [ + [ + 'method' => 'classExists', + 'arguments' => ['models', 'Post'], + 'result' => false + ], + ]); + } + + public function mockConfigurations(): void + { + config([ + 'entity-generator.stubs.repository' => 'entity-generator::repository', + 'entity-generator.paths' => [ + 'repositories' => 'app/Repositories', + 'models' => 'app/Models', + ] + ]); + } + + public function mockFilesystem(): void + { + $structure = [ + 'app' => [ + 'Models' => [ + 'Post.php' => ' [] + ], + ]; + + vfsStream::create($structure); + } } diff --git a/tests/fixtures/RepositoryGeneratorTest/repository.php b/tests/fixtures/RepositoryGeneratorTest/repository.php new file mode 100644 index 00000000..1e635191 --- /dev/null +++ b/tests/fixtures/RepositoryGeneratorTest/repository.php @@ -0,0 +1,17 @@ +setModel(Post::class); + } +} From f7f1b134c4b2883c8b93385aecd9771b8c734408 Mon Sep 17 00:00:00 2001 From: Konstantin Lapkovsky Date: Thu, 21 Dec 2023 20:23:45 +0400 Subject: [PATCH 04/12] chore: remove fixture export. --- tests/FactoryGeneratorTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/FactoryGeneratorTest.php b/tests/FactoryGeneratorTest.php index 701877a0..60cd1d4f 100644 --- a/tests/FactoryGeneratorTest.php +++ b/tests/FactoryGeneratorTest.php @@ -160,7 +160,7 @@ public function testCreateGenericFactory() $this->rollbackToDefaultBasePath(); - $this->assertGeneratedFileEquals('model_factory.php', '/database/factories/ModelFactory.php', true); + $this->assertGeneratedFileEquals('model_factory.php', '/database/factories/ModelFactory.php'); } public function testProcessUnknownFieldType() @@ -212,6 +212,6 @@ public function testCreateClassStyleFactory() $this->rollbackToDefaultBasePath(); - $this->assertGeneratedFileEquals('post_factory.php', '/database/factories/PostFactory.php', true); + $this->assertGeneratedFileEquals('post_factory.php', '/database/factories/PostFactory.php'); } } From 694ee923257eb3dd96923e3e7175998c9f5363e1 Mon Sep 17 00:00:00 2001 From: roman Date: Tue, 17 Dec 2024 17:37:18 +0600 Subject: [PATCH 05/12] refactor: tests refs: https://github.com/RonasIT/laravel-entity-generator/issues/49 --- tests/ModelGeneratorTest.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/ModelGeneratorTest.php b/tests/ModelGeneratorTest.php index 35a3c9fe..3a745404 100644 --- a/tests/ModelGeneratorTest.php +++ b/tests/ModelGeneratorTest.php @@ -16,8 +16,10 @@ public function testModelAlreadyExists() { $this->mockGeneratorForExistingModel(); - $this->expectException(ClassAlreadyExistsException::class); - $this->expectExceptionMessage('Cannot create Post Model cause Post Model already exists. Remove Post Model.'); + $this->assertExceptionThrew( + className: ClassAlreadyExistsException::class, + message: 'Cannot create Post Model cause Post Model already exists. Remove Post Model.', + ); app(ModelGenerator::class) ->setModel('Post') @@ -26,9 +28,11 @@ public function testModelAlreadyExists() public function testRelationModelMissing() { - $this->expectException(ClassNotExistsException::class); - $this->expectExceptionMessage("Cannot create Post Model cause relation model Comment does not exist. " - . "Create the Comment Model by himself or run command 'php artisan make:entity Comment --only-model'."); + $this->assertExceptionThrew( + className: ClassNotExistsException::class, + message: "Cannot create Post Model cause relation model Comment does not exist. " + . "Create the Comment Model by himself or run command 'php artisan make:entity Comment --only-model'.", + ); app(ModelGenerator::class) ->setModel('Post') From fec7db29bb94e99e0f89cb5cdf7243626fb87e79 Mon Sep 17 00:00:00 2001 From: roman Date: Wed, 18 Dec 2024 10:36:10 +0600 Subject: [PATCH 06/12] refactor: remove useless classes refs: https://github.com/RonasIT/laravel-entity-generator/issues/49 --- tests/Support/NovaResource/NovaResourceMockTrait.php | 0 tests/Support/NovaTest/NovaTestMockTrait.php | 0 tests/Support/Shared/GeneratorMockTrait.php | 0 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/Support/NovaResource/NovaResourceMockTrait.php delete mode 100644 tests/Support/NovaTest/NovaTestMockTrait.php delete mode 100644 tests/Support/Shared/GeneratorMockTrait.php diff --git a/tests/Support/NovaResource/NovaResourceMockTrait.php b/tests/Support/NovaResource/NovaResourceMockTrait.php deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/Support/NovaTest/NovaTestMockTrait.php b/tests/Support/NovaTest/NovaTestMockTrait.php deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/Support/Shared/GeneratorMockTrait.php b/tests/Support/Shared/GeneratorMockTrait.php deleted file mode 100644 index e69de29b..00000000 From 3f66a2fcb089ec930ceaa3f7648da3a57edcf280 Mon Sep 17 00:00:00 2001 From: roman Date: Wed, 18 Dec 2024 12:20:23 +0600 Subject: [PATCH 07/12] feat: change tests refs: https://github.com/RonasIT/laravel-entity-generator/issues/49 --- tests/RepositoryGeneratorTest.php | 12 ++++----- .../Repository/RepositoryMockTrait.php | 26 +++++-------------- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/tests/RepositoryGeneratorTest.php b/tests/RepositoryGeneratorTest.php index 2cadf493..bc39ad74 100644 --- a/tests/RepositoryGeneratorTest.php +++ b/tests/RepositoryGeneratorTest.php @@ -14,9 +14,11 @@ public function testModelDoesntExists() { $this->mockGeneratorForMissingModel(); - $this->expectException(ClassNotExistsException::class); - $this->expectErrorMessage("Cannot create Post Model cause Post Model does not exists. " - . "Create a Post Model by himself or run command 'php artisan make:entity Post --only-model'."); + $this->assertExceptionThrew( + className: ClassNotExistsException::class, + message: "Cannot create Post Model cause Post Model does not exists. " + . "Create a Post Model by himself or run command 'php artisan make:entity Post --only-model'.", + ); app(RepositoryGenerator::class) ->setModel('Post') @@ -25,16 +27,12 @@ public function testModelDoesntExists() public function testCreateRepository() { - $this->mockConfigurations(); - $this->mockViewsNamespace(); $this->mockFilesystem(); app(RepositoryGenerator::class) ->setModel('Post') ->generate(); - $this->rollbackToDefaultBasePath(); - $this->assertGeneratedFileEquals('repository.php', 'app/Repositories/PostRepository.php'); } } diff --git a/tests/Support/Repository/RepositoryMockTrait.php b/tests/Support/Repository/RepositoryMockTrait.php index aa1b6114..63113a9e 100644 --- a/tests/Support/Repository/RepositoryMockTrait.php +++ b/tests/Support/Repository/RepositoryMockTrait.php @@ -4,31 +4,17 @@ use org\bovigo\vfs\vfsStream; use RonasIT\Support\Generators\RepositoryGenerator; -use RonasIT\Support\Tests\Support\Shared\GeneratorMockTrait; +use RonasIT\Support\Tests\Support\GeneratorMockTrait; +use RonasIT\Support\Traits\MockTrait; trait RepositoryMockTrait { - use GeneratorMockTrait; + use GeneratorMockTrait, MockTrait; public function mockGeneratorForMissingModel(): void { $this->mockClass(RepositoryGenerator::class, [ - [ - 'method' => 'classExists', - 'arguments' => ['models', 'Post'], - 'result' => false - ], - ]); - } - - public function mockConfigurations(): void - { - config([ - 'entity-generator.stubs.repository' => 'entity-generator::repository', - 'entity-generator.paths' => [ - 'repositories' => 'app/Repositories', - 'models' => 'app/Models', - ] + $this->classExistsMethodCall(['models', 'Post'], false), ]); } @@ -37,9 +23,9 @@ public function mockFilesystem(): void $structure = [ 'app' => [ 'Models' => [ - 'Post.php' => ' ' [] + 'Repositories' => [], ], ]; From 8a4cd74eb95d0af8b45edb47d1591a0b80530618 Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 19 Dec 2024 18:34:03 +0600 Subject: [PATCH 08/12] refactor: code refs: https://github.com/RonasIT/laravel-entity-generator/issues/49 --- tests/Support/NovaTest/NovaTestMockTrait.php | 145 ------------------- 1 file changed, 145 deletions(-) delete mode 100644 tests/Support/NovaTest/NovaTestMockTrait.php diff --git a/tests/Support/NovaTest/NovaTestMockTrait.php b/tests/Support/NovaTest/NovaTestMockTrait.php deleted file mode 100644 index fd2e71bf..00000000 --- a/tests/Support/NovaTest/NovaTestMockTrait.php +++ /dev/null @@ -1,145 +0,0 @@ -mockClass(NovaTestGenerator::class, [ - [ - 'method' => 'getModelFields', - 'arguments' => ['Post'], - 'result' => ['title', 'name'] - ], - [ - 'method' => 'getModelFields', - 'arguments' => ['Post'], - 'result' => ['title', 'name'] - ], - [ - 'method' => 'getModelFields', - 'arguments' => ['Post'], - 'result' => ['title', 'name'] - ], - [ - 'method' => 'getMockModel', - 'arguments' => ['Post'], - 'result' => ['title' => 'some title', 'name' => 'some name'] - ], - [ - 'method' => 'getMockModel', - 'arguments' => ['Post'], - 'result' => ['title' => 'some title', 'name' => 'some name'] - ], - [ - 'method' => 'loadNovaActions', - 'arguments' => [], - 'result' => [ - new PublishPostAction, - new UnPublishPostAction, - new UnPublishPostAction, - ] - ], - [ - 'method' => 'loadNovaFields', - 'arguments' => [], - 'result' => [ - new TextField, - new DateField, - ] - ], - [ - 'method' => 'loadNovaFilters', - 'arguments' => [], - 'result' => [ - new CreatedAtFilter, - ] - ], - ]); - } - - public function mockTestGeneratorForNonExistingNovaResource(): void - { - $this->mockClass(NovaTestGenerator::class, [ - [ - 'method' => 'classExists', - 'arguments' => ['nova', 'PostNovaResource'], - 'result' => false - ], - [ - 'method' => 'classExists', - 'arguments' => ['nova', 'PostResource'], - 'result' => false - ], - [ - 'method' => 'classExists', - 'arguments' => ['nova', 'Post'], - 'result' => false - ] - ]); - } - - public function mockGeneratorForExistingNovaTest(): void - { - $this->mockClass(NovaTestGenerator::class, [ - [ - 'method' => 'classExists', - 'arguments' => ['nova', 'PostNovaResource'], - 'result' => true - ], - [ - 'method' => 'classExists', - 'arguments' => ['nova', 'NovaPostTest'], - 'result' => true - ] - ]); - } - - public function setupConfigurations(): void - { - config([ - 'entity-generator.stubs.nova_test' => 'entity-generator::nova_test', - 'entity-generator.stubs.dump' => 'entity-generator::dumps.pgsql', - 'entity-generator.paths' => [ - 'nova' => 'app/Nova', - 'nova_actions' => 'app/Nova/Actions', - 'tests' => 'tests', - 'models' => 'app/Models' - ] - ]); - } - - public function mockFilesystem(): void - { - $structure = [ - 'app' => [ - 'Nova' => [ - 'Actions' => [ - 'PublishPostAction.php' => ' ' ' 'text', - ], - 'Post.php' => ' [ - 'Post.php' => ' [ - 'fixtures' => [ - 'NovaPostTest' => [] - ] - ] - ]; - - vfsStream::create($structure); - } -} \ No newline at end of file From 87cc3b79a791038cc41714c2aa674e14be04b79a Mon Sep 17 00:00:00 2001 From: roman Date: Fri, 10 Jan 2025 17:17:35 +0600 Subject: [PATCH 09/12] fix: conflicts refs: https://github.com/RonasIT/laravel-entity-generator/issues/49 --- tests/fixtures/ModelGeneratorTest/new_model.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/fixtures/ModelGeneratorTest/new_model.php b/tests/fixtures/ModelGeneratorTest/new_model.php index 94a1064b..4aa5bb05 100644 --- a/tests/fixtures/ModelGeneratorTest/new_model.php +++ b/tests/fixtures/ModelGeneratorTest/new_model.php @@ -2,13 +2,12 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use RonasIT\Support\Traits\ModelTrait; class Post extends Model { - use HasFactory, ModelTrait; + use ModelTrait; protected $fillable = [ 'media_id', From 97931b2c15f5d5c0ce3a5660d059b1a6722e453a Mon Sep 17 00:00:00 2001 From: roman Date: Fri, 10 Jan 2025 21:21:16 +0600 Subject: [PATCH 10/12] feat: add tests refs: https://github.com/RonasIT/laravel-entity-generator/issues/49 --- tests/RepositoryGeneratorTest.php | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/RepositoryGeneratorTest.php b/tests/RepositoryGeneratorTest.php index bc39ad74..dfbdf527 100644 --- a/tests/RepositoryGeneratorTest.php +++ b/tests/RepositoryGeneratorTest.php @@ -2,6 +2,9 @@ namespace RonasIT\Support\Tests; +use Illuminate\Support\Facades\Event; +use RonasIT\Support\Events\SuccessCreateMessage; +use RonasIT\Support\Events\WarningEvent; use RonasIT\Support\Exceptions\ClassNotExistsException; use RonasIT\Support\Generators\RepositoryGenerator; use RonasIT\Support\Tests\Support\Repository\RepositoryMockTrait; @@ -10,6 +13,13 @@ class RepositoryGeneratorTest extends TestCase { use RepositoryMockTrait; + public function setUp(): void + { + parent::setUp(); + + Event::fake(); + } + public function testModelDoesntExists() { $this->mockGeneratorForMissingModel(); @@ -23,6 +33,8 @@ className: ClassNotExistsException::class, app(RepositoryGenerator::class) ->setModel('Post') ->generate(); + + $this->assertFileDoesNotExist('repository.php', 'app/Repositories/PostRepository.php'); } public function testCreateRepository() @@ -34,5 +46,28 @@ public function testCreateRepository() ->generate(); $this->assertGeneratedFileEquals('repository.php', 'app/Repositories/PostRepository.php'); + + $this->assertEventPushed( + className: SuccessCreateMessage::class, + message: 'Created a new Repository: PostRepository', + ); + } + + public function testCreateRepositoryStubNotExist() + { + config(['entity-generator.stubs.repository' => 'incorrect_stub']); + + $this->mockFilesystem(); + + app(RepositoryGenerator::class) + ->setModel('Post') + ->generate(); + + $this->assertFileDoesNotExist('repository.php', 'app/Repositories/PostRepository.php'); + + $this->assertEventPushed( + className: WarningEvent::class, + message: 'Generation of repository has been skipped cause the view incorrect_stub from the config entity-generator.stubs.repository is not exists. Please check that config has the correct view name value.', + ); } } From c0e714bdf0967cfec6e56e59057b5e6f2e4dc009 Mon Sep 17 00:00:00 2001 From: roman Date: Fri, 10 Jan 2025 22:40:56 +0600 Subject: [PATCH 11/12] refactor: code refs: https://github.com/RonasIT/laravel-entity-generator/issues/49 --- tests/RepositoryGeneratorTest.php | 14 ++++---------- tests/Support/Repository/RepositoryMockTrait.php | 8 -------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/tests/RepositoryGeneratorTest.php b/tests/RepositoryGeneratorTest.php index dfbdf527..c9229c98 100644 --- a/tests/RepositoryGeneratorTest.php +++ b/tests/RepositoryGeneratorTest.php @@ -2,7 +2,6 @@ namespace RonasIT\Support\Tests; -use Illuminate\Support\Facades\Event; use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Events\WarningEvent; use RonasIT\Support\Exceptions\ClassNotExistsException; @@ -13,16 +12,11 @@ class RepositoryGeneratorTest extends TestCase { use RepositoryMockTrait; - public function setUp(): void + public function testModelNotExist() { - parent::setUp(); - - Event::fake(); - } - - public function testModelDoesntExists() - { - $this->mockGeneratorForMissingModel(); + $this->mockClass(RepositoryGenerator::class, [ + $this->classExistsMethodCall(['models', 'Post'], false), + ]); $this->assertExceptionThrew( className: ClassNotExistsException::class, diff --git a/tests/Support/Repository/RepositoryMockTrait.php b/tests/Support/Repository/RepositoryMockTrait.php index 63113a9e..95d20eb8 100644 --- a/tests/Support/Repository/RepositoryMockTrait.php +++ b/tests/Support/Repository/RepositoryMockTrait.php @@ -3,7 +3,6 @@ namespace RonasIT\Support\Tests\Support\Repository; use org\bovigo\vfs\vfsStream; -use RonasIT\Support\Generators\RepositoryGenerator; use RonasIT\Support\Tests\Support\GeneratorMockTrait; use RonasIT\Support\Traits\MockTrait; @@ -11,13 +10,6 @@ trait RepositoryMockTrait { use GeneratorMockTrait, MockTrait; - public function mockGeneratorForMissingModel(): void - { - $this->mockClass(RepositoryGenerator::class, [ - $this->classExistsMethodCall(['models', 'Post'], false), - ]); - } - public function mockFilesystem(): void { $structure = [ From 40fdcb29a76afe5f2073dcaea3a348cfa2ccf395 Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 16 Jan 2025 11:16:19 +0600 Subject: [PATCH 12/12] refactor: tests refs: https://github.com/RonasIT/laravel-entity-generator/issues/49 --- src/Generators/RepositoryGenerator.php | 2 +- tests/RepositoryGeneratorTest.php | 2 +- .../Support/Repository/RepositoryMockTrait.php | 18 +++++++----------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Generators/RepositoryGenerator.php b/src/Generators/RepositoryGenerator.php index a046397f..b20b3871 100644 --- a/src/Generators/RepositoryGenerator.php +++ b/src/Generators/RepositoryGenerator.php @@ -12,7 +12,7 @@ public function generate(): void if (!$this->classExists('models', $this->model)) { $this->throwFailureException( ClassNotExistsException::class, - "Cannot create {$this->model} Model cause {$this->model} Model does not exists.", + "Cannot create {$this->model}Repository cause {$this->model} Model does not exists.", "Create a {$this->model} Model by himself or run command 'php artisan make:entity {$this->model} --only-model'." ); } diff --git a/tests/RepositoryGeneratorTest.php b/tests/RepositoryGeneratorTest.php index c9229c98..14cb0452 100644 --- a/tests/RepositoryGeneratorTest.php +++ b/tests/RepositoryGeneratorTest.php @@ -20,7 +20,7 @@ public function testModelNotExist() $this->assertExceptionThrew( className: ClassNotExistsException::class, - message: "Cannot create Post Model cause Post Model does not exists. " + message: "Cannot create PostRepository cause Post Model does not exists. " . "Create a Post Model by himself or run command 'php artisan make:entity Post --only-model'.", ); diff --git a/tests/Support/Repository/RepositoryMockTrait.php b/tests/Support/Repository/RepositoryMockTrait.php index 95d20eb8..9438cfd4 100644 --- a/tests/Support/Repository/RepositoryMockTrait.php +++ b/tests/Support/Repository/RepositoryMockTrait.php @@ -2,25 +2,21 @@ namespace RonasIT\Support\Tests\Support\Repository; -use org\bovigo\vfs\vfsStream; +use RonasIT\Support\Tests\Support\FileSystemMock; use RonasIT\Support\Tests\Support\GeneratorMockTrait; -use RonasIT\Support\Traits\MockTrait; trait RepositoryMockTrait { - use GeneratorMockTrait, MockTrait; + use GeneratorMockTrait; public function mockFilesystem(): void { - $structure = [ - 'app' => [ - 'Models' => [ - 'Post.php' => ' [], - ], + $fileSystemMock = new FileSystemMock; + + $fileSystemMock->models = [ + 'Post.php' => $this->mockPhpFileContent(), ]; - vfsStream::create($structure); + $fileSystemMock->setStructure(); } }