Skip to content

Commit 3c132a3

Browse files
committed
fix: nova model state name in test template
1 parent 2685560 commit 3c132a3

File tree

6 files changed

+89
-89
lines changed

6 files changed

+89
-89
lines changed

src/Generators/NovaTestGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public function generateTests(): void
4747
'url_path' => Str::kebab($this->model) . '-resources',
4848
'entity' => $this->model,
4949
'entities' => $this->getPluralName($this->model),
50-
'lower_entity' => Str::snake($this->model),
51-
'lower_first_entity' => Str::lcfirst($this->model),
50+
'snake_entity' => Str::snake($this->model),
51+
'dromedary_entity' => Str::lcfirst($this->model),
5252
'lower_entities' => $this->getPluralName(Str::snake($this->model)),
5353
'actions' => $actions,
5454
'filters' => $filters,

stubs/nova_test.blade.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ class Nova{{$entity}}Test extends TestCase
1313
use NovaTestTrait;
1414

1515
protected static User $user;
16-
protected static ModelTestState ${{$lower_first_entity}}State;
16+
protected static ModelTestState ${{$dromedary_entity}}State;
1717

1818
public function setUp(): void
1919
{
2020
parent::setUp();
2121

2222
self::$user ??= User::find(1);
23-
self::${{$lower_first_entity}}State ??= new ModelTestState({{$entity}}::class);
23+
self::${{$dromedary_entity}}State ??= new ModelTestState({{$entity}}::class);
2424

2525
$this->skipDocumentationCollecting();
2626
}
2727

2828
public function testCreate(): void
2929
{
30-
$data = $this->getJsonFixture('create_{{$lower_entity}}_request.json');
30+
$data = $this->getJsonFixture('create_{{$snake_entity}}_request.json');
3131

3232
$response = $this->actingAs(self::$user, 'web')->json('post', '/nova-api/{{$url_path}}', $data);
3333

@@ -37,15 +37,15 @@ public function testCreate(): void
3737
$response->assertCreated();
3838
@endif
3939

40-
$this->assertEqualsFixture('create_{{$lower_entity}}_response.json', $response->json());
40+
$this->assertEqualsFixture('create_{{$snake_entity}}_response.json', $response->json());
4141

4242
// TODO: Need to remove after first successful start
43-
self::${{$lower_first_entity}}State->assertChangesEqualsFixture('create_{{$lower_entities}}_state.json', true);
43+
self::${{$dromedary_entity}}State->assertChangesEqualsFixture('create_{{$lower_entities}}_state.json', true);
4444
}
4545

4646
public function testCreateNoAuth(): void
4747
{
48-
$data = $this->getJsonFixture('create_{{$lower_entity}}_request.json');
48+
$data = $this->getJsonFixture('create_{{$snake_entity}}_request.json');
4949

5050
$response = $this->json('post', '/nova-api/{{$url_path}}', $data);
5151

@@ -55,7 +55,7 @@ public function testCreateNoAuth(): void
5555
$response->assertUnauthorized();
5656
@endif
5757

58-
self::${{$lower_first_entity}}State->assertNotChanged();
58+
self::${{$dromedary_entity}}State->assertNotChanged();
5959
}
6060

6161
public function testCreateValidationError(): void
@@ -71,12 +71,12 @@ public function testCreateValidationError(): void
7171
// TODO: Need to remove after first successful start
7272
$this->assertEqualsFixture('create_validation_response.json', $response->json(), true);
7373

74-
self::${{$lower_first_entity}}State->assertNotChanged();
74+
self::${{$dromedary_entity}}State->assertNotChanged();
7575
}
7676

7777
public function testUpdate(): void
7878
{
79-
$data = $this->getJsonFixture('update_{{$lower_entity}}_request.json');
79+
$data = $this->getJsonFixture('update_{{$snake_entity}}_request.json');
8080

8181
$response = $this->actingAs(self::$user, 'web')->json('put', '/nova-api/{{$url_path}}/1', $data);
8282

@@ -87,12 +87,12 @@ public function testUpdate(): void
8787
@endif
8888

8989
// TODO: Need to remove after first successful start
90-
self::${{$lower_first_entity}}State->assertChangesEqualsFixture('update_{{$lower_entities}}_state.json', true);
90+
self::${{$dromedary_entity}}State->assertChangesEqualsFixture('update_{{$lower_entities}}_state.json', true);
9191
}
9292

9393
public function testUpdateNotExists(): void
9494
{
95-
$data = $this->getJsonFixture('update_{{$lower_entity}}_request.json');
95+
$data = $this->getJsonFixture('update_{{$snake_entity}}_request.json');
9696

9797
$response = $this->actingAs(self::$user, 'web')->json('put', '/nova-api/{{$url_path}}/0', $data);
9898

@@ -105,7 +105,7 @@ public function testUpdateNotExists(): void
105105

106106
public function testUpdateNoAuth(): void
107107
{
108-
$data = $this->getJsonFixture('update_{{$lower_entity}}_request.json');
108+
$data = $this->getJsonFixture('update_{{$snake_entity}}_request.json');
109109

110110
$response = $this->json('put', '/nova-api/{{$url_path}}/1', $data);
111111

@@ -157,7 +157,7 @@ public function testDelete(): void
157157
@endif
158158

159159
// TODO: Need to remove after first successful start
160-
self::${{$lower_first_entity}}State->assertChangesEqualsFixture('delete_{{$lower_entities}}_state.json', true);
160+
self::${{$dromedary_entity}}State->assertChangesEqualsFixture('delete_{{$lower_entities}}_state.json', true);
161161
}
162162

163163
public function testDeleteNotExists(): void
@@ -197,7 +197,7 @@ public function testGet(): void
197197
@endif
198198

199199
// TODO: Need to remove after first successful start
200-
$this->assertEqualsFixture('get_{{$lower_entity}}_response.json', $response->json(), true);
200+
$this->assertEqualsFixture('get_{{$snake_entity}}_response.json', $response->json(), true);
201201
}
202202

203203
public function testGetNotExists(): void
@@ -281,7 +281,7 @@ public function testRun{{$entity}}Actions($action, $request, ${{$lower_entities}
281281
$this->assertEmpty($response->getContent());
282282

283283
// TODO: Need to remove after first successful start
284-
self::${{$lower_first_entity}}State->assertChangesEqualsFixture(${{$lower_entities}}StateFixture, true);
284+
self::${{$dromedary_entity}}State->assertChangesEqualsFixture(${{$lower_entities}}StateFixture, true);
285285
}
286286

287287
public function get{{$entity}}ActionsData(): array
@@ -292,7 +292,7 @@ public function get{{$entity}}ActionsData(): array
292292
'request' => [
293293
'resources' => '1,2',
294294
],
295-
'response_fixture' => 'get_{{$lower_entity}}_actions_{{$action['fixture']}}.json',
295+
'response_fixture' => 'get_{{$snake_entity}}_actions_{{$action['fixture']}}.json',
296296
],
297297
@endforeach
298298
];
@@ -323,7 +323,7 @@ public function get{{$entity}}FiltersData(): array
323323
'request' => [
324324
'{{$filter['name']}}' => $this->novaSearchParams(['search term']),
325325
],
326-
'response_fixture' => 'filter_{{$lower_entity}}_by_{{$filter['fixture_name']}}.json',
326+
'response_fixture' => 'filter_{{$snake_entity}}_by_{{$filter['fixture_name']}}.json',
327327
],
328328
@endforeach
329329
];

tests/NovaTestGeneratorTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ public function testCreateNovaTestsResourceNotExists()
2828
$mock = $this->mockClassExistsFunction();
2929

3030
$this->expectException(ClassNotExistsException::class);
31-
$this->expectExceptionMessage("Cannot create NovaPostTest cause Post Nova resource does not exist. Create Post Nova resource.");
31+
$this->expectExceptionMessage("Cannot create NovaSomePostTest cause SomePost Nova resource does not exist. Create SomePost Nova resource.");
3232

3333
$generatorMock = $this->getGeneratorMockForNonExistingNovaResource();
3434

3535
try {
3636
$generatorMock
37-
->setModel('Post')
37+
->setModel('SomePost')
3838
->generate();
3939
} finally {
4040
$mock->disable();
@@ -48,13 +48,13 @@ public function testCreateNovaTestAlreadyExists()
4848
$mock = $this->mockClassExistsFunction();
4949

5050
$this->expectException(ClassAlreadyExistsException::class);
51-
$this->expectExceptionMessage("Cannot create NovaPostTest cause it's already exist. Remove NovaPostTest.");
51+
$this->expectExceptionMessage("Cannot create NovaSomePostTest cause it's already exist. Remove NovaSomePostTest.");
5252

5353
$generatorMock = $this->getGeneratorMockForExistingNovaResourceTest();
5454

5555
try {
5656
$generatorMock
57-
->setModel('Post')
57+
->setModel('SomePost')
5858
->generate();
5959
} finally {
6060
$mock->disable();
@@ -71,16 +71,16 @@ public function testCreateWithActions()
7171
$this->mockNovaResourceTestGenerator();
7272

7373
app(NovaTestGenerator::class)
74-
->setModel('Post')
74+
->setModel('SomePost')
7575
->generate();
7676

7777
$this->rollbackToDefaultBasePath();
7878

79-
$this->assertGeneratedFileEquals('created_resource_test.php', 'tests/NovaPostTest.php');
80-
$this->assertGeneratedFileEquals('dump.sql', 'tests/fixtures/NovaPostTest/nova_post_dump.sql');
81-
$this->assertGeneratedFileEquals('create_post_request.json', 'tests/fixtures/NovaPostTest/create_post_request.json');
82-
$this->assertGeneratedFileEquals('create_post_response.json', 'tests/fixtures/NovaPostTest/create_post_response.json');
83-
$this->assertGeneratedFileEquals('update_post_request.json', 'tests/fixtures/NovaPostTest/update_post_request.json');
79+
$this->assertGeneratedFileEquals('created_resource_test.php', 'tests/NovaSomePostTest.php');
80+
$this->assertGeneratedFileEquals('dump.sql', 'tests/fixtures/NovaSomePostTest/nova_some_post_dump.sql');
81+
$this->assertGeneratedFileEquals('create_post_request.json', 'tests/fixtures/NovaSomePostTest/create_some_post_request.json');
82+
$this->assertGeneratedFileEquals('create_post_response.json', 'tests/fixtures/NovaSomePostTest/create_some_post_response.json');
83+
$this->assertGeneratedFileEquals('update_post_request.json', 'tests/fixtures/NovaSomePostTest/update_some_post_request.json');
8484

8585
$functionMock->disable();
8686
}

tests/Support/NovaTestMockTrait.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,23 @@ public function getGeneratorMockForExistingNovaResourceTest(): MockInterface
8585
$mock
8686
->shouldAllowMockingProtectedMethods()
8787
->shouldReceive('classExists')
88-
->with('nova', 'Post')
88+
->with('nova', 'SomePost')
8989
->andReturn(true);
9090

9191
$mock
9292
->shouldReceive('classExists')
93-
->with('nova', 'PostResource')
93+
->with('nova', 'SomePostResource')
9494
->andReturn(false);
9595

9696
$mock
9797
->shouldReceive('classExists')
98-
->with('nova', 'PostNovaResource')
98+
->with('nova', 'SomePostNovaResource')
9999
->andReturn(false);
100100

101101
$mock
102102
->shouldReceive('classExists')
103103
->once()
104-
->with('nova', 'NovaPostTest')
104+
->with('nova', 'NovaSomePostTest')
105105
->andReturn(true);
106106

107107
return $mock;
@@ -137,20 +137,20 @@ public function mockFilesystem(): void
137137
'app' => [
138138
'Nova' => [
139139
'Actions' => [
140-
'PublishPostAction.php' => '<?php',
141-
'ArchivePostAction.php' => '<?php',
140+
'PublishSomePostAction.php' => '<?php',
141+
'ArchiveSomePostAction.php' => '<?php',
142142
'BlockCommentAction.php' => '<?php',
143-
'UnPublishPostAction.txt' => 'text',
143+
'UnPublishSomePostAction.txt' => 'text',
144144
],
145-
'Post.php' => '<?php',
145+
'SomePost.php' => '<?php',
146146
],
147147
'Models' => [
148-
'Post.php' => '<?php',
148+
'SomePost.php' => '<?php',
149149
]
150150
],
151151
'tests' => [
152152
'fixtures' => [
153-
'NovaPostTest' => [],
153+
'NovaSomePostTest' => [],
154154
]
155155
]
156156
];

0 commit comments

Comments
 (0)