Skip to content

Commit 375e61a

Browse files
committed
Merge remote-tracking branch 'origin/master' into 49-add-service-generator-tests
# Conflicts: # tests/SeederGeneratorTest.php
2 parents da8e50e + 926bbfb commit 375e61a

29 files changed

+67
-269
lines changed

composer.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Generators/EntityGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ abstract class EntityGenerator
2626
protected $paths = [];
2727
protected $model;
2828
protected $fields;
29-
protected $relations;
29+
protected $relations = [];
3030
protected $crudOptions;
3131

3232
/**

src/Generators/ModelGenerator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function generate(): void
2525
);
2626
}
2727

28-
if ($this->isStubExists('model') && (collect($this->relations)->every(fn ($relation) => empty($relation)) || $this->isStubExists('relation', 'model'))) {
28+
if ($this->isStubExists('model') && (!$this->hasRelations() || $this->isStubExists('relation', 'model'))) {
2929
$this->prepareRelatedModels();
3030
$modelContent = $this->getNewModelContent();
3131

@@ -35,6 +35,11 @@ public function generate(): void
3535
}
3636
}
3737

38+
protected function hasRelations(): bool
39+
{
40+
return !collect($this->relations)->every(fn ($relation) => empty($relation));
41+
}
42+
3843
protected function getNewModelContent(): string
3944
{
4045
return $this->getStub('model', [

src/Generators/RepositoryGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function generate(): void
1212
if (!$this->classExists('models', $this->model)) {
1313
$this->throwFailureException(
1414
ClassNotExistsException::class,
15-
"Cannot create {$this->model} Model cause {$this->model} Model does not exists.",
15+
"Cannot create {$this->model}Repository cause {$this->model} Model does not exists.",
1616
"Create a {$this->model} Model by himself or run command 'php artisan make:entity {$this->model} --only-model'."
1717
);
1818
}

tests/FactoryGeneratorTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ className: ClassAlreadyExistsException::class,
5050

5151
public function testProcessUnknownFieldType()
5252
{
53-
$this->mockConfigurations();
5453
$this->mockFilesystem();
5554

5655
$this->assertExceptionThrew(
@@ -74,7 +73,6 @@ className: ViewException::class,
7473

7574
public function testCreateSuccess()
7675
{
77-
$this->mockConfigurations();
7876
$this->mockFilesystem();
7977

8078
app(FactoryGenerator::class)

tests/MigrationGeneratorTest.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@
55
use Illuminate\Support\Carbon;
66
use RonasIT\Support\Exceptions\UnknownFieldTypeException;
77
use RonasIT\Support\Generators\MigrationGenerator;
8-
use RonasIT\Support\Tests\Support\Migration\MigrationMockTrait;
98

109
class MigrationGeneratorTest extends TestCase
1110
{
12-
use MigrationMockTrait;
13-
1411
public function testSetUnknownFieldType()
1512
{
16-
$this->setupConfigurations();
17-
1813
$this->assertExceptionThrew(
1914
className: UnknownFieldTypeException::class,
2015
message: 'Unknown field type unknown-type in MigrationGenerator.',
@@ -39,9 +34,6 @@ public function testCreateMigration()
3934
{
4035
Carbon::setTestNow('2022-02-02');
4136

42-
$this->mockFilesystem();
43-
$this->setupConfigurations();
44-
4537
app(MigrationGenerator::class)
4638
->setModel('Post')
4739
->setRelations([
@@ -67,9 +59,6 @@ public function testCreateMigrationMYSQL()
6759

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

70-
$this->mockFilesystem();
71-
$this->setupConfigurations();
72-
7362
app(MigrationGenerator::class)
7463
->setModel('Post')
7564
->setRelations([

tests/ModelGeneratorTest.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
use RonasIT\Support\Exceptions\ClassNotExistsException;
99
use RonasIT\Support\Generators\ModelGenerator;
1010
use RonasIT\Support\Tests\Support\Model\ModelMockTrait;
11-
use RonasIT\Support\Traits\MockTrait;
1211

1312
class ModelGeneratorTest extends TestCase
1413
{
15-
use ModelMockTrait, MockTrait;
14+
use ModelMockTrait;
1615

1716
public function testModelAlreadyExists()
1817
{
@@ -69,7 +68,7 @@ public function testCreateModel()
6968

7069
$this->assertGeneratedFileEquals('new_model.php', 'app/Models/Post.php');
7170
$this->assertGeneratedFileEquals('comment_relation_model.php', 'app/Models/Comment.php');
72-
$this->assertGeneratedFileEquals('user_relation_model.php', 'app/Models/User.php');
71+
$this->assertGeneratedFileEquals('comment_relation_model.php', 'app/Models/User.php');
7372

7473
$this->assertEventPushed(
7574
className: SuccessCreateMessage::class,
@@ -86,12 +85,6 @@ public function testCreateModelStubNotExist()
8685
app(ModelGenerator::class)
8786
->setModel('Post')
8887
->setFields([])
89-
->setRelations([
90-
'hasOne' => [],
91-
'hasMany' => [],
92-
'belongsTo' => [],
93-
'belongsToMany' => [],
94-
])
9588
->generate();
9689

9790
$this->assertFileDoesNotExist('app/Models/Post.php');
@@ -113,12 +106,6 @@ public function testCreateModelWithoutRelationsRelationStubNotExist()
113106
app(ModelGenerator::class)
114107
->setModel('Post')
115108
->setFields([])
116-
->setRelations([
117-
'hasOne' => [],
118-
'hasMany' => [],
119-
'belongsTo' => [],
120-
'belongsToMany' => [],
121-
])
122109
->generate();
123110

124111
$this->assertGeneratedFileEquals('new_model_without_fields_and_relations.php', 'app/Models/Post.php');

tests/NovaResourceGeneratorTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace RonasIT\Support\Tests;
44

5-
use Illuminate\Support\Facades\Event;
65
use RonasIT\Support\Events\SuccessCreateMessage;
76
use RonasIT\Support\Events\WarningEvent;
87
use RonasIT\Support\Exceptions\ClassAlreadyExistsException;
@@ -14,13 +13,6 @@ class NovaResourceGeneratorTest extends TestCase
1413
{
1514
use NovaResourceGeneratorMockTrait;
1615

17-
public function setUp(): void
18-
{
19-
parent::setUp();
20-
21-
Event::fake();
22-
}
23-
2416
public function testCreateWithMissingNovaPackage()
2517
{
2618
$this->mockNovaServiceProviderExists(false);

tests/NovaTestGeneratorTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace RonasIT\Support\Tests;
44

55
use RonasIT\Support\Tests\Support\Models\WelcomeBonus;
6-
use Illuminate\Support\Facades\Event;
76
use RonasIT\Support\Events\SuccessCreateMessage;
87
use RonasIT\Support\Events\WarningEvent;
98
use RonasIT\Support\Exceptions\ClassAlreadyExistsException;
@@ -58,8 +57,6 @@ className: ClassAlreadyExistsException::class,
5857

5958
public function testNovaTestStubNotExist()
6059
{
61-
Event::fake();
62-
6360
$this->mockNativeGeneratorFunctions(
6461
$this->nativeClassExistsMethodCall([NovaServiceProvider::class, true]),
6562
$this->nativeClassExistsMethodCall([WelcomeBonus::class, true]),
@@ -96,8 +93,6 @@ className: WarningEvent::class,
9693

9794
public function testDumpStubNotExist()
9895
{
99-
Event::fake();
100-
10196
$this->mockNovaServiceProviderExists();
10297

10398
$this->mockFilesystem();
@@ -156,8 +151,6 @@ public function testSuccess()
156151

157152
public function testGenerateNovaPackageNotInstall()
158153
{
159-
Event::fake();
160-
161154
$this->mockNovaServiceProviderExists(false);
162155

163156
app(NovaTestGenerator::class)

tests/RepositoryGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function testModelNotExist()
2020

2121
$this->assertExceptionThrew(
2222
className: ClassNotExistsException::class,
23-
message: "Cannot create Post Model cause Post Model does not exists. "
23+
message: "Cannot create PostRepository cause Post Model does not exists. "
2424
. "Create a Post Model by himself or run command 'php artisan make:entity Post --only-model'.",
2525
);
2626

0 commit comments

Comments
 (0)