Skip to content

Commit eaa0be3

Browse files
committed
fix:tests
1 parent b325828 commit eaa0be3

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/Generators/RequestsGenerator.php

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

55
use Illuminate\Support\Arr;
66
use Illuminate\Support\Str;
7-
use RonasIT\Support\DTO\RelationsDTO;
87
use RonasIT\Support\Events\SuccessCreateMessage;
98

109
class RequestsGenerator extends EntityGenerator
@@ -15,6 +14,13 @@ class RequestsGenerator extends EntityGenerator
1514
const DELETE_METHOD = 'Delete';
1615
const GET_METHOD = 'Get';
1716

17+
public function setRelationFields(): array
18+
{
19+
return array_map(function ($field) {
20+
return Str::snake($field) . '_id';
21+
}, $this->relations->belongsTo);
22+
}
23+
1824
public function generate(): void
1925
{
2026
if (!$this->isStubExists('request')) {
@@ -167,7 +173,7 @@ protected function getRules($name, $type, $required, $nullable, $present): array
167173
Arr::get($replaces, $type, $type)
168174
];
169175

170-
if (in_array($name, $this->relations->belongsTo)) {
176+
if (in_array($name, $this->setRelationFields())) {
171177
$tableName = str_replace('_id', '', $name);
172178

173179
$rules[] = "exists:{$this->getTableName($tableName)},id";

tests/FactoryGeneratorTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,10 @@ public function testConfigFolderWithIncorrectCase(): void
139139
'string' => ['title', 'iban', 'something'],
140140
'json' => ['json_text'],
141141
])
142-
->setRelations([
143-
'hasOne' => ['user'],
144-
'hasMany' => [],
145-
'belongsTo' => ['user'],
146-
])
142+
->setRelations(new RelationsDTO(
143+
hasOne: ['user'],
144+
belongsTo: ['user'],
145+
))
147146
->setModel('Post')
148147
->generate();
149148
}

tests/ModelGeneratorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public function testCreateModelWithoutRelationsRelationStubNotExist()
101101

102102
app(ModelGenerator::class)
103103
->setModel('Post')
104+
->setRelations(new RelationsDTO())
104105
->setFields([])
105106
->generate();
106107

0 commit comments

Comments
 (0)