diff --git a/stubs/nova_test.blade.php b/stubs/nova_test.blade.php index 50f7a46c..3aa2fe9c 100644 --- a/stubs/nova_test.blade.php +++ b/stubs/nova_test.blade.php @@ -24,16 +24,16 @@ public function setUp(): void public function testCreate(): void { - $data = $this->getJsonFixture('create_{{$snake_entity}}_request.json'); + $data = $this->getJsonFixture('create_{{$snake_entity}}_request'); $response = $this->novaActingAs(self::$user)->novaCreateResourceAPICall({{$entity}}::class, $data); $response->assertCreated(); - $this->assertEqualsFixture('create_{{$snake_entity}}_response.json', $response->json()); + $this->assertEqualsFixture('create_{{$snake_entity}}_response', $response->json()); // TODO: Need to remove last argument after first successful start - self::${{$dromedary_entity}}State->assertChangesEqualsFixture('create_{{$lower_entities}}_state.json', true); + self::${{$dromedary_entity}}State->assertChangesEqualsFixture('create_{{$lower_entities}}_state', true); } public function testCreateNoAuth(): void @@ -52,26 +52,26 @@ public function testCreateValidationError(): void $response->assertUnprocessable(); // TODO: Need to remove last argument after first successful start - $this->assertEqualsFixture('create_validation_response.json', $response->json(), true); + $this->assertEqualsFixture('create_validation_response', $response->json(), true); self::${{$dromedary_entity}}State->assertNotChanged(); } public function testUpdate(): void { - $data = $this->getJsonFixture('update_{{$snake_entity}}_request.json'); + $data = $this->getJsonFixture('update_{{$snake_entity}}_request'); $response = $this->novaActingAs(self::$user)->novaUpdateResourceAPICall({{$entity}}::class, 1, $data); $response->assertNoContent(); // TODO: Need to remove last argument after first successful start - self::${{$dromedary_entity}}State->assertChangesEqualsFixture('update_{{$lower_entities}}_state.json', true); + self::${{$dromedary_entity}}State->assertChangesEqualsFixture('update_{{$lower_entities}}_state', true); } public function testUpdateNotExists(): void { - $data = $this->getJsonFixture('update_{{$snake_entity}}_request.json'); + $data = $this->getJsonFixture('update_{{$snake_entity}}_request'); $response = $this->novaActingAs(self::$user)->novaUpdateResourceAPICall({{$entity}}::class, 0, $data); @@ -92,7 +92,7 @@ public function testUpdateValidationError(): void $response->assertUnprocessable(); // TODO: Need to remove last argument after first successful start - $this->assertEqualsFixture('update_validation_response.json', $response->json(), true); + $this->assertEqualsFixture('update_validation_response', $response->json(), true); } public function testGetUpdatableFields(): void @@ -102,7 +102,7 @@ public function testGetUpdatableFields(): void $response->assertOk(); // TODO: Need to remove last argument after first successful start - $this->assertEqualsFixture('get_updatable_fields_response.json', $response->json(), true); + $this->assertEqualsFixture('get_updatable_fields_response', $response->json(), true); } public function testDelete(): void @@ -112,7 +112,7 @@ public function testDelete(): void $response->assertOk(); // TODO: Need to remove last argument after first successful start - self::${{$dromedary_entity}}State->assertChangesEqualsFixture('delete_{{$lower_entities}}_state.json', true); + self::${{$dromedary_entity}}State->assertChangesEqualsFixture('delete_{{$lower_entities}}_state', true); } public function testDeleteNotExists(): void @@ -136,7 +136,7 @@ public function testGet(): void $response->assertOk(); // TODO: Need to remove last argument after first successful start - $this->assertEqualsFixture('get_{{$snake_entity}}_response.json', $response->json(), true); + $this->assertEqualsFixture('get_{{$snake_entity}}_response', $response->json(), true); } public function testGetNotExists(): void @@ -167,7 +167,7 @@ public function testGetFieldsVisibleOnCreate(): void $response->assertOk(); // TODO: Need to remove last argument after first successful start - $this->assertEqualsFixture('get_fields_visible_on_create_response.json', $response->json(), true); + $this->assertEqualsFixture('get_fields_visible_on_create_response', $response->json(), true); } public static function getRun{{$entity}}ActionsData(): array diff --git a/stubs/test.blade.php b/stubs/test.blade.php index c4eb43c3..9e2f75e0 100644 --- a/stubs/test.blade.php +++ b/stubs/test.blade.php @@ -37,7 +37,7 @@ public function setUp(): void @if (in_array('C', $options)) public function testCreate() { - $data = $this->getJsonFixture('create_{{\Illuminate\Support\Str::snake($entity)}}_request.json'); + $data = $this->getJsonFixture('create_{{\Illuminate\Support\Str::snake($entity)}}_request'); @if (!$withAuth) $response = $this->json('post', '/{{$entities}}', $data); @@ -48,16 +48,16 @@ public function testCreate() $response->assertCreated(); // TODO: Need to remove last argument after first successful start - $this->assertEqualsFixture('create_{{\Illuminate\Support\Str::snake($entity)}}_response.json', $response->json(), true); + $this->assertEqualsFixture('create_{{\Illuminate\Support\Str::snake($entity)}}_response', $response->json(), true); // TODO: Need to remove last argument after first successful start - self::${{\Illuminate\Support\Str::camel($entity)}}State->assertChangesEqualsFixture('create_{{\Illuminate\Support\Str::snake($entity)}}_state.json', true); + self::${{\Illuminate\Support\Str::camel($entity)}}State->assertChangesEqualsFixture('create_{{\Illuminate\Support\Str::snake($entity)}}_state', true); } @if ($withAuth) public function testCreateNoAuth() { - $data = $this->getJsonFixture('create_{{\Illuminate\Support\Str::snake($entity)}}_request.json'); + $data = $this->getJsonFixture('create_{{\Illuminate\Support\Str::snake($entity)}}_request'); $response = $this->json('post', '/{{$entities}}', $data); @@ -69,7 +69,7 @@ public function testCreateNoAuth() @if (in_array('U', $options)) public function testUpdate() { - $data = $this->getJsonFixture('update_{{\Illuminate\Support\Str::snake($entity)}}_request.json'); + $data = $this->getJsonFixture('update_{{\Illuminate\Support\Str::snake($entity)}}_request'); @if (!$withAuth) $response = $this->json('put', '/{{$entities}}/1', $data); @@ -80,12 +80,12 @@ public function testUpdate() $response->assertNoContent(); // TODO: Need to remove last argument after first successful start - self::${{\Illuminate\Support\Str::camel($entity)}}State->assertChangesEqualsFixture('update_{{\Illuminate\Support\Str::snake($entity)}}_state.json', true); + self::${{\Illuminate\Support\Str::camel($entity)}}State->assertChangesEqualsFixture('update_{{\Illuminate\Support\Str::snake($entity)}}_state', true); } public function testUpdateNotExists() { - $data = $this->getJsonFixture('update_{{\Illuminate\Support\Str::snake($entity)}}_request.json'); + $data = $this->getJsonFixture('update_{{\Illuminate\Support\Str::snake($entity)}}_request'); @if (!$withAuth) $response = $this->json('put', '/{{$entities}}/0', $data); @@ -101,7 +101,7 @@ public function testUpdateNotExists() @if ($withAuth) public function testUpdateNoAuth() { - $data = $this->getJsonFixture('update_{{\Illuminate\Support\Str::snake($entity)}}_request.json'); + $data = $this->getJsonFixture('update_{{\Illuminate\Support\Str::snake($entity)}}_request'); $response = $this->json('put', '/{{$entities}}/1', $data); @@ -124,7 +124,7 @@ public function testDelete() $response->assertNoContent(); // TODO: Need to remove last argument after first successful start - self::${{\Illuminate\Support\Str::camel($entity)}}State->assertChangesEqualsFixture('delete_{{\Illuminate\Support\Str::snake($entity)}}_state.json', true); + self::${{\Illuminate\Support\Str::camel($entity)}}State->assertChangesEqualsFixture('delete_{{\Illuminate\Support\Str::snake($entity)}}_state', true); } public function testDeleteNotExists() @@ -164,7 +164,7 @@ public function testGet() // TODO: Need to remove after first successful start $this->exportJson('get_{{\Illuminate\Support\Str::snake($entity)}}.json', $response->json()); - $this->assertEqualsFixture('get_{{\Illuminate\Support\Str::snake($entity)}}.json', $response->json()); + $this->assertEqualsFixture('get_{{\Illuminate\Support\Str::snake($entity)}}', $response->json()); } public function testGetNotExists() diff --git a/tests/CommandTest.php b/tests/CommandTest.php index c07df082..8c90745e 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -4,8 +4,6 @@ use Carbon\Carbon; use Illuminate\Support\Facades\Config; -use org\bovigo\vfs\vfsStream; -use org\bovigo\vfs\vfsStreamFile; use RonasIT\Support\Exceptions\ClassNotExistsException; use RonasIT\Support\Tests\Support\Command\CommandMockTrait; use UnexpectedValueException; @@ -18,9 +16,7 @@ public function setUp(): void { parent::setUp(); - vfsStream::newDirectory('routes') - ->at($this->rootDirectory) - ->addChild(new vfsStreamFile('api.php')); + $this->mockFilesystem(); } public function testCallWithInvalidCrudOption() @@ -52,7 +48,6 @@ public function testCallCommand() Carbon::setTestNow('2016-10-20 11:05:00'); - $this->mockFilesystem(); $this->mockGenerator(); $this->mockGettingModelInstance(); @@ -143,6 +138,6 @@ public function testCallWithNotDefaultConfig() $this->assertFileExists($configPath); - $this->assertEqualsFixture('changed_config.json', $updated); + $this->assertEqualsFixture('changed_config', $updated); } } diff --git a/tests/ControllerGeneratorTest.php b/tests/ControllerGeneratorTest.php index 96ce0f54..a8b436a4 100644 --- a/tests/ControllerGeneratorTest.php +++ b/tests/ControllerGeneratorTest.php @@ -15,6 +15,13 @@ class ControllerGeneratorTest extends TestCase { use ControllerGeneratorMockTrait; + public function setUp(): void + { + parent::setUp(); + + $this->mockFilesystem(); + } + public function testControllerAlreadyExists() { $this->mockClass(ControllerGenerator::class, [ @@ -65,8 +72,6 @@ className: FileNotFoundException::class, public function testControllerStubNotExist() { - $this->mockFilesystem(); - View::shouldReceive('exists') ->with('entity-generator::controller') ->once() @@ -88,8 +93,6 @@ className: WarningEvent::class, public function testRoutesStubNotExist() { - $this->mockFilesystem(); - config(['entity-generator.stubs.routes' => 'incorrect_stub']); app(ControllerGenerator::class) @@ -108,8 +111,6 @@ public function testRoutesStubNotExist() public function testUseRoutesStubNotExist() { - $this->mockFilesystem(); - config(['entity-generator.stubs.use_routes' => 'incorrect_stub']); app(ControllerGenerator::class) @@ -128,8 +129,6 @@ public function testUseRoutesStubNotExist() public function testSuccess() { - $this->mockFilesystem(); - app(ControllerGenerator::class) ->setModel('Post') ->setCrudOptions(['C', 'R', 'U', 'D']) diff --git a/tests/FactoryGeneratorTest.php b/tests/FactoryGeneratorTest.php index 0bd7bd17..da88ce4e 100644 --- a/tests/FactoryGeneratorTest.php +++ b/tests/FactoryGeneratorTest.php @@ -17,8 +17,17 @@ class FactoryGeneratorTest extends TestCase { use FactoryMockTrait; + public function setUp(): void + { + parent::setUp(); + + $this->mockFilesystem(); + } + public function testModelNotExists() { + $this->mockFileSystemWithoutPostModel(); + $this->assertExceptionThrew( className: ClassNotExistsException::class, message: "Cannot create PostFactory cause Post Model does not exists. " @@ -53,8 +62,6 @@ className: ClassAlreadyExistsException::class, public function testProcessUnknownFieldType() { - $this->mockFilesystem(); - $this->assertExceptionThrew( className: ViewException::class, message: "Cannot generate fake data for unsupported another_type field type. " @@ -76,8 +83,6 @@ className: ViewException::class, public function testCreateSuccess() { - $this->mockFilesystem(); - app(FactoryGenerator::class) ->setFields([ 'integer-required' => ['author_id'], @@ -102,8 +107,6 @@ className: SuccessCreateMessage::class, public function testCreateFactoryWithoutFactoryStub(): void { - $this->mockFilesystem(); - config(['entity-generator.stubs.factory' => 'incorrect_stub']); app(FactoryGenerator::class) diff --git a/tests/MigrationGeneratorTest.php b/tests/MigrationGeneratorTest.php index 9a156aed..174668bb 100644 --- a/tests/MigrationGeneratorTest.php +++ b/tests/MigrationGeneratorTest.php @@ -33,8 +33,6 @@ className: UnknownFieldTypeException::class, public function testCreateMigration() { - Carbon::setTestNow('2022-02-02'); - app(MigrationGenerator::class) ->setModel('Post') ->setRelations([ @@ -58,8 +56,6 @@ public function testCreateMigrationMYSQL() { putenv('DB_CONNECTION=mysql'); - Carbon::setTestNow('2022-02-02'); - app(MigrationGenerator::class) ->setModel('Post') ->setRelations([ @@ -82,8 +78,6 @@ public function testCreateMigrationMYSQL() public function testCreateMigrationWithoutMigrationStub(): void { - Carbon::setTestNow('2022-02-02'); - config(['entity-generator.stubs.migration' => 'incorrect_stub']); app(MigrationGenerator::class) diff --git a/tests/ModelGeneratorTest.php b/tests/ModelGeneratorTest.php index 73e96af1..e9cc60ac 100644 --- a/tests/ModelGeneratorTest.php +++ b/tests/ModelGeneratorTest.php @@ -13,6 +13,13 @@ class ModelGeneratorTest extends TestCase { use ModelMockTrait; + public function setUp(): void + { + parent::setUp(); + + $this->mockFilesystem(); + } + public function testModelAlreadyExists() { $this->mockClass(ModelGenerator::class, [ @@ -31,6 +38,8 @@ className: ClassAlreadyExistsException::class, public function testRelationModelMissing() { + $this->mockFileSystemWithoutCommentModel(); + $this->assertExceptionThrew( className: ClassNotExistsException::class, message: "Cannot create Post Model cause relation model Comment does not exist. " @@ -50,8 +59,6 @@ className: ClassNotExistsException::class, public function testCreateModel() { - $this->mockFilesystem(); - app(ModelGenerator::class) ->setModel('Post') ->setFields([ @@ -78,8 +85,6 @@ className: SuccessCreateMessage::class, public function testCreateModelStubNotExist() { - $this->mockFilesystem(); - config(['entity-generator.stubs.model' => 'incorrect_stub']); app(ModelGenerator::class) @@ -99,8 +104,6 @@ className: WarningEvent::class, public function testCreateModelWithoutRelationsRelationStubNotExist() { - $this->mockFilesystem(); - config(['entity-generator.stubs.relation' => 'incorrect_stub']); app(ModelGenerator::class) @@ -118,8 +121,6 @@ className: SuccessCreateMessage::class, public function testCreateModelWithRelationsRelationStubNotExist() { - $this->mockFilesystem(); - config(['entity-generator.stubs.relation' => 'incorrect_stub']); app(ModelGenerator::class) diff --git a/tests/NovaResourceGeneratorTest.php b/tests/NovaResourceGeneratorTest.php index 5a5b897f..cea48ffa 100644 --- a/tests/NovaResourceGeneratorTest.php +++ b/tests/NovaResourceGeneratorTest.php @@ -13,6 +13,13 @@ class NovaResourceGeneratorTest extends TestCase { use NovaResourceGeneratorMockTrait; + public function setUp():void + { + parent::setUp(); + + $this->mockFilesystem(); + } + public function testCreateWithMissingNovaPackage() { $this->mockNovaServiceProviderExists(false); @@ -29,6 +36,8 @@ className: SuccessCreateMessage::class, public function testCreateNovaResourceWithMissingModel() { + $this->mockFileSystemWithoutPostModel(); + $this->mockNovaServiceProviderExists(); $this->assertExceptionThrew( @@ -65,9 +74,7 @@ public function testNovaResourceStubNotExist() { $this->mockNovaServiceProviderExists(); - $this->mockFilesystem(); - - $fields = $this->getJsonFixture('command_line_fields.json'); + $fields = $this->getJsonFixture('command_line_fields'); config(['entity-generator.stubs.nova_resource' => 'incorrect_stub']); @@ -88,9 +95,7 @@ public function testSuccess() { $this->mockNovaServiceProviderExists(); - $this->mockFilesystem(); - - $fields = $this->getJsonFixture('command_line_fields.json'); + $fields = $this->getJsonFixture('command_line_fields'); app(NovaResourceGenerator::class) ->setModel('Post') @@ -111,8 +116,6 @@ public function testSuccessWithoutCommandLineFields() $this->mockGettingModelInstance(); - $this->mockFilesystem(); - app(NovaResourceGenerator::class) ->setModel('Post') ->setFields([]) diff --git a/tests/NovaTestGeneratorTest.php b/tests/NovaTestGeneratorTest.php index 8b3fe11e..d953040a 100644 --- a/tests/NovaTestGeneratorTest.php +++ b/tests/NovaTestGeneratorTest.php @@ -16,6 +16,13 @@ class NovaTestGeneratorTest extends TestCase { use NovaTestGeneratorMockTrait; + public function setUp(): void + { + parent::setUp(); + + $this->mockFilesystem(); + } + public function testGenerateResourceNotExists() { $this->mockNovaServiceProviderExists(); @@ -62,7 +69,6 @@ public function testNovaTestStubNotExist() $this->nativeClassExistsMethodCall([WelcomeBonus::class, true]), ); - $this->mockFilesystem(); $this->mockNovaRequestClassCall(); config([ @@ -95,7 +101,6 @@ public function testDumpStubNotExist() { $this->mockNovaServiceProviderExists(); - $this->mockFilesystem(); $this->mockNovaRequestClassCall(); config([ @@ -135,7 +140,6 @@ public function testSuccess() $this->nativeClassExistsMethodCall([WelcomeBonus::class, true]), ); - $this->mockFilesystem(); $this->mockNovaRequestClassCall(); app(NovaTestGenerator::class) diff --git a/tests/RepositoryGeneratorTest.php b/tests/RepositoryGeneratorTest.php index 14cb0452..730f063c 100644 --- a/tests/RepositoryGeneratorTest.php +++ b/tests/RepositoryGeneratorTest.php @@ -12,6 +12,13 @@ class RepositoryGeneratorTest extends TestCase { use RepositoryMockTrait; + public function setUp(): void + { + parent::setUp(); + + $this->mockFilesystem(); + } + public function testModelNotExist() { $this->mockClass(RepositoryGenerator::class, [ @@ -33,8 +40,6 @@ className: ClassNotExistsException::class, public function testCreateRepository() { - $this->mockFilesystem(); - app(RepositoryGenerator::class) ->setModel('Post') ->generate(); @@ -51,8 +56,6 @@ public function testCreateRepositoryStubNotExist() { config(['entity-generator.stubs.repository' => 'incorrect_stub']); - $this->mockFilesystem(); - app(RepositoryGenerator::class) ->setModel('Post') ->generate(); diff --git a/tests/Support/ControllerGeneratorTest/ControllerGeneratorMockTrait.php b/tests/Support/ControllerGeneratorTest/ControllerGeneratorMockTrait.php index fb39a019..0c740b3c 100644 --- a/tests/Support/ControllerGeneratorTest/ControllerGeneratorMockTrait.php +++ b/tests/Support/ControllerGeneratorTest/ControllerGeneratorMockTrait.php @@ -15,7 +15,7 @@ public function mockFilesystemWithoutRoutesFile(): void $fileSystemMock->services = [ 'PostService.php' => $this->mockPhpFileContent(), ]; - $fileSystemMock->controllers = []; + $fileSystemMock->routes = []; $fileSystemMock->setStructure(); } diff --git a/tests/Support/Factory/FactoryMockTrait.php b/tests/Support/Factory/FactoryMockTrait.php index 0e9bb17f..392bad93 100644 --- a/tests/Support/Factory/FactoryMockTrait.php +++ b/tests/Support/Factory/FactoryMockTrait.php @@ -15,6 +15,17 @@ public function mockFactoryGenerator(array ...$functionCalls): void $this->mockClass(FactoryGenerator::class, $functionCalls); } + public function mockFileSystemWithoutPostModel(): void + { + $fileSystemMock = new FileSystemMock(); + + $fileSystemMock->models = [ + 'User.php' => $this->mockPhpFileContent(), + ]; + + $fileSystemMock->setStructure(); + } + public function mockFilesystem(): void { $fileSystemMock = new FileSystemMock(); diff --git a/tests/Support/Model/ModelMockTrait.php b/tests/Support/Model/ModelMockTrait.php index dad2d4ea..1da65e3c 100644 --- a/tests/Support/Model/ModelMockTrait.php +++ b/tests/Support/Model/ModelMockTrait.php @@ -9,6 +9,18 @@ trait ModelMockTrait { use GeneratorMockTrait; + + public function mockFileSystemWithoutCommentModel(): void + { + $fileSystemMock = new FileSystemMock(); + + $fileSystemMock->models = [ + 'User.php' => file_get_contents(getcwd() . '/tests/Support/Models/WelcomeBonus.php'), + ]; + + $fileSystemMock->setStructure(); + } + public function mockFilesystem(): void { $fileSystemMock = new FileSystemMock; diff --git a/tests/Support/NovaResourceGeneratorTest/NovaResourceGeneratorMockTrait.php b/tests/Support/NovaResourceGeneratorTest/NovaResourceGeneratorMockTrait.php index 77410f91..705f1492 100644 --- a/tests/Support/NovaResourceGeneratorTest/NovaResourceGeneratorMockTrait.php +++ b/tests/Support/NovaResourceGeneratorTest/NovaResourceGeneratorMockTrait.php @@ -38,4 +38,13 @@ public function mockGettingModelInstance(): void $this->app->instance('App\\Models\\Post', new Post); } + + public function mockFileSystemWithoutPostModel(): void + { + $fileSystemMock = new FileSystemMock(); + + $fileSystemMock->models = null; + + $fileSystemMock->setStructure(); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 3a232272..10d4c8cd 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -5,11 +5,11 @@ use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables; use Illuminate\Foundation\Testing\Concerns\InteractsWithViews; use Illuminate\Support\Arr; +use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Event; use Illuminate\Support\Str; use Orchestra\Testbench\TestCase as BaseTestCase; use org\bovigo\vfs\vfsStream; -use org\bovigo\vfs\vfsStreamDirectory; use RonasIT\Support\EntityGeneratorServiceProvider; use RonasIT\Support\Traits\FixturesTrait; @@ -21,23 +21,21 @@ class TestCase extends BaseTestCase protected bool $globalExportMode = false; protected string $generatedFileBasePath; - protected vfsStreamDirectory $rootDirectory; - public function setUp(): void { parent::setUp(); $this->mockConfigurations(); - $this->rootDirectory = vfsStream::setup(); + vfsStream::setup(); $this->generatedFileBasePath = vfsStream::url('root'); - vfsStream::newDirectory('config')->at($this->rootDirectory); - Event::fake(); $this->app->setBasePath($this->generatedFileBasePath); + + Carbon::setTestNow('2022-02-02'); } public function getFixturePath(string $fixtureName): string diff --git a/tests/TestGeneratorTest.php b/tests/TestGeneratorTest.php index d283b901..cd2d8789 100644 --- a/tests/TestGeneratorTest.php +++ b/tests/TestGeneratorTest.php @@ -24,6 +24,8 @@ public function setUp(): void WarningEvent::class, SuccessCreateMessage::class, ]); + + $this->mockFilesystem(); } public function testMissingModel() @@ -41,8 +43,6 @@ className: ClassNotExistsException::class, public function testCreateTests() { - Carbon::setTestNow('2022-02-02'); - $mock = Mockery::mock('alias:Illuminate\Support\Facades\DB'); $mock ->shouldReceive('beginTransaction', 'rollBack') @@ -65,8 +65,6 @@ public function testCreateTests() $this->classExistsMethodCall(['factories', 'PostFactory']), ]); - $this->mockFilesystem(); - app(TestsGenerator::class) ->setCrudOptions(['C', 'R', 'U', 'D']) ->setModel('Post') @@ -91,8 +89,6 @@ public function testCreateTests() public function testCreateTestsReadDelete() { - Carbon::setTestNow('2022-02-02'); - $mock = Mockery::mock('alias:Illuminate\Support\Facades\DB'); $mock ->shouldReceive('beginTransaction', 'rollBack') @@ -115,8 +111,6 @@ public function testCreateTestsReadDelete() $this->classExistsMethodCall(['factories', 'PostFactory']), ]); - $this->mockFilesystem(); - app(TestsGenerator::class) ->setCrudOptions(['R', 'D']) ->setModel('Post') @@ -141,15 +135,11 @@ public function testCreateTestsDumpStubNotExist() 'entity-generator.stubs.dump' => 'incorrect_stub', ]); - Carbon::setTestNow('2022-02-02'); - $this->mockClass(TestsGenerator::class, [ $this->classExistsMethodCall(['models', 'User']), $this->classExistsMethodCall(['factories', 'PostFactory']), ]); - $this->mockFilesystem(); - app(TestsGenerator::class) ->setCrudOptions(['C', 'R', 'U', 'D']) ->setModel('Post') @@ -182,8 +172,6 @@ public function testCreateTestsTestStubNotExist() 'entity-generator.stubs.test' => 'incorrect_stub', ]); - Carbon::setTestNow('2022-02-02'); - $mock = Mockery::mock('alias:Illuminate\Support\Facades\DB'); $mock ->shouldReceive('beginTransaction', 'rollBack') @@ -201,8 +189,6 @@ public function testCreateTestsTestStubNotExist() $this->classExistsMethodCall(['factories', 'PostFactory']), ]); - $this->mockFilesystem(); - app(TestsGenerator::class) ->setCrudOptions(['C', 'R', 'U', 'D']) ->setModel('Post') diff --git a/tests/TranslationGeneratorTest.php b/tests/TranslationGeneratorTest.php index b902a886..5814d083 100644 --- a/tests/TranslationGeneratorTest.php +++ b/tests/TranslationGeneratorTest.php @@ -13,11 +13,16 @@ class TranslationGeneratorTest extends TestCase { use TranslationMockTrait; - public function testCreate() + public function setUp(): void { - Lang::shouldReceive('get')->andReturn([]); + parent::setUp(); $this->mockFilesystem(); + } + + public function testCreate() + { + Lang::shouldReceive('get')->andReturn([]); app(TranslationsGenerator::class) ->setModel('Post') diff --git a/tests/fixtures/CommandTest/nova_test.php b/tests/fixtures/CommandTest/nova_test.php index fa304c3d..c7b2a1ae 100644 --- a/tests/fixtures/CommandTest/nova_test.php +++ b/tests/fixtures/CommandTest/nova_test.php @@ -26,16 +26,16 @@ public function setUp(): void public function testCreate(): void { - $data = $this->getJsonFixture('create_post_request.json'); + $data = $this->getJsonFixture('create_post_request'); $response = $this->novaActingAs(self::$user)->novaCreateResourceAPICall(Post::class, $data); $response->assertCreated(); - $this->assertEqualsFixture('create_post_response.json', $response->json()); + $this->assertEqualsFixture('create_post_response', $response->json()); // TODO: Need to remove last argument after first successful start - self::$postState->assertChangesEqualsFixture('create_posts_state.json', true); + self::$postState->assertChangesEqualsFixture('create_posts_state', true); } public function testCreateNoAuth(): void @@ -54,26 +54,26 @@ public function testCreateValidationError(): void $response->assertUnprocessable(); // TODO: Need to remove last argument after first successful start - $this->assertEqualsFixture('create_validation_response.json', $response->json(), true); + $this->assertEqualsFixture('create_validation_response', $response->json(), true); self::$postState->assertNotChanged(); } public function testUpdate(): void { - $data = $this->getJsonFixture('update_post_request.json'); + $data = $this->getJsonFixture('update_post_request'); $response = $this->novaActingAs(self::$user)->novaUpdateResourceAPICall(Post::class, 1, $data); $response->assertNoContent(); // TODO: Need to remove last argument after first successful start - self::$postState->assertChangesEqualsFixture('update_posts_state.json', true); + self::$postState->assertChangesEqualsFixture('update_posts_state', true); } public function testUpdateNotExists(): void { - $data = $this->getJsonFixture('update_post_request.json'); + $data = $this->getJsonFixture('update_post_request'); $response = $this->novaActingAs(self::$user)->novaUpdateResourceAPICall(Post::class, 0, $data); @@ -94,7 +94,7 @@ public function testUpdateValidationError(): void $response->assertUnprocessable(); // TODO: Need to remove last argument after first successful start - $this->assertEqualsFixture('update_validation_response.json', $response->json(), true); + $this->assertEqualsFixture('update_validation_response', $response->json(), true); } public function testGetUpdatableFields(): void @@ -104,7 +104,7 @@ public function testGetUpdatableFields(): void $response->assertOk(); // TODO: Need to remove last argument after first successful start - $this->assertEqualsFixture('get_updatable_fields_response.json', $response->json(), true); + $this->assertEqualsFixture('get_updatable_fields_response', $response->json(), true); } public function testDelete(): void @@ -114,7 +114,7 @@ public function testDelete(): void $response->assertOk(); // TODO: Need to remove last argument after first successful start - self::$postState->assertChangesEqualsFixture('delete_posts_state.json', true); + self::$postState->assertChangesEqualsFixture('delete_posts_state', true); } public function testDeleteNotExists(): void @@ -138,7 +138,7 @@ public function testGet(): void $response->assertOk(); // TODO: Need to remove last argument after first successful start - $this->assertEqualsFixture('get_post_response.json', $response->json(), true); + $this->assertEqualsFixture('get_post_response', $response->json(), true); } public function testGetNotExists(): void @@ -169,7 +169,7 @@ public function testGetFieldsVisibleOnCreate(): void $response->assertOk(); // TODO: Need to remove last argument after first successful start - $this->assertEqualsFixture('get_fields_visible_on_create_response.json', $response->json(), true); + $this->assertEqualsFixture('get_fields_visible_on_create_response', $response->json(), true); } public static function getRunPostActionsData(): array diff --git a/tests/fixtures/CommandTest/test.php b/tests/fixtures/CommandTest/test.php index 24219fb8..f0834e5a 100644 --- a/tests/fixtures/CommandTest/test.php +++ b/tests/fixtures/CommandTest/test.php @@ -19,34 +19,34 @@ public function setUp(): void public function testCreate() { - $data = $this->getJsonFixture('create_post_request.json'); + $data = $this->getJsonFixture('create_post_request'); $response = $this->json('post', '/posts', $data); $response->assertCreated(); // TODO: Need to remove last argument after first successful start - $this->assertEqualsFixture('create_post_response.json', $response->json(), true); + $this->assertEqualsFixture('create_post_response', $response->json(), true); // TODO: Need to remove last argument after first successful start - self::$postState->assertChangesEqualsFixture('create_post_state.json', true); + self::$postState->assertChangesEqualsFixture('create_post_state', true); } public function testUpdate() { - $data = $this->getJsonFixture('update_post_request.json'); + $data = $this->getJsonFixture('update_post_request'); $response = $this->json('put', '/posts/1', $data); $response->assertNoContent(); // TODO: Need to remove last argument after first successful start - self::$postState->assertChangesEqualsFixture('update_post_state.json', true); + self::$postState->assertChangesEqualsFixture('update_post_state', true); } public function testUpdateNotExists() { - $data = $this->getJsonFixture('update_post_request.json'); + $data = $this->getJsonFixture('update_post_request'); $response = $this->json('put', '/posts/0', $data); @@ -62,7 +62,7 @@ public function testDelete() $response->assertNoContent(); // TODO: Need to remove last argument after first successful start - self::$postState->assertChangesEqualsFixture('delete_post_state.json', true); + self::$postState->assertChangesEqualsFixture('delete_post_state', true); } public function testDeleteNotExists() @@ -83,7 +83,7 @@ public function testGet() // TODO: Need to remove after first successful start $this->exportJson('get_post.json', $response->json()); - $this->assertEqualsFixture('get_post.json', $response->json()); + $this->assertEqualsFixture('get_post', $response->json()); } public function testGetNotExists() diff --git a/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php b/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php index ec6e6543..48cf5a0c 100644 --- a/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php +++ b/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php @@ -26,16 +26,16 @@ public function setUp(): void public function testCreate(): void { - $data = $this->getJsonFixture('create_welcome_bonus_request.json'); + $data = $this->getJsonFixture('create_welcome_bonus_request'); $response = $this->novaActingAs(self::$user)->novaCreateResourceAPICall(WelcomeBonus::class, $data); $response->assertCreated(); - $this->assertEqualsFixture('create_welcome_bonus_response.json', $response->json()); + $this->assertEqualsFixture('create_welcome_bonus_response', $response->json()); // TODO: Need to remove last argument after first successful start - self::$welcomeBonusState->assertChangesEqualsFixture('create_welcome_bonuses_state.json', true); + self::$welcomeBonusState->assertChangesEqualsFixture('create_welcome_bonuses_state', true); } public function testCreateNoAuth(): void @@ -54,26 +54,26 @@ public function testCreateValidationError(): void $response->assertUnprocessable(); // TODO: Need to remove last argument after first successful start - $this->assertEqualsFixture('create_validation_response.json', $response->json(), true); + $this->assertEqualsFixture('create_validation_response', $response->json(), true); self::$welcomeBonusState->assertNotChanged(); } public function testUpdate(): void { - $data = $this->getJsonFixture('update_welcome_bonus_request.json'); + $data = $this->getJsonFixture('update_welcome_bonus_request'); $response = $this->novaActingAs(self::$user)->novaUpdateResourceAPICall(WelcomeBonus::class, 1, $data); $response->assertNoContent(); // TODO: Need to remove last argument after first successful start - self::$welcomeBonusState->assertChangesEqualsFixture('update_welcome_bonuses_state.json', true); + self::$welcomeBonusState->assertChangesEqualsFixture('update_welcome_bonuses_state', true); } public function testUpdateNotExists(): void { - $data = $this->getJsonFixture('update_welcome_bonus_request.json'); + $data = $this->getJsonFixture('update_welcome_bonus_request'); $response = $this->novaActingAs(self::$user)->novaUpdateResourceAPICall(WelcomeBonus::class, 0, $data); @@ -94,7 +94,7 @@ public function testUpdateValidationError(): void $response->assertUnprocessable(); // TODO: Need to remove last argument after first successful start - $this->assertEqualsFixture('update_validation_response.json', $response->json(), true); + $this->assertEqualsFixture('update_validation_response', $response->json(), true); } public function testGetUpdatableFields(): void @@ -104,7 +104,7 @@ public function testGetUpdatableFields(): void $response->assertOk(); // TODO: Need to remove last argument after first successful start - $this->assertEqualsFixture('get_updatable_fields_response.json', $response->json(), true); + $this->assertEqualsFixture('get_updatable_fields_response', $response->json(), true); } public function testDelete(): void @@ -114,7 +114,7 @@ public function testDelete(): void $response->assertOk(); // TODO: Need to remove last argument after first successful start - self::$welcomeBonusState->assertChangesEqualsFixture('delete_welcome_bonuses_state.json', true); + self::$welcomeBonusState->assertChangesEqualsFixture('delete_welcome_bonuses_state', true); } public function testDeleteNotExists(): void @@ -138,7 +138,7 @@ public function testGet(): void $response->assertOk(); // TODO: Need to remove last argument after first successful start - $this->assertEqualsFixture('get_welcome_bonus_response.json', $response->json(), true); + $this->assertEqualsFixture('get_welcome_bonus_response', $response->json(), true); } public function testGetNotExists(): void @@ -169,7 +169,7 @@ public function testGetFieldsVisibleOnCreate(): void $response->assertOk(); // TODO: Need to remove last argument after first successful start - $this->assertEqualsFixture('get_fields_visible_on_create_response.json', $response->json(), true); + $this->assertEqualsFixture('get_fields_visible_on_create_response', $response->json(), true); } public static function getRunWelcomeBonusActionsData(): array diff --git a/tests/fixtures/TestGeneratorTest/post_test.php b/tests/fixtures/TestGeneratorTest/post_test.php index dcc066b8..0559f966 100644 --- a/tests/fixtures/TestGeneratorTest/post_test.php +++ b/tests/fixtures/TestGeneratorTest/post_test.php @@ -24,22 +24,22 @@ public function setUp(): void public function testCreate() { - $data = $this->getJsonFixture('create_post_request.json'); + $data = $this->getJsonFixture('create_post_request'); $response = $this->actingAs(self::$user)->json('post', '/posts', $data); $response->assertCreated(); // TODO: Need to remove last argument after first successful start - $this->assertEqualsFixture('create_post_response.json', $response->json(), true); + $this->assertEqualsFixture('create_post_response', $response->json(), true); // TODO: Need to remove last argument after first successful start - self::$postState->assertChangesEqualsFixture('create_post_state.json', true); + self::$postState->assertChangesEqualsFixture('create_post_state', true); } public function testCreateNoAuth() { - $data = $this->getJsonFixture('create_post_request.json'); + $data = $this->getJsonFixture('create_post_request'); $response = $this->json('post', '/posts', $data); @@ -48,19 +48,19 @@ public function testCreateNoAuth() public function testUpdate() { - $data = $this->getJsonFixture('update_post_request.json'); + $data = $this->getJsonFixture('update_post_request'); $response = $this->actingAs(self::$user)->json('put', '/posts/1', $data); $response->assertNoContent(); // TODO: Need to remove last argument after first successful start - self::$postState->assertChangesEqualsFixture('update_post_state.json', true); + self::$postState->assertChangesEqualsFixture('update_post_state', true); } public function testUpdateNotExists() { - $data = $this->getJsonFixture('update_post_request.json'); + $data = $this->getJsonFixture('update_post_request'); $response = $this->actingAs(self::$user)->json('put', '/posts/0', $data); @@ -71,7 +71,7 @@ public function testUpdateNotExists() public function testUpdateNoAuth() { - $data = $this->getJsonFixture('update_post_request.json'); + $data = $this->getJsonFixture('update_post_request'); $response = $this->json('put', '/posts/1', $data); @@ -87,7 +87,7 @@ public function testDelete() $response->assertNoContent(); // TODO: Need to remove last argument after first successful start - self::$postState->assertChangesEqualsFixture('delete_post_state.json', true); + self::$postState->assertChangesEqualsFixture('delete_post_state', true); } public function testDeleteNotExists() @@ -115,7 +115,7 @@ public function testGet() // TODO: Need to remove after first successful start $this->exportJson('get_post.json', $response->json()); - $this->assertEqualsFixture('get_post.json', $response->json()); + $this->assertEqualsFixture('get_post', $response->json()); } public function testGetNotExists() diff --git a/tests/fixtures/TestGeneratorTest/post_test_read_delete.php b/tests/fixtures/TestGeneratorTest/post_test_read_delete.php index 89635966..2e92a49d 100644 --- a/tests/fixtures/TestGeneratorTest/post_test_read_delete.php +++ b/tests/fixtures/TestGeneratorTest/post_test_read_delete.php @@ -29,7 +29,7 @@ public function testDelete() $response->assertNoContent(); // TODO: Need to remove last argument after first successful start - self::$postState->assertChangesEqualsFixture('delete_post_state.json', true); + self::$postState->assertChangesEqualsFixture('delete_post_state', true); } public function testDeleteNotExists() @@ -57,7 +57,7 @@ public function testGet() // TODO: Need to remove after first successful start $this->exportJson('get_post.json', $response->json()); - $this->assertEqualsFixture('get_post.json', $response->json()); + $this->assertEqualsFixture('get_post', $response->json()); } public function testGetNotExists()