From 8c7116b39f8928c5a51835f248fbf237c28d4bc1 Mon Sep 17 00:00:00 2001 From: Konstantin Lapkovsky Date: Wed, 20 Dec 2023 23:14:21 +0400 Subject: [PATCH 01/15] test: add model generation test. --- src/Generators/ModelGenerator.php | 6 +- stubs/relation.blade.php | 2 +- tests/ControllerGeneratorTest.php | 12 ---- tests/FactoryGeneratorTest.php | 12 ---- tests/MigrationGeneratorTest.php | 12 ---- tests/ModelGeneratorTest.php | 71 +++++++++++++++++++ tests/NovaResourceGeneratorTest.php | 12 ---- tests/NovaTestGeneratorTest.php | 12 ---- .../Controller/ControllerMockTrait.php | 3 +- tests/Support/Factory/FactoryMockTrait.php | 3 +- tests/Support/Model/ModelMockTrait.php | 64 +++++++++++++++++ tests/Support/Model/RelationModelMock.php | 11 +++ .../NovaResource/NovaResourceMockTrait.php | 3 +- tests/Support/NovaTest/NovaTestMockTrait.php | 3 +- tests/Support/Shared/GeneratorMockTrait.php | 3 + tests/TestCase.php | 12 ++++ .../comment_relation_model.php | 16 +++++ .../fixtures/ModelGeneratorTest/new_model.php | 31 ++++++++ .../user_relation_model.php | 16 +++++ 19 files changed, 232 insertions(+), 72 deletions(-) create mode 100644 tests/ModelGeneratorTest.php create mode 100644 tests/Support/Model/ModelMockTrait.php create mode 100644 tests/Support/Model/RelationModelMock.php create mode 100644 tests/fixtures/ModelGeneratorTest/comment_relation_model.php create mode 100644 tests/fixtures/ModelGeneratorTest/new_model.php create mode 100644 tests/fixtures/ModelGeneratorTest/user_relation_model.php diff --git a/src/Generators/ModelGenerator.php b/src/Generators/ModelGenerator.php index 2de0708..c8c49fc 100644 --- a/src/Generators/ModelGenerator.php +++ b/src/Generators/ModelGenerator.php @@ -58,8 +58,8 @@ public function prepareRelatedModels(): void if (!$this->classExists('models', $relation)) { $this->throwFailureException( ClassNotExistsException::class, - "Cannot create {$relation} Model cause {$relation} Model does not exists.", - "Create a {$relation} Model by himself or run command 'php artisan make:entity {$relation} --only-model'." + "Cannot create {$this->model} Model cause relation model {$relation} does not exist.", + "Create the {$relation} Model by himself or run command 'php artisan make:entity {$relation} --only-model'." ); } @@ -115,7 +115,7 @@ protected function getCasts($fields): array $result = []; foreach ($fields as $fieldType => $names) { - if (empty($casts[$fieldType])) { + if (!array_key_exists($fieldType, $casts)) { continue; } diff --git a/stubs/relation.blade.php b/stubs/relation.blade.php index 72fec66..7ad7c40 100644 --- a/stubs/relation.blade.php +++ b/stubs/relation.blade.php @@ -1,4 +1,4 @@ public function {{$name}}() { return $this->{{$type}}({{$entity}}::class); - } + } \ No newline at end of file diff --git a/tests/ControllerGeneratorTest.php b/tests/ControllerGeneratorTest.php index ca0bf9c..cdbe876 100644 --- a/tests/ControllerGeneratorTest.php +++ b/tests/ControllerGeneratorTest.php @@ -3,7 +3,6 @@ namespace RonasIT\Support\Tests; use Illuminate\Contracts\Filesystem\FileNotFoundException; -use org\bovigo\vfs\vfsStream; use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Exceptions\ClassAlreadyExistsException; use RonasIT\Support\Exceptions\ClassNotExistsException; @@ -14,17 +13,6 @@ class ControllerGeneratorTest extends TestCase { use ControllerMockTrait; - public function setUp(): void - { - parent::setUp(); - - vfsStream::setup(); - - $this->generatedFileBasePath = vfsStream::url('root'); - - $this->app->setBasePath($this->generatedFileBasePath); - } - public function testControllerAlreadyExists() { $this->getFiredEvents([SuccessCreateMessage::class]); diff --git a/tests/FactoryGeneratorTest.php b/tests/FactoryGeneratorTest.php index bcc56b6..701877a 100644 --- a/tests/FactoryGeneratorTest.php +++ b/tests/FactoryGeneratorTest.php @@ -3,7 +3,6 @@ namespace RonasIT\Support\Tests; use Illuminate\View\ViewException; -use org\bovigo\vfs\vfsStream; use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Exceptions\ClassAlreadyExistsException; use RonasIT\Support\Exceptions\ClassNotExistsException; @@ -16,17 +15,6 @@ class FactoryGeneratorTest extends TestCase { use FactoryMockTrait; - public function setUp(): void - { - parent::setUp(); - - vfsStream::setup(); - - $this->generatedFileBasePath = vfsStream::url('root'); - - $this->app->setBasePath($this->generatedFileBasePath); - } - public function testModelNotExists() { $this->getFiredEvents([SuccessCreateMessage::class]); diff --git a/tests/MigrationGeneratorTest.php b/tests/MigrationGeneratorTest.php index de33a53..42990e5 100644 --- a/tests/MigrationGeneratorTest.php +++ b/tests/MigrationGeneratorTest.php @@ -3,7 +3,6 @@ namespace RonasIT\Support\Tests; use Illuminate\Support\Carbon; -use org\bovigo\vfs\vfsStream; use ReflectionClass; use RonasIT\Support\Exceptions\UnknownFieldTypeException; use RonasIT\Support\Generators\MigrationGenerator; @@ -13,17 +12,6 @@ class MigrationGeneratorTest extends TestCase { use MigrationMockTrait; - public function setUp(): void - { - parent::setUp(); - - vfsStream::setup(); - - $this->generatedFileBasePath = vfsStream::url('root'); - - $this->app->setBasePath($this->generatedFileBasePath); - } - public function testSetUnknownFieldType() { $this->mockViewsNamespace(); diff --git a/tests/ModelGeneratorTest.php b/tests/ModelGeneratorTest.php new file mode 100644 index 0000000..76b6340 --- /dev/null +++ b/tests/ModelGeneratorTest.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/NovaResourceGeneratorTest.php b/tests/NovaResourceGeneratorTest.php index a6f16ae..9999d59 100644 --- a/tests/NovaResourceGeneratorTest.php +++ b/tests/NovaResourceGeneratorTest.php @@ -6,7 +6,6 @@ use Doctrine\DBAL\Types\DateTimeType; use Doctrine\DBAL\Types\IntegerType; use Doctrine\DBAL\Types\StringType; -use org\bovigo\vfs\vfsStream; use ReflectionClass; use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Exceptions\ClassAlreadyExistsException; @@ -19,17 +18,6 @@ class NovaResourceGeneratorTest extends TestCase { use NovaResourceMockTrait; - public function setUp(): void - { - parent::setUp(); - - vfsStream::setup(); - - $this->generatedFileBasePath = vfsStream::url('root'); - - $this->app->setBasePath($this->generatedFileBasePath); - } - public function testCreateWithMissingNovaPackage() { $this->expectsEvents([SuccessCreateMessage::class]); diff --git a/tests/NovaTestGeneratorTest.php b/tests/NovaTestGeneratorTest.php index 0c0712f..1edc48b 100644 --- a/tests/NovaTestGeneratorTest.php +++ b/tests/NovaTestGeneratorTest.php @@ -2,7 +2,6 @@ namespace RonasIT\Support\Tests; -use org\bovigo\vfs\vfsStream; use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Exceptions\ClassAlreadyExistsException; use RonasIT\Support\Exceptions\ClassNotExistsException; @@ -13,17 +12,6 @@ class NovaTestGeneratorTest extends TestCase { use NovaTestMockTrait; - public function setUp(): void - { - parent::setUp(); - - vfsStream::setup(); - - $this->generatedFileBasePath = vfsStream::url('root'); - - $this->app->setBasePath($this->generatedFileBasePath); - } - public function testCreateNovaTestsResourceNotExists() { $mock = $this->mockClassExistsFunction(); diff --git a/tests/Support/Controller/ControllerMockTrait.php b/tests/Support/Controller/ControllerMockTrait.php index 7a22ae0..0542665 100644 --- a/tests/Support/Controller/ControllerMockTrait.php +++ b/tests/Support/Controller/ControllerMockTrait.php @@ -5,11 +5,10 @@ use org\bovigo\vfs\vfsStream; use RonasIT\Support\Generators\ControllerGenerator; use RonasIT\Support\Tests\Support\Shared\GeneratorMockTrait; -use RonasIT\Support\Traits\MockClassTrait; trait ControllerMockTrait { - use GeneratorMockTrait, MockClassTrait; + use GeneratorMockTrait; public function mockControllerGeneratorForExistingController(): void { diff --git a/tests/Support/Factory/FactoryMockTrait.php b/tests/Support/Factory/FactoryMockTrait.php index 32e170d..ede9f70 100644 --- a/tests/Support/Factory/FactoryMockTrait.php +++ b/tests/Support/Factory/FactoryMockTrait.php @@ -6,11 +6,10 @@ use ReflectionClass; use RonasIT\Support\Generators\FactoryGenerator; use RonasIT\Support\Tests\Support\Shared\GeneratorMockTrait; -use RonasIT\Support\Traits\MockClassTrait; trait FactoryMockTrait { - use GeneratorMockTrait, MockClassTrait; + use GeneratorMockTrait; public function getFactoryGeneratorMockForMissingModel(): void { diff --git a/tests/Support/Model/ModelMockTrait.php b/tests/Support/Model/ModelMockTrait.php new file mode 100644 index 0000000..bfddb97 --- /dev/null +++ b/tests/Support/Model/ModelMockTrait.php @@ -0,0 +1,64 @@ +mockClass(ModelGenerator::class, [ + [ + 'method' => 'classExists', + 'arguments' => ['models', 'Post'], + 'result' => true + ] + ]); + } + + public function mockGeneratorForMissingRelationModel() + { + $this->mockClass(ModelGenerator::class, [ + [ + 'method' => 'classExists', + 'arguments' => ['models', 'Post'], + 'result' => false + ], + [ + 'method' => 'classExists', + 'arguments' => ['models', 'Comment'], + 'result' => false + ] + ]); + } + + public function setupConfigurations(): void + { + config([ + 'entity-generator.stubs.model' => 'entity-generator::model', + 'entity-generator.stubs.relation' => 'entity-generator::relation', + 'entity-generator.paths' => [ + 'models' => 'app/Models', + ] + ]); + } + + public function mockFilesystem(): void + { + $structure = [ + 'app' => [ + 'Models' => [ + 'Comment.php' => file_get_contents(getcwd() . '/tests/Support/Model/RelationModelMock.php'), + 'User.php' => file_get_contents(getcwd() . '/tests/Support/Model/RelationModelMock.php') + ] + ], + ]; + + vfsStream::create($structure); + } +} diff --git a/tests/Support/Model/RelationModelMock.php b/tests/Support/Model/RelationModelMock.php new file mode 100644 index 0000000..f8cf9a4 --- /dev/null +++ b/tests/Support/Model/RelationModelMock.php @@ -0,0 +1,11 @@ +getMockBuilder($className); diff --git a/tests/TestCase.php b/tests/TestCase.php index 75530d1..a262382 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,6 +6,7 @@ use Illuminate\Foundation\Testing\Concerns\InteractsWithViews; use Illuminate\Support\Str; use Orchestra\Testbench\TestCase as BaseTestCase; +use org\bovigo\vfs\vfsStream; use phpmock\Mock; use RonasIT\Support\Traits\FixturesTrait; @@ -16,6 +17,17 @@ class TestCase extends BaseTestCase protected $globalExportMode = false; protected $generatedFileBasePath; + public function setUp(): void + { + parent::setUp(); + + vfsStream::setup(); + + $this->generatedFileBasePath = vfsStream::url('root'); + + $this->app->setBasePath($this->generatedFileBasePath); + } + public function tearDown(): void { parent::tearDown(); diff --git a/tests/fixtures/ModelGeneratorTest/comment_relation_model.php b/tests/fixtures/ModelGeneratorTest/comment_relation_model.php new file mode 100644 index 0000000..da86050 --- /dev/null +++ b/tests/fixtures/ModelGeneratorTest/comment_relation_model.php @@ -0,0 +1,16 @@ +belongsTo(Post::class); + } +} diff --git a/tests/fixtures/ModelGeneratorTest/new_model.php b/tests/fixtures/ModelGeneratorTest/new_model.php new file mode 100644 index 0000000..c62efef --- /dev/null +++ b/tests/fixtures/ModelGeneratorTest/new_model.php @@ -0,0 +1,31 @@ +hasOne(Comment::class); + } + public function users() + { + return $this->hasMany(User::class); + } + protected $casts = [ + 'is_published' => 'boolean', + ]; +} \ No newline at end of file diff --git a/tests/fixtures/ModelGeneratorTest/user_relation_model.php b/tests/fixtures/ModelGeneratorTest/user_relation_model.php new file mode 100644 index 0000000..da86050 --- /dev/null +++ b/tests/fixtures/ModelGeneratorTest/user_relation_model.php @@ -0,0 +1,16 @@ +belongsTo(Post::class); + } +} From ae0b5527f8b1206e768cc31cf8a8a96334d5ef07 Mon Sep 17 00:00:00 2001 From: Konstantin Lapkovsky Date: Thu, 21 Dec 2023 13:53:42 +0400 Subject: [PATCH 02/15] 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 0000000..5bd69f1 --- /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 0000000..262083d --- /dev/null +++ b/tests/Support/Repository/RepositoryMockTrait.php @@ -0,0 +1,10 @@ + Date: Thu, 21 Dec 2023 19:15:31 +0400 Subject: [PATCH 03/15] 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 a232255..fd2e71b 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 04/15] 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 5bd69f1..2cadf49 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 262083d..aa1b611 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 0000000..1e63519 --- /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 05/15] 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 701877a..60cd1d4 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 d2e27c04163ba7c10f913e823e2468cf43451c14 Mon Sep 17 00:00:00 2001 From: Anton Zabolotnikov Date: Wed, 20 Nov 2024 16:21:27 +0500 Subject: [PATCH 06/15] chore: add migration generator tests --- src/Generators/ModelGenerator.php | 24 +++++++++---------- tests/ModelGeneratorTest.php | 12 ++++------ tests/Support/Model/ModelMockTrait.php | 8 +++---- .../comment_relation_model.php | 5 ---- .../user_relation_model.php | 5 ---- 5 files changed, 20 insertions(+), 34 deletions(-) diff --git a/src/Generators/ModelGenerator.php b/src/Generators/ModelGenerator.php index c8c49fc..ae847d8 100644 --- a/src/Generators/ModelGenerator.php +++ b/src/Generators/ModelGenerator.php @@ -10,18 +10,18 @@ class ModelGenerator extends EntityGenerator { - CONST PLURAL_NUMBER_REQUIRED = [ + protected const array PLURAL_NUMBER_REQUIRED = [ 'belongsToMany', - 'hasMany' + 'hasMany', ]; public function generate(): void { if ($this->classExists('models', $this->model)) { $this->throwFailureException( - ClassAlreadyExistsException::class, - "Cannot create {$this->model} Model cause {$this->model} Model already exists.", - "Remove {$this->model} Model." + exceptionClass: ClassAlreadyExistsException::class, + failureMessage: "Cannot create {$this->model} Model cause {$this->model} Model already exists.", + recommendedMessage: "Remove {$this->model} Model.", ); } @@ -40,7 +40,7 @@ protected function getNewModelContent(): string 'fields' => Arr::collapse($this->fields), 'relations' => $this->prepareRelations(), 'casts' => $this->getCasts($this->fields), - 'namespace' => $this->getOrCreateNamespace('models') + 'namespace' => $this->getOrCreateNamespace('models'), ]); } @@ -68,7 +68,7 @@ public function prepareRelatedModels(): void $newRelation = $this->getStub('relation', [ 'name' => $this->getRelationName($this->model, $types[$type]), 'type' => $types[$type], - 'entity' => $this->model + 'entity' => $this->model, ]); $fixedContent = preg_replace('/\}$/', "\n {$newRelation}\n}", $content); @@ -78,9 +78,9 @@ public function prepareRelatedModels(): void } } - public function getModelContent($model): string + public function getModelContent(string $model): string { - $modelPath = base_path($this->paths['models'] . "/{$model}.php"); + $modelPath = base_path("{$this->paths['models']}/{$model}.php"); return file_get_contents($modelPath); } @@ -95,7 +95,7 @@ public function prepareRelations(): array $result[] = [ 'name' => $this->getRelationName($relation, $type), 'type' => $type, - 'entity' => $relation + 'entity' => $relation, ]; } } @@ -104,7 +104,7 @@ public function prepareRelations(): array return $result; } - protected function getCasts($fields): array + protected function getCasts(array $fields): array { $casts = [ 'boolean-required' => 'boolean', @@ -127,7 +127,7 @@ protected function getCasts($fields): array return $result; } - private function getRelationName($relation, $type): string + private function getRelationName(string $relation, string $type): string { $relationName = Str::snake($relation); diff --git a/tests/ModelGeneratorTest.php b/tests/ModelGeneratorTest.php index 76b6340..35a3c9f 100644 --- a/tests/ModelGeneratorTest.php +++ b/tests/ModelGeneratorTest.php @@ -6,17 +6,18 @@ use RonasIT\Support\Exceptions\ClassNotExistsException; use RonasIT\Support\Generators\ModelGenerator; use RonasIT\Support\Tests\Support\Model\ModelMockTrait; +use RonasIT\Support\Traits\MockTrait; class ModelGeneratorTest extends TestCase { - use ModelMockTrait; + use ModelMockTrait, MockTrait; public function testModelAlreadyExists() { $this->mockGeneratorForExistingModel(); $this->expectException(ClassAlreadyExistsException::class); - $this->expectErrorMessage('Cannot create Post Model cause Post Model already exists. Remove Post Model.'); + $this->expectExceptionMessage('Cannot create Post Model cause Post Model already exists. Remove Post Model.'); app(ModelGenerator::class) ->setModel('Post') @@ -25,10 +26,8 @@ public function testModelAlreadyExists() public function testRelationModelMissing() { - $this->mockGeneratorForMissingRelationModel(); - $this->expectException(ClassNotExistsException::class); - $this->expectErrorMessage("Cannot create Post Model cause relation model Comment does not exist. " + $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'."); app(ModelGenerator::class) @@ -45,7 +44,6 @@ public function testRelationModelMissing() public function testCreateModel() { $this->setupConfigurations(); - $this->mockViewsNamespace(); $this->mockFilesystem(); app(ModelGenerator::class) @@ -62,8 +60,6 @@ public function testCreateModel() ]) ->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/Model/ModelMockTrait.php b/tests/Support/Model/ModelMockTrait.php index bfddb97..a4bc3f8 100644 --- a/tests/Support/Model/ModelMockTrait.php +++ b/tests/Support/Model/ModelMockTrait.php @@ -4,7 +4,7 @@ use org\bovigo\vfs\vfsStream; use RonasIT\Support\Generators\ModelGenerator; -use RonasIT\Support\Tests\Support\Shared\GeneratorMockTrait; +use RonasIT\Support\Tests\Support\GeneratorMockTrait; trait ModelMockTrait { @@ -14,7 +14,7 @@ public function mockGeneratorForExistingModel() { $this->mockClass(ModelGenerator::class, [ [ - 'method' => 'classExists', + 'function' => 'classExists', 'arguments' => ['models', 'Post'], 'result' => true ] @@ -25,12 +25,12 @@ public function mockGeneratorForMissingRelationModel() { $this->mockClass(ModelGenerator::class, [ [ - 'method' => 'classExists', + 'function' => 'classExists', 'arguments' => ['models', 'Post'], 'result' => false ], [ - 'method' => 'classExists', + 'function' => 'classExists', 'arguments' => ['models', 'Comment'], 'result' => false ] diff --git a/tests/fixtures/ModelGeneratorTest/comment_relation_model.php b/tests/fixtures/ModelGeneratorTest/comment_relation_model.php index da86050..f8cf9a4 100644 --- a/tests/fixtures/ModelGeneratorTest/comment_relation_model.php +++ b/tests/fixtures/ModelGeneratorTest/comment_relation_model.php @@ -8,9 +8,4 @@ public function some_relation() { } - - public function post() - { - return $this->belongsTo(Post::class); - } } diff --git a/tests/fixtures/ModelGeneratorTest/user_relation_model.php b/tests/fixtures/ModelGeneratorTest/user_relation_model.php index da86050..f8cf9a4 100644 --- a/tests/fixtures/ModelGeneratorTest/user_relation_model.php +++ b/tests/fixtures/ModelGeneratorTest/user_relation_model.php @@ -8,9 +8,4 @@ public function some_relation() { } - - public function post() - { - return $this->belongsTo(Post::class); - } } From fe2e1f39e44adaa9c24c6171c8cd8dc4b70a3e17 Mon Sep 17 00:00:00 2001 From: roman Date: Mon, 9 Dec 2024 09:14:02 +0600 Subject: [PATCH 07/15] feat: fix tests refs: https://github.com/RonasIT/laravel-entity-generator/issues/49 --- tests/fixtures/ModelGeneratorTest/comment_relation_model.php | 5 +++++ tests/fixtures/ModelGeneratorTest/user_relation_model.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/tests/fixtures/ModelGeneratorTest/comment_relation_model.php b/tests/fixtures/ModelGeneratorTest/comment_relation_model.php index f8cf9a4..da86050 100644 --- a/tests/fixtures/ModelGeneratorTest/comment_relation_model.php +++ b/tests/fixtures/ModelGeneratorTest/comment_relation_model.php @@ -8,4 +8,9 @@ public function some_relation() { } + + public function post() + { + return $this->belongsTo(Post::class); + } } diff --git a/tests/fixtures/ModelGeneratorTest/user_relation_model.php b/tests/fixtures/ModelGeneratorTest/user_relation_model.php index f8cf9a4..da86050 100644 --- a/tests/fixtures/ModelGeneratorTest/user_relation_model.php +++ b/tests/fixtures/ModelGeneratorTest/user_relation_model.php @@ -8,4 +8,9 @@ public function some_relation() { } + + public function post() + { + return $this->belongsTo(Post::class); + } } From 14abfa0a230905bf2e0d044cc5eaf23f4d8d2ff6 Mon Sep 17 00:00:00 2001 From: roman Date: Tue, 17 Dec 2024 17:27:12 +0600 Subject: [PATCH 08/15] feat: change test refs: https://github.com/RonasIT/laravel-entity-generator/issues/49 --- tests/fixtures/ModelGeneratorTest/new_model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/ModelGeneratorTest/new_model.php b/tests/fixtures/ModelGeneratorTest/new_model.php index c62efef..80f1e29 100644 --- a/tests/fixtures/ModelGeneratorTest/new_model.php +++ b/tests/fixtures/ModelGeneratorTest/new_model.php @@ -8,7 +8,7 @@ class Post extends Model { - use ModelTrait, HasFactory; + use HasFactory, ModelTrait; protected $fillable = [ 'media_id', From 694ee923257eb3dd96923e3e7175998c9f5363e1 Mon Sep 17 00:00:00 2001 From: roman Date: Tue, 17 Dec 2024 17:37:18 +0600 Subject: [PATCH 09/15] 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 35a3c9f..3a74540 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 10/15] 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 e69de29..0000000 diff --git a/tests/Support/NovaTest/NovaTestMockTrait.php b/tests/Support/NovaTest/NovaTestMockTrait.php deleted file mode 100644 index e69de29..0000000 diff --git a/tests/Support/Shared/GeneratorMockTrait.php b/tests/Support/Shared/GeneratorMockTrait.php deleted file mode 100644 index e69de29..0000000 From 3f66a2fcb089ec930ceaa3f7648da3a57edcf280 Mon Sep 17 00:00:00 2001 From: roman Date: Wed, 18 Dec 2024 12:20:23 +0600 Subject: [PATCH 11/15] 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 2cadf49..bc39ad7 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 aa1b611..63113a9 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 3ae2cdcd9836b561aa7e601c00a58c370c82f1e2 Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 19 Dec 2024 17:52:54 +0600 Subject: [PATCH 12/15] refactor: code refs: https://github.com/RonasIT/laravel-entity-generator/issues/49 --- tests/ModelGeneratorTest.php | 15 ++++++---- tests/Support/Model/ModelMockTrait.php | 29 ++++++------------- .../NovaResource/NovaResourceMockTrait.php | 0 tests/Support/NovaTest/NovaTestMockTrait.php | 0 tests/Support/Shared/GeneratorMockTrait.php | 0 5 files changed, 18 insertions(+), 26 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/ModelGeneratorTest.php b/tests/ModelGeneratorTest.php index 35a3c9f..c34d925 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') @@ -43,7 +47,6 @@ public function testRelationModelMissing() public function testCreateModel() { - $this->setupConfigurations(); $this->mockFilesystem(); app(ModelGenerator::class) diff --git a/tests/Support/Model/ModelMockTrait.php b/tests/Support/Model/ModelMockTrait.php index a4bc3f8..17ed0be 100644 --- a/tests/Support/Model/ModelMockTrait.php +++ b/tests/Support/Model/ModelMockTrait.php @@ -10,41 +10,30 @@ trait ModelMockTrait { use GeneratorMockTrait; - public function mockGeneratorForExistingModel() + public function mockGeneratorForExistingModel(): void { $this->mockClass(ModelGenerator::class, [ [ 'function' => 'classExists', 'arguments' => ['models', 'Post'], - 'result' => true - ] + 'result' => true, + ], ]); } - public function mockGeneratorForMissingRelationModel() + public function mockGeneratorForMissingRelationModel(): void { $this->mockClass(ModelGenerator::class, [ [ 'function' => 'classExists', 'arguments' => ['models', 'Post'], - 'result' => false + 'result' => false, ], [ 'function' => 'classExists', 'arguments' => ['models', 'Comment'], - 'result' => false - ] - ]); - } - - public function setupConfigurations(): void - { - config([ - 'entity-generator.stubs.model' => 'entity-generator::model', - 'entity-generator.stubs.relation' => 'entity-generator::relation', - 'entity-generator.paths' => [ - 'models' => 'app/Models', - ] + 'result' => false, + ], ]); } @@ -54,8 +43,8 @@ public function mockFilesystem(): void 'app' => [ 'Models' => [ 'Comment.php' => file_get_contents(getcwd() . '/tests/Support/Model/RelationModelMock.php'), - 'User.php' => file_get_contents(getcwd() . '/tests/Support/Model/RelationModelMock.php') - ] + 'User.php' => file_get_contents(getcwd() . '/tests/Support/Model/RelationModelMock.php'), + ], ], ]; diff --git a/tests/Support/NovaResource/NovaResourceMockTrait.php b/tests/Support/NovaResource/NovaResourceMockTrait.php deleted file mode 100644 index e69de29..0000000 diff --git a/tests/Support/NovaTest/NovaTestMockTrait.php b/tests/Support/NovaTest/NovaTestMockTrait.php deleted file mode 100644 index e69de29..0000000 diff --git a/tests/Support/Shared/GeneratorMockTrait.php b/tests/Support/Shared/GeneratorMockTrait.php deleted file mode 100644 index e69de29..0000000 From d185d9cf3719a2b28e96ba16d4c8be56aadc72a9 Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 19 Dec 2024 17:54:17 +0600 Subject: [PATCH 13/15] refactor: code refs: https://github.com/RonasIT/laravel-entity-generator/issues/49 --- tests/ModelGeneratorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ModelGeneratorTest.php b/tests/ModelGeneratorTest.php index c34d925..d1904e8 100644 --- a/tests/ModelGeneratorTest.php +++ b/tests/ModelGeneratorTest.php @@ -18,7 +18,7 @@ public function testModelAlreadyExists() $this->assertExceptionThrew( className: ClassAlreadyExistsException::class, - message: 'Cannot create Post Model cause Post Model already exists. Remove Post Model.' + message: 'Cannot create Post Model cause Post Model already exists. Remove Post Model.', ); app(ModelGenerator::class) From f3165306f2c80724f01da688c34e008355e025a1 Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 19 Dec 2024 17:55:34 +0600 Subject: [PATCH 14/15] refactor: code refs: https://github.com/RonasIT/laravel-entity-generator/issues/49 --- tests/Support/Controller/ControllerMockTrait.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/Support/Controller/ControllerMockTrait.php diff --git a/tests/Support/Controller/ControllerMockTrait.php b/tests/Support/Controller/ControllerMockTrait.php deleted file mode 100644 index e69de29..0000000 From 8a4cd74eb95d0af8b45edb47d1591a0b80530618 Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 19 Dec 2024 18:34:03 +0600 Subject: [PATCH 15/15] 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 fd2e71b..0000000 --- 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