Skip to content

Commit 7db7fba

Browse files
authored
Fix factory generation for smallInteger and tinyInteger dataTypes (#257)
1 parent b61770d commit 7db7fba

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

src/Generators/FactoryGenerator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ public static function fakerDataType(string $type)
249249
'unsignedsmallinteger' => 'randomDigitNotNull',
250250
'biginteger' => 'randomNumber()',
251251
'smallint' => 'randomNumber()',
252+
'tinyinteger' => 'randomNumber()',
253+
'smallinteger' => 'randomNumber()',
252254
'decimal' => 'randomFloat(/** decimal_attributes **/)',
253255
'float' => 'randomFloat(/** float_attributes **/)',
254256
'longtext' => 'text',

tests/Feature/Generator/FactoryGeneratorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public function modelTreeDataProvider()
152152
['drafts/unconventional-foreign-key.yaml', 'database/factories/StateFactory.php', 'factories/unconventional-foreign-key.php'],
153153
['drafts/foreign-key-shorthand.yaml', 'database/factories/CommentFactory.php', 'factories/foreign-key-shorthand.php'],
154154
['drafts/resource-statements.yaml', 'database/factories/UserFactory.php', 'factories/resource-statements.php'],
155+
['drafts/factory-smallint-and-tinyint.yaml', 'database/factories/ModelFactory.php', 'factories/factory-smallint-and-tinyint.php'],
155156
];
156157
}
157158
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
models:
2+
Model:
3+
market_type: tinyInteger
4+
deposit: smallInteger unsigned
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
/** @var \Illuminate\Database\Eloquent\Factory $factory */
4+
5+
use App\Model;
6+
use Faker\Generator as Faker;
7+
8+
$factory->define(Model::class, function (Faker $faker) {
9+
return [
10+
'market_type' => $faker->randomNumber(),
11+
'deposit' => $faker->randomNumber(),
12+
];
13+
});

0 commit comments

Comments
 (0)