diff --git a/src/Generators/FactoryGenerator.php b/src/Generators/FactoryGenerator.php index 19cec10b..06b719d4 100644 --- a/src/Generators/FactoryGenerator.php +++ b/src/Generators/FactoryGenerator.php @@ -75,7 +75,7 @@ protected function buildDefinition(Model $model) * @var \Blueprint\Models\Column $column */ foreach ($fillable as $column) { - if ($column->name() === 'id') { + if (in_array($column->name(), ['id', 'softdeletes', 'softdeletestz'])) { continue; } @@ -185,6 +185,10 @@ protected function buildDefinition(Model $model) } } + if (empty($definition)) { + return '//'; + } + return trim($definition); } @@ -194,10 +198,15 @@ private function fillableColumns(array $columns): array return $columns; } - return array_filter( + $nonNullableColumns = array_filter( $columns, fn (Column $column) => !in_array('nullable', $column->modifiers()) ); + + return array_filter( + $nonNullableColumns, + fn (Column $column) => $column->dataType() !== 'softDeletes' + ); } private function fullyQualifyModelReference(string $model_name) diff --git a/tests/Feature/Generators/FactoryGeneratorTest.php b/tests/Feature/Generators/FactoryGeneratorTest.php index 3380c73c..f1f93ba5 100644 --- a/tests/Feature/Generators/FactoryGeneratorTest.php +++ b/tests/Feature/Generators/FactoryGeneratorTest.php @@ -5,7 +5,6 @@ use Blueprint\Blueprint; use Blueprint\Generators\FactoryGenerator; use Blueprint\Tree; -use Illuminate\Support\Facades\App; use Tests\TestCase; /** @@ -215,6 +214,7 @@ public function modelTreeDataProvider() ['drafts/resource-statements.yaml', 'database/factories/UserFactory.php', 'factories/resource-statements.php'], ['drafts/factory-smallint-and-tinyint.yaml', 'database/factories/ModelFactory.php', 'factories/factory-smallint-and-tinyint.php'], ['drafts/all-column-types.yaml', 'database/factories/AllTypeFactory.php', 'factories/all-column-types.php'], + ['drafts/shorthands.yaml', 'database/factories/NameFactory.php', 'factories/shorthands.php'], ]; } } diff --git a/tests/fixtures/factories/shorthands.php b/tests/fixtures/factories/shorthands.php new file mode 100644 index 00000000..c60a3386 --- /dev/null +++ b/tests/fixtures/factories/shorthands.php @@ -0,0 +1,29 @@ +