Skip to content

Commit 4943946

Browse files
committed
Merge remote-tracking branch 'origin/master' into 49-add-repository-generator-tests
2 parents c0e714b + 3b523a6 commit 4943946

21 files changed

+49
-195
lines changed

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', [

tests/ControllerGeneratorTest.php

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

55
use Illuminate\Contracts\Filesystem\FileNotFoundException;
6-
use Illuminate\Support\Facades\Event;
76
use Illuminate\Support\Facades\View;
87
use RonasIT\Support\Events\SuccessCreateMessage;
98
use RonasIT\Support\Events\WarningEvent;
@@ -16,13 +15,6 @@ class ControllerGeneratorTest extends TestCase
1615
{
1716
use ControllerGeneratorMockTrait;
1817

19-
public function setUp(): void
20-
{
21-
parent::setUp();
22-
23-
Event::fake();
24-
}
25-
2618
public function testControllerAlreadyExists()
2719
{
2820
$this->mockClass(ControllerGenerator::class, [

tests/FactoryGeneratorTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ class FactoryGeneratorTest extends TestCase
1414
{
1515
use FactoryMockTrait;
1616

17-
public function setUp(): void
18-
{
19-
parent::setUp();
20-
21-
Event::fake();
22-
}
23-
2417
public function testModelNotExists()
2518
{
2619
$this->assertExceptionThrew(
@@ -57,7 +50,6 @@ className: ClassAlreadyExistsException::class,
5750

5851
public function testProcessUnknownFieldType()
5952
{
60-
$this->mockConfigurations();
6153
$this->mockFilesystem();
6254

6355
$this->assertExceptionThrew(
@@ -81,7 +73,6 @@ className: ViewException::class,
8173

8274
public function testCreateSuccess()
8375
{
84-
$this->mockConfigurations();
8576
$this->mockFilesystem();
8677

8778
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/SeederGeneratorTest.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,13 @@
22

33
namespace RonasIT\Support\Tests;
44

5-
use Illuminate\Support\Facades\Event;
65
use RonasIT\Support\Events\WarningEvent;
76
use RonasIT\Support\Generators\SeederGenerator;
8-
use RonasIT\Support\Tests\Support\SeederGeneratorMockTrait;
97

108
class SeederGeneratorTest extends TestCase
119
{
12-
use SeederGeneratorMockTrait;
13-
14-
public function setUp(): void
15-
{
16-
parent::setUp();
17-
18-
Event::fake();
19-
}
20-
2110
public function testCreateSeeder()
2211
{
23-
$this->mockFilesystem();
24-
2512
app(SeederGenerator::class)
2613
->setRelations([
2714
'hasOne' => [],
@@ -38,8 +25,6 @@ public function testCreateSeeder()
3825

3926
public function testCreateSeederEmptyDatabaseSeederStubNotExist()
4027
{
41-
$this->mockFilesystem();
42-
4328
config(['entity-generator.stubs.database_empty_seeder' => 'entity-generator::database_seed_empty']);
4429

4530
app(SeederGenerator::class)
@@ -63,8 +48,6 @@ className: WarningEvent::class,
6348

6449
public function testCreateSeederEntityDatabaseSeederStubNotExist()
6550
{
66-
$this->mockFilesystem();
67-
6851
config(['entity-generator.stubs.seeder' => 'incorrect_stub']);
6952

7053
app(SeederGenerator::class)

tests/Support/ControllerGeneratorTest/ControllerGeneratorMockTrait.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44

55
use RonasIT\Support\Tests\Support\FileSystemMock;
66
use RonasIT\Support\Tests\Support\GeneratorMockTrait;
7-
use RonasIT\Support\Traits\MockTrait;
87

98
trait ControllerGeneratorMockTrait
109
{
1110
use GeneratorMockTrait;
12-
use MockTrait;
1311

1412
public function mockFilesystemWithoutRoutesFile(): void
1513
{

0 commit comments

Comments
 (0)