Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

34 fix #35

Merged
merged 2 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/generator/default/faker.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@ public function generateModel()
<?php foreach ($model->attributes as $attribute):
if (!$attribute->fakerStub || $attribute->isReference()) {
continue;
} ?>
$model-><?= $attribute->columnName ?> = <?= $attribute->fakerStub ?>;
<?php endforeach; ?><?php /** For foreign referenced
<?php foreach ($model->attributes as $attribute):
if (!$attribute->fakerStub || !$attribute->isReference()) {
continue;
} ?>
}
?>
<?php if($attribute->primary === true && $attribute->phpType === 'int'):?>
//$model-><?= $attribute->columnName ?> = <?= $attribute->fakerStub ?>;
<?php else:?>
$model-><?= $attribute->columnName ?> = <?= $attribute->fakerStub ?>;
<?php endif;?>
<?php endforeach; ?>
**/?>
return $model;
}

Expand All @@ -52,7 +50,7 @@ public static function makeOne(array $attributes, bool $save = false)
{
$model = (new static())->generateModel();
$model->setAttributes($attributes);
if($save === true){
if ($save === true) {
$model->save();
}
return $model;
Expand All @@ -70,7 +68,7 @@ public static function make($number, array $commonAttributes, bool $save = false
if ($number < 1) {
return [];
}
return array_map(function() use ($commonAttributes, $save){
return array_map(function () use ($commonAttributes, $save) {
return static::makeOne($commonAttributes, $save);
}, range(0, $number -1));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/blog/models/CategoryFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function generateModel()
$faker = FakerFactory::create(\Yii::$app->language);
$uniqueFaker = new UniqueGenerator($faker);
$model = new Category();
$model->id = $uniqueFaker->numberBetween(0, 2147483647);
//$model->id = $uniqueFaker->numberBetween(0, 2147483647);
$model->title = substr($faker->sentence, 0, 255);
$model->active = $faker->boolean;
return $model;
Expand All @@ -30,7 +30,7 @@ public static function makeOne(array $attributes, bool $save = false)
{
$model = (new static())->generateModel();
$model->setAttributes($attributes);
if($save === true){
if ($save === true) {
$model->save();
}
return $model;
Expand All @@ -48,7 +48,7 @@ public static function make($number, array $commonAttributes, bool $save = false
if ($number < 1) {
return [];
}
return array_map(function() use ($commonAttributes, $save){
return array_map(function () use ($commonAttributes, $save) {
return static::makeOne($commonAttributes, $save);
}, range(0, $number -1));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/blog/models/CommentFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function generateModel()
$faker = FakerFactory::create(\Yii::$app->language);
$uniqueFaker = new UniqueGenerator($faker);
$model = new Comment();
$model->id = $uniqueFaker->numberBetween(0, 2147483647);
//$model->id = $uniqueFaker->numberBetween(0, 2147483647);
$model->message = [];
$model->created_at = $faker->unixTime;
return $model;
Expand All @@ -30,7 +30,7 @@ public static function makeOne(array $attributes, bool $save = false)
{
$model = (new static())->generateModel();
$model->setAttributes($attributes);
if($save === true){
if ($save === true) {
$model->save();
}
return $model;
Expand All @@ -48,7 +48,7 @@ public static function make($number, array $commonAttributes, bool $save = false
if ($number < 1) {
return [];
}
return array_map(function() use ($commonAttributes, $save){
return array_map(function () use ($commonAttributes, $save) {
return static::makeOne($commonAttributes, $save);
}, range(0, $number -1));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/blog/models/FakerableFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function generateModel()
$faker = FakerFactory::create(\Yii::$app->language);
$uniqueFaker = new UniqueGenerator($faker);
$model = new Fakerable();
$model->id = $uniqueFaker->numberBetween(0, 2147483647);
//$model->id = $uniqueFaker->numberBetween(0, 2147483647);
$model->active = $faker->boolean;
$model->floatval = $faker->randomFloat();
$model->floatval_lim = $faker->randomFloat(null, 0, 1);
Expand Down Expand Up @@ -43,7 +43,7 @@ public static function makeOne(array $attributes, bool $save = false)
{
$model = (new static())->generateModel();
$model->setAttributes($attributes);
if($save === true){
if ($save === true) {
$model->save();
}
return $model;
Expand All @@ -61,7 +61,7 @@ public static function make($number, array $commonAttributes, bool $save = false
if ($number < 1) {
return [];
}
return array_map(function() use ($commonAttributes, $save){
return array_map(function () use ($commonAttributes, $save) {
return static::makeOne($commonAttributes, $save);
}, range(0, $number -1));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/blog/models/PostFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function generateModel()
$faker = FakerFactory::create(\Yii::$app->language);
$uniqueFaker = new UniqueGenerator($faker);
$model = new Post();
$model->uid = $uniqueFaker->numberBetween(0, 2147483647);
//$model->uid = $uniqueFaker->numberBetween(0, 2147483647);
$model->title = substr($faker->sentence, 0, 255);
$model->slug = substr($uniqueFaker->slug, 0, 200);
$model->active = $faker->boolean;
Expand All @@ -32,7 +32,7 @@ public static function makeOne(array $attributes, bool $save = false)
{
$model = (new static())->generateModel();
$model->setAttributes($attributes);
if($save === true){
if ($save === true) {
$model->save();
}
return $model;
Expand All @@ -50,7 +50,7 @@ public static function make($number, array $commonAttributes, bool $save = false
if ($number < 1) {
return [];
}
return array_map(function() use ($commonAttributes, $save){
return array_map(function () use ($commonAttributes, $save) {
return static::makeOne($commonAttributes, $save);
}, range(0, $number -1));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/blog/models/UserFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function generateModel()
$faker = FakerFactory::create(\Yii::$app->language);
$uniqueFaker = new UniqueGenerator($faker);
$model = new User();
$model->id = $uniqueFaker->numberBetween(0, 2147483647);
//$model->id = $uniqueFaker->numberBetween(0, 2147483647);
$model->username = substr($faker->userName, 0, 200);
$model->email = substr($faker->safeEmail, 0, 200);
$model->password = $faker->password;
Expand All @@ -34,7 +34,7 @@ public static function makeOne(array $attributes, bool $save = false)
{
$model = (new static())->generateModel();
$model->setAttributes($attributes);
if($save === true){
if ($save === true) {
$model->save();
}
return $model;
Expand All @@ -52,7 +52,7 @@ public static function make($number, array $commonAttributes, bool $save = false
if ($number < 1) {
return [];
}
return array_map(function() use ($commonAttributes, $save){
return array_map(function () use ($commonAttributes, $save) {
return static::makeOne($commonAttributes, $save);
}, range(0, $number -1));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/blog_v2/models/CategoryFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function generateModel()
$faker = FakerFactory::create(\Yii::$app->language);
$uniqueFaker = new UniqueGenerator($faker);
$model = new Category();
$model->id = $uniqueFaker->numberBetween(0, 2147483647);
//$model->id = $uniqueFaker->numberBetween(0, 2147483647);
$model->title = substr($faker->sentence, 0, 100);
$model->cover = $faker->sentence;
$model->active = $faker->boolean;
Expand All @@ -31,7 +31,7 @@ public static function makeOne(array $attributes, bool $save = false)
{
$model = (new static())->generateModel();
$model->setAttributes($attributes);
if($save === true){
if ($save === true) {
$model->save();
}
return $model;
Expand All @@ -49,7 +49,7 @@ public static function make($number, array $commonAttributes, bool $save = false
if ($number < 1) {
return [];
}
return array_map(function() use ($commonAttributes, $save){
return array_map(function () use ($commonAttributes, $save) {
return static::makeOne($commonAttributes, $save);
}, range(0, $number -1));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/blog_v2/models/CommentFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function generateModel()
$faker = FakerFactory::create(\Yii::$app->language);
$uniqueFaker = new UniqueGenerator($faker);
$model = new Comment();
$model->id = $uniqueFaker->numberBetween(0, 2147483647);
//$model->id = $uniqueFaker->numberBetween(0, 2147483647);
$model->message = $faker->sentence;
$model->created_at = $faker->dateTimeThisYear('now', 'UTC')->format(DATE_ATOM);
return $model;
Expand All @@ -30,7 +30,7 @@ public static function makeOne(array $attributes, bool $save = false)
{
$model = (new static())->generateModel();
$model->setAttributes($attributes);
if($save === true){
if ($save === true) {
$model->save();
}
return $model;
Expand All @@ -48,7 +48,7 @@ public static function make($number, array $commonAttributes, bool $save = false
if ($number < 1) {
return [];
}
return array_map(function() use ($commonAttributes, $save){
return array_map(function () use ($commonAttributes, $save) {
return static::makeOne($commonAttributes, $save);
}, range(0, $number -1));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/blog_v2/models/PostFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function generateModel()
$faker = FakerFactory::create(\Yii::$app->language);
$uniqueFaker = new UniqueGenerator($faker);
$model = new Post();
$model->id = $uniqueFaker->numberBetween(0, 2147483647);
//$model->id = $uniqueFaker->numberBetween(0, 2147483647);
$model->title = substr($faker->sentence, 0, 255);
$model->slug = substr($uniqueFaker->slug, 0, 200);
$model->lang = $faker->randomElement(['ru','eng']);
Expand All @@ -33,7 +33,7 @@ public static function makeOne(array $attributes, bool $save = false)
{
$model = (new static())->generateModel();
$model->setAttributes($attributes);
if($save === true){
if ($save === true) {
$model->save();
}
return $model;
Expand All @@ -51,7 +51,7 @@ public static function make($number, array $commonAttributes, bool $save = false
if ($number < 1) {
return [];
}
return array_map(function() use ($commonAttributes, $save){
return array_map(function () use ($commonAttributes, $save) {
return static::makeOne($commonAttributes, $save);
}, range(0, $number -1));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/blog_v2/models/PostTagFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function generateModel()
$faker = FakerFactory::create(\Yii::$app->language);
$uniqueFaker = new UniqueGenerator($faker);
$model = new PostTag();
$model->id = $uniqueFaker->numberBetween(0, 2147483647);
//$model->id = $uniqueFaker->numberBetween(0, 2147483647);
return $model;
}

Expand All @@ -28,7 +28,7 @@ public static function makeOne(array $attributes, bool $save = false)
{
$model = (new static())->generateModel();
$model->setAttributes($attributes);
if($save === true){
if ($save === true) {
$model->save();
}
return $model;
Expand All @@ -46,7 +46,7 @@ public static function make($number, array $commonAttributes, bool $save = false
if ($number < 1) {
return [];
}
return array_map(function() use ($commonAttributes, $save){
return array_map(function () use ($commonAttributes, $save) {
return static::makeOne($commonAttributes, $save);
}, range(0, $number -1));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/blog_v2/models/TagFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function generateModel()
$faker = FakerFactory::create(\Yii::$app->language);
$uniqueFaker = new UniqueGenerator($faker);
$model = new Tag();
$model->id = $uniqueFaker->numberBetween(0, 2147483647);
//$model->id = $uniqueFaker->numberBetween(0, 2147483647);
$model->name = substr($faker->text(100), 0, 100);
$model->lang = $faker->randomElement(['ru','eng']);
return $model;
Expand All @@ -30,7 +30,7 @@ public static function makeOne(array $attributes, bool $save = false)
{
$model = (new static())->generateModel();
$model->setAttributes($attributes);
if($save === true){
if ($save === true) {
$model->save();
}
return $model;
Expand All @@ -48,7 +48,7 @@ public static function make($number, array $commonAttributes, bool $save = false
if ($number < 1) {
return [];
}
return array_map(function() use ($commonAttributes, $save){
return array_map(function () use ($commonAttributes, $save) {
return static::makeOne($commonAttributes, $save);
}, range(0, $number -1));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/blog_v2/models/UserFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function generateModel()
$faker = FakerFactory::create(\Yii::$app->language);
$uniqueFaker = new UniqueGenerator($faker);
$model = new User();
$model->id = $uniqueFaker->numberBetween(0, 2147483647);
//$model->id = $uniqueFaker->numberBetween(0, 2147483647);
$model->login = $faker->userName;
$model->email = $faker->safeEmail;
$model->password = $faker->password;
Expand All @@ -34,7 +34,7 @@ public static function makeOne(array $attributes, bool $save = false)
{
$model = (new static())->generateModel();
$model->setAttributes($attributes);
if($save === true){
if ($save === true) {
$model->save();
}
return $model;
Expand All @@ -52,7 +52,7 @@ public static function make($number, array $commonAttributes, bool $save = false
if ($number < 1) {
return [];
}
return array_map(function() use ($commonAttributes, $save){
return array_map(function () use ($commonAttributes, $save) {
return static::makeOne($commonAttributes, $save);
}, range(0, $number -1));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/menu/models/MenuFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function generateModel()
$faker = FakerFactory::create(\Yii::$app->language);
$uniqueFaker = new UniqueGenerator($faker);
$model = new Menu();
$model->id = $uniqueFaker->numberBetween(0, 2147483647);
//$model->id = $uniqueFaker->numberBetween(0, 2147483647);
$model->name = substr($faker->text(100), 0, 100);
$model->args = [];
$model->kwargs = [];
Expand All @@ -31,7 +31,7 @@ public static function makeOne(array $attributes, bool $save = false)
{
$model = (new static())->generateModel();
$model->setAttributes($attributes);
if($save === true){
if ($save === true) {
$model->save();
}
return $model;
Expand All @@ -49,7 +49,7 @@ public static function make($number, array $commonAttributes, bool $save = false
if ($number < 1) {
return [];
}
return array_map(function() use ($commonAttributes, $save){
return array_map(function () use ($commonAttributes, $save) {
return static::makeOne($commonAttributes, $save);
}, range(0, $number -1));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/petstore/models/PetFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function generateModel()
$faker = FakerFactory::create(\Yii::$app->language);
$uniqueFaker = new UniqueGenerator($faker);
$model = new Pet();
$model->id = $uniqueFaker->numberBetween(0, 2147483647);
//$model->id = $uniqueFaker->numberBetween(0, 2147483647);
$model->name = $faker->sentence;
$model->tag = $faker->randomElement(['one', 'two', 'three', 'four']);
return $model;
Expand All @@ -30,7 +30,7 @@ public static function makeOne(array $attributes, bool $save = false)
{
$model = (new static())->generateModel();
$model->setAttributes($attributes);
if($save === true){
if ($save === true) {
$model->save();
}
return $model;
Expand All @@ -48,7 +48,7 @@ public static function make($number, array $commonAttributes, bool $save = false
if ($number < 1) {
return [];
}
return array_map(function() use ($commonAttributes, $save){
return array_map(function () use ($commonAttributes, $save) {
return static::makeOne($commonAttributes, $save);
}, range(0, $number -1));
}
Expand Down
Loading