Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions stubs/nova_test.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions stubs/test.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 2 additions & 7 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down Expand Up @@ -52,7 +48,6 @@ public function testCallCommand()

Carbon::setTestNow('2016-10-20 11:05:00');

$this->mockFilesystem();
$this->mockGenerator();
$this->mockGettingModelInstance();

Expand Down Expand Up @@ -143,6 +138,6 @@ public function testCallWithNotDefaultConfig()

$this->assertFileExists($configPath);

$this->assertEqualsFixture('changed_config.json', $updated);
$this->assertEqualsFixture('changed_config', $updated);
}
}
15 changes: 7 additions & 8 deletions tests/ControllerGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, [
Expand Down Expand Up @@ -65,8 +72,6 @@ className: FileNotFoundException::class,

public function testControllerStubNotExist()
{
$this->mockFilesystem();

View::shouldReceive('exists')
->with('entity-generator::controller')
->once()
Expand All @@ -88,8 +93,6 @@ className: WarningEvent::class,

public function testRoutesStubNotExist()
{
$this->mockFilesystem();

config(['entity-generator.stubs.routes' => 'incorrect_stub']);

app(ControllerGenerator::class)
Expand All @@ -108,8 +111,6 @@ public function testRoutesStubNotExist()

public function testUseRoutesStubNotExist()
{
$this->mockFilesystem();

config(['entity-generator.stubs.use_routes' => 'incorrect_stub']);

app(ControllerGenerator::class)
Expand All @@ -128,8 +129,6 @@ public function testUseRoutesStubNotExist()

public function testSuccess()
{
$this->mockFilesystem();

app(ControllerGenerator::class)
->setModel('Post')
->setCrudOptions(['C', 'R', 'U', 'D'])
Expand Down
15 changes: 9 additions & 6 deletions tests/FactoryGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. "
Expand Down Expand Up @@ -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. "
Expand All @@ -76,8 +83,6 @@ className: ViewException::class,

public function testCreateSuccess()
{
$this->mockFilesystem();

app(FactoryGenerator::class)
->setFields([
'integer-required' => ['author_id'],
Expand All @@ -102,8 +107,6 @@ className: SuccessCreateMessage::class,

public function testCreateFactoryWithoutFactoryStub(): void
{
$this->mockFilesystem();

config(['entity-generator.stubs.factory' => 'incorrect_stub']);

app(FactoryGenerator::class)
Expand Down
6 changes: 0 additions & 6 deletions tests/MigrationGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ className: UnknownFieldTypeException::class,

public function testCreateMigration()
{
Carbon::setTestNow('2022-02-02');

app(MigrationGenerator::class)
->setModel('Post')
->setRelations([
Expand All @@ -58,8 +56,6 @@ public function testCreateMigrationMYSQL()
{
putenv('DB_CONNECTION=mysql');

Carbon::setTestNow('2022-02-02');

app(MigrationGenerator::class)
->setModel('Post')
->setRelations([
Expand All @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions tests/ModelGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, [
Expand All @@ -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. "
Expand All @@ -50,8 +59,6 @@ className: ClassNotExistsException::class,

public function testCreateModel()
{
$this->mockFilesystem();

app(ModelGenerator::class)
->setModel('Post')
->setFields([
Expand All @@ -78,8 +85,6 @@ className: SuccessCreateMessage::class,

public function testCreateModelStubNotExist()
{
$this->mockFilesystem();

config(['entity-generator.stubs.model' => 'incorrect_stub']);

app(ModelGenerator::class)
Expand All @@ -99,8 +104,6 @@ className: WarningEvent::class,

public function testCreateModelWithoutRelationsRelationStubNotExist()
{
$this->mockFilesystem();

config(['entity-generator.stubs.relation' => 'incorrect_stub']);

app(ModelGenerator::class)
Expand All @@ -118,8 +121,6 @@ className: SuccessCreateMessage::class,

public function testCreateModelWithRelationsRelationStubNotExist()
{
$this->mockFilesystem();

config(['entity-generator.stubs.relation' => 'incorrect_stub']);

app(ModelGenerator::class)
Expand Down
Loading