diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 462cb33e..7e51029d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3'] + php-versions: ['8.0', '8.1', '8.2', '8.3'] steps: - uses: actions/checkout@v3 @@ -60,7 +60,7 @@ jobs: run: make UID=0 migrate - name: Check style - if: "!contains(matrix.php-versions, '8.')" + if: "matrix.php-versions == '8.0'" run: make check-style-from-host - name: Run tests diff --git a/composer.json b/composer.json index 115ef883..2b269165 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "source": "https://github.com/cebe/yii2-openapi" }, "require": { - "php": "^7.4 || ^8.0", + "php": "^8.0", "cebe/php-openapi": "^1.7.0", "yiisoft/yii2": "~2.0.48", "yiisoft/yii2-gii": "~2.0.0 | ~2.1.0 | ~2.2.0| ~2.3.0", diff --git a/src/lib/FakerStubResolver.php b/src/lib/FakerStubResolver.php index 97051145..e140bba8 100644 --- a/src/lib/FakerStubResolver.php +++ b/src/lib/FakerStubResolver.php @@ -120,16 +120,37 @@ public function resolve(): ?string return null; } - if (!$this->property->hasAttr('example') || + // No optional wrapping for required/non-nullable fields without an example (always generate a real value), + // or for unique-items fields (optional fallback would break uniqueness). + if ( + (($this->attribute->isRequired() || $this->attribute->nullable === false) && !$this->property->hasAttr('example')) || $this->property->getAttr('uniqueItems') ) { + if ($this->attribute->phpType === 'string' && $this->attribute->size) { + return 'substr(' . $result . ', 0, '.$this->attribute->size.')'; + } return $result; } $example = $this->property->getAttr('example'); $example = VarExporter::export($example); $example = preg_replace('/\n/', "\n ", $example); - return str_replace('$faker->', '$faker->optional(0.92, ' . $example . ')->', $result); + + /** + * $example must be the exact value that goes into the DB column, e.g. '2020-03-14 21:42:17' + * for a datetime column — not a DateTime object or ISO string with timezone offset. + * optional() without a default returns null on miss; all -> are made nullsafe so the whole + * chain collapses to null, then ?? $example inserts the ready-to-store fallback value. + * + * Negative lookbehind prevents turning an existing ?-> into ??-> + */ + $wrapped = str_replace('$faker?->', '$faker->optional(0.92)->', preg_replace('/(?/', '?->', $result)); + + if ($this->attribute->phpType === 'string' && $this->attribute->size) { + return 'is_string($s = ' . $wrapped . ') ? substr($s, 0, '.$this->attribute->size.') : ' . $example; + } + + return $wrapped . ' ?? ' . $example; } private function fakeForString(): ?string @@ -161,8 +182,7 @@ private function fakeForString(): ?string return '$faker->title'; } if ($this->attribute->primary || $this->attribute->isReference()) { - $size = $this->attribute->size ?? 255; - return 'substr($uniqueFaker->sha256, 0, ' . $size . ')'; + return '$uniqueFaker->sha256'; } $patterns = [ @@ -197,22 +217,19 @@ private function fakeForString(): ?string '~(url|site|website|href)~i' => '$faker->url', '~(username|login)~i' => '$faker->userName', ]; - $size = $this->attribute->size > 0 ? $this->attribute->size : null; foreach ($patterns as $pattern => $fake) { if (preg_match($pattern, $this->attribute->columnName)) { - if ($size) { - return 'substr(' . $fake . ', 0, ' . $size . ')'; - } return $fake; } } + $size = $this->attribute->size > 0 ? $this->attribute->size : null; if ($size) { $method = 'text'; if ($size < 5) { $method = 'word'; } - return 'substr($faker->' . $method . '(' . $size . '), 0, ' . $size . ')'; + return '$faker->' . $method . '(' . $size . ')'; } return '$faker->sentence'; } @@ -389,10 +406,8 @@ private function reindentArrayMapForObject(string $code, int $depth): string } [$body, $count] = [$m[1], $m[2]]; - // For nested array_map: wrapInArray places the inner return at 12 spaces and the inner closing - // brace at 8 spaces. We want the inner return at bodyIndent+4 and the inner brace at bodyIndent, - // so the shift is bodyIndent - 8. For simple (non-nested) bodies the shift is bodyIndent - 12. - $shift = strlen($bodyIndent) - (str_starts_with($body, 'return array_map(') ? 8 : 12); + // wrapInArray shifts nested array_map bodies by 4 spaces, so all bodies now start at 12 spaces. + $shift = strlen($bodyIndent) - 12; if ($shift > 0) { $body = preg_replace('/\n/', "\n" . str_repeat(' ', $shift), $body); } @@ -443,8 +458,14 @@ public function handleOneOf(SpecObjectInterface $items, int $count): string public function wrapInArray(string $aFaker, bool $uniqueItems, int $count, bool $oneOf = false): string { $ret = $oneOf ? '' : 'return '; + $inner = $uniqueItems ? str_replace('$faker->', '$uniqueFaker->', $aFaker) : $aFaker; + // Only shift when the inner value is itself a nested array_map; + // handleOneOf and fakeForObject results already carry correct indentation + if (str_starts_with($inner, 'array_map(') && str_contains($inner, PHP_EOL)) { + $inner = str_replace(PHP_EOL, PHP_EOL . ' ', $inner); + } return 'array_map(function () use ($faker, $uniqueFaker) { - ' . $ret . ($uniqueItems ? str_replace('$faker->', '$uniqueFaker->', $aFaker) : $aFaker) . '; + ' . $ret . $inner . '; }, range(1, ' . $count . '))'; } diff --git a/src/lib/migrations/BaseMigrationBuilder.php b/src/lib/migrations/BaseMigrationBuilder.php index ded9a7af..a4b40a66 100644 --- a/src/lib/migrations/BaseMigrationBuilder.php +++ b/src/lib/migrations/BaseMigrationBuilder.php @@ -380,6 +380,7 @@ protected function buildRelations():void $this->migration->dependencies[] = $refTable; } } + ksort($existedRelations); foreach ($existedRelations as $fkName => $relation) { ['fkCol' => $fkCol, 'refCol' => $refCol, 'refTable' => $refTable] = $relation; $this->migration @@ -414,6 +415,7 @@ protected function buildRelationsForJunction(ManyToManyRelation $relation):void $this->migration->dependencies[] = $refTable; } } + ksort($existedRelations); foreach ($existedRelations as $fkName => $rel) { ['fkCol' => $fkCol, 'refCol' => $refCol, 'refTable' => $refTable] = $rel; $this->migration diff --git a/tests/fixtures/blog.php b/tests/fixtures/blog.php index 7fe3d122..793ab948 100644 --- a/tests/fixtures/blog.php +++ b/tests/fixtures/blog.php @@ -24,9 +24,9 @@ ->setDefault('reader') ->setFakerStub('$faker->randomElement([\'admin\', \'editor\', \'reader\'])'), 'flags' => (new Attribute('flags', ['phpType'=>'int', 'dbType'=>'integer']))->setDefault(0)->setFakerStub - ('$faker->numberBetween(0, 1000000)'), + ('$faker->optional(0.92)->numberBetween(0, 1000000) ?? null'), 'created_at' => (new Attribute('created_at', ['phpType' => 'string', 'dbType' => 'datetime'])) - ->setDefault(new \yii\db\Expression('(CURRENT_TIMESTAMP)'))->setFakerStub('$faker->dateTimeThisYear(\'now\', \'UTC\')->format(\'Y-m-d H:i:s\')'), + ->setDefault(new \yii\db\Expression('(CURRENT_TIMESTAMP)'))->setFakerStub('$faker->optional(0.92)->dateTimeThisYear(\'now\', \'UTC\')?->format(\'Y-m-d H:i:s\') ?? null'), ], 'relations' => [], 'indexes' => [ @@ -66,7 +66,7 @@ 'title' => (new Attribute('title', ['phpType' => 'string', 'dbType' => 'string'])) ->setRequired()->setSize(255)->setFakerStub('substr($faker->sentence, 0, 255)'), 'slug' => (new Attribute('slug', ['phpType' => 'string', 'dbType' => 'string'])) - ->setSize(200)->setLimits(null, null, 1)->setFakerStub('substr($uniqueFaker->slug, 0, 200)'), + ->setSize(200)->setLimits(null, null, 1)->setFakerStub('is_string($s = $uniqueFaker?->slug) ? substr($s, 0, 200) : null'), 'active' => (new Attribute('active', ['phpType' => 'bool', 'dbType' => 'boolean'])) ->setRequired()->setDefault(false)->setFakerStub('$faker->boolean'), 'category' => (new Attribute('category', ['phpType' => 'int', 'dbType' => 'integer'])) @@ -75,7 +75,7 @@ ->setDescription('Category of posts') ->setFakerStub('$faker->randomElement(\app\models\Category::find()->select("id")->column())'), 'created_at' => (new Attribute('created_at', ['phpType' => 'string', 'dbType' => 'date'])) - ->setFakerStub('$faker->dateTimeThisCentury->format(\'Y-m-d\')'), + ->setFakerStub('$faker->optional(0.92)->dateTimeThisCentury?->format(\'Y-m-d\') ?? null'), 'created_by' => (new Attribute('created_by', ['phpType' => 'int', 'dbType' => 'integer'])) ->asReference('User') ->setDescription('The User') diff --git a/tests/specs/blog.yaml b/tests/specs/blog.yaml index 4da49119..43bd973a 100644 --- a/tests/specs/blog.yaml +++ b/tests/specs/blog.yaml @@ -236,9 +236,17 @@ components: str_date: type: string format: date + str_date_ex: + type: string + format: date + example: '2020-03-14' str_datetime: type: string format: date-time + str_datetime_ex: + type: string + format: date-time + example: '2020-03-14 21:42:17' str_country: type: string Error: diff --git a/tests/specs/blog/migrations/m200000_000003_create_table_fakerable.php b/tests/specs/blog/migrations/m200000_000003_create_table_fakerable.php index 0f3eebad..404ed1c7 100644 --- a/tests/specs/blog/migrations/m200000_000003_create_table_fakerable.php +++ b/tests/specs/blog/migrations/m200000_000003_create_table_fakerable.php @@ -21,7 +21,9 @@ public function up() 'str_text' => $this->text()->null(), 'str_varchar' => $this->string(100)->null()->defaultValue(null), 'str_date' => $this->date()->null()->defaultValue(null), + 'str_date_ex' => $this->date()->null()->defaultValue(null), 'str_datetime' => $this->timestamp()->null()->defaultValue(null), + 'str_datetime_ex' => $this->timestamp()->null()->defaultValue(null), 'str_country' => $this->text()->null(), ]); } diff --git a/tests/specs/blog/migrations_maria_db/m200000_000003_create_table_fakerable.php b/tests/specs/blog/migrations_maria_db/m200000_000003_create_table_fakerable.php index 84f6247c..a8772cc2 100644 --- a/tests/specs/blog/migrations_maria_db/m200000_000003_create_table_fakerable.php +++ b/tests/specs/blog/migrations_maria_db/m200000_000003_create_table_fakerable.php @@ -21,7 +21,9 @@ public function up() 'str_text' => $this->text()->null()->defaultValue(null), 'str_varchar' => $this->string(100)->null()->defaultValue(null), 'str_date' => $this->date()->null()->defaultValue(null), + 'str_date_ex' => $this->date()->null()->defaultValue(null), 'str_datetime' => $this->timestamp()->null()->defaultValue(null), + 'str_datetime_ex' => $this->timestamp()->null()->defaultValue(null), 'str_country' => $this->text()->null()->defaultValue(null), ]); } diff --git a/tests/specs/blog/migrations_mysql_db/m200000_000003_create_table_fakerable.php b/tests/specs/blog/migrations_mysql_db/m200000_000003_create_table_fakerable.php index 0f3eebad..404ed1c7 100644 --- a/tests/specs/blog/migrations_mysql_db/m200000_000003_create_table_fakerable.php +++ b/tests/specs/blog/migrations_mysql_db/m200000_000003_create_table_fakerable.php @@ -21,7 +21,9 @@ public function up() 'str_text' => $this->text()->null(), 'str_varchar' => $this->string(100)->null()->defaultValue(null), 'str_date' => $this->date()->null()->defaultValue(null), + 'str_date_ex' => $this->date()->null()->defaultValue(null), 'str_datetime' => $this->timestamp()->null()->defaultValue(null), + 'str_datetime_ex' => $this->timestamp()->null()->defaultValue(null), 'str_country' => $this->text()->null(), ]); } diff --git a/tests/specs/blog/migrations_pgsql_db/m200000_000003_create_table_fakerable.php b/tests/specs/blog/migrations_pgsql_db/m200000_000003_create_table_fakerable.php index a42b8954..9f42f694 100644 --- a/tests/specs/blog/migrations_pgsql_db/m200000_000003_create_table_fakerable.php +++ b/tests/specs/blog/migrations_pgsql_db/m200000_000003_create_table_fakerable.php @@ -21,7 +21,9 @@ public function safeUp() 'str_text' => $this->text()->null()->defaultValue(null), 'str_varchar' => $this->string(100)->null()->defaultValue(null), 'str_date' => $this->date()->null()->defaultValue(null), + 'str_date_ex' => $this->date()->null()->defaultValue(null), 'str_datetime' => $this->timestamp()->null()->defaultValue(null), + 'str_datetime_ex' => $this->timestamp()->null()->defaultValue(null), 'str_country' => $this->text()->null()->defaultValue(null), ]); } diff --git a/tests/specs/blog/models/FakerableFaker.php b/tests/specs/blog/models/FakerableFaker.php index 8f7b1cf0..b7cfffab 100644 --- a/tests/specs/blog/models/FakerableFaker.php +++ b/tests/specs/blog/models/FakerableFaker.php @@ -29,21 +29,23 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new Fakerable(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->active = $faker->boolean; - $model->floatval = $faker->randomFloat(); - $model->floatval_lim = $faker->randomFloat(null, 0, 1); - $model->doubleval = $faker->randomFloat(); - $model->int_min = $faker->numberBetween(5, 1000000); - $model->int_max = $faker->numberBetween(0, 5); - $model->int_minmax = $faker->numberBetween(5, 25); - $model->int_created_at = $faker->unixTime; - $model->int_simple = $faker->numberBetween(0, 1000000); - $model->str_text = $faker->sentence; - $model->str_varchar = substr($faker->text(100), 0, 100); - $model->str_date = $faker->dateTimeThisCentury->format('Y-m-d'); - $model->str_datetime = $faker->dateTimeThisYear('now', 'UTC')->format('Y-m-d H:i:s'); - $model->str_country = $faker->countryCode; + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; + $model->active = $faker->optional(0.92)->boolean ?? null; + $model->floatval = $faker->optional(0.92)->randomFloat() ?? null; + $model->floatval_lim = $faker->optional(0.92)->randomFloat(null, 0, 1) ?? null; + $model->doubleval = $faker->optional(0.92)->randomFloat() ?? null; + $model->int_min = $faker->optional(0.92)->numberBetween(5, 1000000) ?? null; + $model->int_max = $faker->optional(0.92)->numberBetween(0, 5) ?? null; + $model->int_minmax = $faker->optional(0.92)->numberBetween(5, 25) ?? null; + $model->int_created_at = $faker->optional(0.92)->unixTime ?? null; + $model->int_simple = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->str_text = $faker->optional(0.92)->sentence ?? null; + $model->str_varchar = is_string($s = $faker->optional(0.92)->text(100)) ? substr($s, 0, 100) : null; + $model->str_date = $faker->optional(0.92)->dateTimeThisCentury?->format('Y-m-d') ?? null; + $model->str_date_ex = $faker->optional(0.92)->dateTimeThisCentury?->format('Y-m-d') ?? '2020-03-14'; + $model->str_datetime = $faker->optional(0.92)->dateTimeThisYear('now', 'UTC')?->format('Y-m-d H:i:s') ?? null; + $model->str_datetime_ex = $faker->optional(0.92)->dateTimeThisYear('now', 'UTC')?->format('Y-m-d H:i:s') ?? '2020-03-14 21:42:17'; + $model->str_country = $faker->optional(0.92)->countryCode ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/blog/models/PostFaker.php b/tests/specs/blog/models/PostFaker.php index 946a284f..7bf9fab6 100644 --- a/tests/specs/blog/models/PostFaker.php +++ b/tests/specs/blog/models/PostFaker.php @@ -31,10 +31,10 @@ public function generateModel($attributes = []) $model = new Post(); $model->uid = substr($uniqueFaker->sha256, 0, 128); $model->title = substr($faker->sentence, 0, 255); - $model->slug = substr($uniqueFaker->slug, 0, 200); + $model->slug = is_string($s = $uniqueFaker?->slug) ? substr($s, 0, 200) : null; $model->category_id = $faker->randomElement(\app\models\Category::find()->select("id")->column()); $model->active = $faker->boolean; - $model->created_at = $faker->dateTimeThisCentury->format('Y-m-d'); + $model->created_at = $faker->optional(0.92)->dateTimeThisCentury?->format('Y-m-d') ?? null; $model->created_by_id = $faker->randomElement(\app\models\User::find()->select("id")->column()); if (!is_callable($attributes)) { $model->setAttributes($attributes, false); diff --git a/tests/specs/blog/models/UserFaker.php b/tests/specs/blog/models/UserFaker.php index 5ea4f541..db7a22d1 100644 --- a/tests/specs/blog/models/UserFaker.php +++ b/tests/specs/blog/models/UserFaker.php @@ -34,8 +34,8 @@ public function generateModel($attributes = []) $model->email = substr($faker->safeEmail, 0, 200); $model->password = $faker->password; $model->role = $faker->randomElement(['admin', 'editor', 'reader']); - $model->flags = $faker->numberBetween(0, 1000000); - $model->created_at = $faker->dateTimeThisYear('now', 'UTC')->format('Y-m-d H:i:s'); + $model->flags = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->created_at = $faker->optional(0.92)->dateTimeThisYear('now', 'UTC')?->format('Y-m-d H:i:s') ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/blog/models/base/Fakerable.php b/tests/specs/blog/models/base/Fakerable.php index 9ba7a049..64ee5f3c 100644 --- a/tests/specs/blog/models/base/Fakerable.php +++ b/tests/specs/blog/models/base/Fakerable.php @@ -22,7 +22,9 @@ * @property string $str_text * @property string $str_varchar * @property string $str_date + * @property string $str_date_ex * @property string $str_datetime + * @property string $str_datetime_ex * @property string $str_country * */ @@ -36,7 +38,7 @@ public static function tableName() public function rules() { return [ - 'trim' => [['str_text', 'str_varchar', 'str_date', 'str_datetime', 'str_country'], 'trim'], + 'trim' => [['str_text', 'str_varchar', 'str_date', 'str_date_ex', 'str_datetime', 'str_datetime_ex', 'str_country'], 'trim'], 'int_min_default' => [['int_min'], 'default', 'value' => 3], 'active_boolean' => [['active'], 'boolean'], 'floatval_double' => [['floatval'], 'double'], @@ -50,7 +52,9 @@ public function rules() 'str_text_string' => [['str_text'], 'string'], 'str_varchar_string' => [['str_varchar'], 'string', 'max' => 100], 'str_date_date' => [['str_date'], 'date', 'format' => 'php:Y-m-d'], + 'str_date_ex_date' => [['str_date_ex'], 'date', 'format' => 'php:Y-m-d'], 'str_datetime_datetime' => [['str_datetime'], 'datetime', 'format' => 'php:Y-m-d H:i:s'], + 'str_datetime_ex_datetime' => [['str_datetime_ex'], 'datetime', 'format' => 'php:Y-m-d H:i:s'], 'str_country_string' => [['str_country'], 'string'], ]; } diff --git a/tests/specs/blog_v2/migrations_pgsql_db/m200000_000005_change_table_v2_comments.php b/tests/specs/blog_v2/migrations_pgsql_db/m200000_000005_change_table_v2_comments.php index e9ad9ff5..43d9d465 100644 --- a/tests/specs/blog_v2/migrations_pgsql_db/m200000_000005_change_table_v2_comments.php +++ b/tests/specs/blog_v2/migrations_pgsql_db/m200000_000005_change_table_v2_comments.php @@ -7,8 +7,8 @@ class m200000_000005_change_table_v2_comments extends \yii\db\Migration { public function safeUp() { - $this->dropForeignKey('fk_v2_comments_author_id_v2_users_id', '{{%v2_comments}}'); $this->dropForeignKey('fk_v2_comments_post_id_v2_posts_uid', '{{%v2_comments}}'); + $this->dropForeignKey('fk_v2_comments_author_id_v2_users_id', '{{%v2_comments}}'); $this->addColumn('{{%v2_comments}}', 'user_id', $this->bigInteger()->null()->defaultValue(null)->comment('The User')); $this->dropColumn('{{%v2_comments}}', 'author_id'); $this->alterColumn('{{%v2_comments}}', 'message', 'text NOT NULL USING "message"::text'); @@ -33,7 +33,7 @@ public function safeDown() $this->alterColumn('{{%v2_comments}}', 'message', "SET DEFAULT '[]'"); $this->alterColumn('{{%v2_comments}}', 'meta_data', "SET NOT NULL"); $this->alterColumn('{{%v2_comments}}', 'meta_data', "SET DEFAULT '[]'"); - $this->addForeignKey('fk_v2_comments_post_id_v2_posts_uid', '{{%v2_comments}}', 'post_id', 'itt_v2_posts', 'uid'); $this->addForeignKey('fk_v2_comments_author_id_v2_users_id', '{{%v2_comments}}', 'author_id', 'itt_v2_users', 'id'); + $this->addForeignKey('fk_v2_comments_post_id_v2_posts_uid', '{{%v2_comments}}', 'post_id', 'itt_v2_posts', 'uid'); } } diff --git a/tests/specs/blog_v2/models/CommentFaker.php b/tests/specs/blog_v2/models/CommentFaker.php index 68535e74..02a1f443 100644 --- a/tests/specs/blog_v2/models/CommentFaker.php +++ b/tests/specs/blog_v2/models/CommentFaker.php @@ -33,7 +33,7 @@ public function generateModel($attributes = []) $model->post_id = $faker->randomElement(\app\models\Post::find()->select("id")->column()); $model->user_id = $faker->randomElement(\app\models\User::find()->select("id")->column()); $model->message = $faker->sentence; - $model->meta_data = substr($faker->optional(0.92, 'type==\'ticket\' && status==\'closed\'')->text(300), 0, 300); + $model->meta_data = is_string($s = $faker->optional(0.92)->text(300)) ? substr($s, 0, 300) : 'type==\'ticket\' && status==\'closed\''; $model->created_at = $faker->dateTimeThisYear('now', 'UTC')->format('Y-m-d H:i:s'); if (!is_callable($attributes)) { $model->setAttributes($attributes, false); diff --git a/tests/specs/blog_v2/models/PostFaker.php b/tests/specs/blog_v2/models/PostFaker.php index 8238bfb4..3ad808cb 100644 --- a/tests/specs/blog_v2/models/PostFaker.php +++ b/tests/specs/blog_v2/models/PostFaker.php @@ -31,11 +31,11 @@ public function generateModel($attributes = []) $model = new Post(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); $model->title = substr($faker->sentence, 0, 255); - $model->slug = substr($uniqueFaker->slug, 0, 200); - $model->lang = $faker->randomElement(['ru','eng']); + $model->slug = is_string($s = $uniqueFaker?->slug) ? substr($s, 0, 200) : null; + $model->lang = $faker->optional(0.92)->randomElement(['ru','eng']) ?? null; $model->category_id = $faker->randomElement(\app\models\Category::find()->select("id")->column()); $model->active = $faker->boolean; - $model->created_at = $faker->dateTimeThisCentury->format('Y-m-d'); + $model->created_at = $faker->optional(0.92)->dateTimeThisCentury?->format('Y-m-d') ?? null; $model->created_by_id = $faker->randomElement(\app\models\User::find()->select("id")->column()); if (!is_callable($attributes)) { $model->setAttributes($attributes, false); diff --git a/tests/specs/blog_v2/models/UserFaker.php b/tests/specs/blog_v2/models/UserFaker.php index 3e3980e7..2ef78221 100644 --- a/tests/specs/blog_v2/models/UserFaker.php +++ b/tests/specs/blog_v2/models/UserFaker.php @@ -34,8 +34,8 @@ public function generateModel($attributes = []) $model->email = substr($faker->safeEmail, 0, 255); $model->password = $faker->password; $model->role = $faker->randomElement(['admin', 'editor', 'reader']); - $model->flags = $faker->numberBetween(0, 1000000); - $model->created_at = $faker->dateTimeThisYear('now', 'UTC')->format('Y-m-d H:i:s'); + $model->flags = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->created_at = $faker->optional(0.92)->dateTimeThisYear('now', 'UTC')?->format('Y-m-d H:i:s') ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/fk_col_name/app/models/DeliveryFaker.php b/tests/specs/fk_col_name/app/models/DeliveryFaker.php index a0227d1a..af7db069 100644 --- a/tests/specs/fk_col_name/app/models/DeliveryFaker.php +++ b/tests/specs/fk_col_name/app/models/DeliveryFaker.php @@ -30,7 +30,7 @@ public function generateModel($attributes = []) $uniqueFaker = $this->uniqueFaker; $model = new Delivery(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->title = $faker->sentence; + $model->title = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/fk_col_name/app/models/WebhookFaker.php b/tests/specs/fk_col_name/app/models/WebhookFaker.php index 061e20e5..cb52e349 100644 --- a/tests/specs/fk_col_name/app/models/WebhookFaker.php +++ b/tests/specs/fk_col_name/app/models/WebhookFaker.php @@ -29,8 +29,8 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new Webhook(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->sentence; + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; + $model->name = $faker->optional(0.92)->sentence ?? null; $model->user_id = $faker->randomElement(\app\models\User::find()->select("id")->column()); $model->redelivery_of = $faker->randomElement(\app\models\Delivery::find()->select("id")->column()); if (!is_callable($attributes)) { diff --git a/tests/specs/fk_col_name_index/app/models/DeliveryFaker.php b/tests/specs/fk_col_name_index/app/models/DeliveryFaker.php index a0227d1a..af7db069 100644 --- a/tests/specs/fk_col_name_index/app/models/DeliveryFaker.php +++ b/tests/specs/fk_col_name_index/app/models/DeliveryFaker.php @@ -30,7 +30,7 @@ public function generateModel($attributes = []) $uniqueFaker = $this->uniqueFaker; $model = new Delivery(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->title = $faker->sentence; + $model->title = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/fk_col_name_index/app/models/WebhookFaker.php b/tests/specs/fk_col_name_index/app/models/WebhookFaker.php index 11a768a1..23ede003 100644 --- a/tests/specs/fk_col_name_index/app/models/WebhookFaker.php +++ b/tests/specs/fk_col_name_index/app/models/WebhookFaker.php @@ -29,8 +29,8 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new Webhook(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = substr($faker->text(255), 0, 255); + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; + $model->name = is_string($s = $faker->optional(0.92)->text(255)) ? substr($s, 0, 255) : null; $model->user_id = $faker->randomElement(\app\models\User::find()->select("id")->column()); $model->redelivery_of = $faker->randomElement(\app\models\Delivery::find()->select("id")->column()); $model->rd_abc_2 = $faker->randomElement(\app\models\Delivery::find()->select("id")->column()); diff --git a/tests/specs/id_not_in_rules/app/models/PostFaker.php b/tests/specs/id_not_in_rules/app/models/PostFaker.php index 1ceec66b..9e63070d 100644 --- a/tests/specs/id_not_in_rules/app/models/PostFaker.php +++ b/tests/specs/id_not_in_rules/app/models/PostFaker.php @@ -29,8 +29,8 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new Post(); - $model->uid = substr($uniqueFaker->sha256, 0, 255); - $model->title = $faker->sentence; + $model->uid = $uniqueFaker?->sha256 ?? null; + $model->title = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/158_bug_giiapi_generated_rules_enum_with_trim/maria/models/MailingFaker.php b/tests/specs/issue_fix/158_bug_giiapi_generated_rules_enum_with_trim/maria/models/MailingFaker.php index 25e1a71b..4e338f49 100644 --- a/tests/specs/issue_fix/158_bug_giiapi_generated_rules_enum_with_trim/maria/models/MailingFaker.php +++ b/tests/specs/issue_fix/158_bug_giiapi_generated_rules_enum_with_trim/maria/models/MailingFaker.php @@ -31,7 +31,7 @@ public function generateModel($attributes = []) $model = new Mailing(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); $model->name = substr($faker->text(128), 0, 128); - $model->paymentMethodName = $faker->randomElement(['card','cash','ewallet']); + $model->paymentMethodName = $faker->optional(0.92)->randomElement(['card','cash','ewallet']) ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/159_bug_giiapi_generated_rules_emailid/maria/models/ContactFaker.php b/tests/specs/issue_fix/159_bug_giiapi_generated_rules_emailid/maria/models/ContactFaker.php index 75604ea2..143648c3 100644 --- a/tests/specs/issue_fix/159_bug_giiapi_generated_rules_emailid/maria/models/ContactFaker.php +++ b/tests/specs/issue_fix/159_bug_giiapi_generated_rules_emailid/maria/models/ContactFaker.php @@ -31,8 +31,8 @@ public function generateModel($attributes = []) $model = new Contact(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); $model->mailing_id = $faker->randomElement(\app\models\Mailing::find()->select("id")->column()); - $model->active = $faker->boolean; - $model->nickname = $faker->sentence; + $model->active = $faker->optional(0.92)->boolean ?? null; + $model->nickname = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/159_bug_giiapi_generated_rules_emailid/maria/models/MailingFaker.php b/tests/specs/issue_fix/159_bug_giiapi_generated_rules_emailid/maria/models/MailingFaker.php index 1cd0a3f2..583a096f 100644 --- a/tests/specs/issue_fix/159_bug_giiapi_generated_rules_emailid/maria/models/MailingFaker.php +++ b/tests/specs/issue_fix/159_bug_giiapi_generated_rules_emailid/maria/models/MailingFaker.php @@ -31,7 +31,7 @@ public function generateModel($attributes = []) $model = new Mailing(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); $model->name = substr($faker->text(128), 0, 128); - $model->paymentMethodName = $faker->sentence; + $model->paymentMethodName = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/162_bug_dollarref_with_x_faker/app/models/OrderFaker.php b/tests/specs/issue_fix/162_bug_dollarref_with_x_faker/app/models/OrderFaker.php index 0fca8d6c..d32dfebc 100644 --- a/tests/specs/issue_fix/162_bug_dollarref_with_x_faker/app/models/OrderFaker.php +++ b/tests/specs/issue_fix/162_bug_dollarref_with_x_faker/app/models/OrderFaker.php @@ -30,7 +30,7 @@ public function generateModel($attributes = []) $uniqueFaker = $this->uniqueFaker; $model = new Order(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->sentence; + $model->name = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/AccountFaker.php b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/AccountFaker.php index 0b5284d5..0ea53f96 100644 --- a/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/AccountFaker.php +++ b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/AccountFaker.php @@ -31,7 +31,7 @@ public function generateModel($attributes = []) $model = new Account(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); $model->name = substr($faker->text(128), 0, 128); - $model->paymentMethodName = $faker->sentence; + $model->paymentMethodName = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/ContactFaker.php b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/ContactFaker.php index c1a4a88f..909d7c6b 100644 --- a/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/ContactFaker.php +++ b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/ContactFaker.php @@ -31,8 +31,8 @@ public function generateModel($attributes = []) $model = new Contact(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); $model->account_id = $faker->randomElement(\app\models\Account::find()->select("id")->column()); - $model->active = $faker->boolean; - $model->nickname = $faker->sentence; + $model->active = $faker->optional(0.92)->boolean ?? null; + $model->nickname = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/20_consider_openapi_spec_examples_in_faker_code_generation/mysql/models/FruitFaker.php b/tests/specs/issue_fix/20_consider_openapi_spec_examples_in_faker_code_generation/mysql/models/FruitFaker.php index d4767811..cb0c70e9 100644 --- a/tests/specs/issue_fix/20_consider_openapi_spec_examples_in_faker_code_generation/mysql/models/FruitFaker.php +++ b/tests/specs/issue_fix/20_consider_openapi_spec_examples_in_faker_code_generation/mysql/models/FruitFaker.php @@ -29,8 +29,8 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new Fruit(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->sentence; + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; + $model->name = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/20_consider_openapi_spec_examples_in_faker_code_generation/mysql/models/PetFaker.php b/tests/specs/issue_fix/20_consider_openapi_spec_examples_in_faker_code_generation/mysql/models/PetFaker.php index 26608530..b52197ce 100644 --- a/tests/specs/issue_fix/20_consider_openapi_spec_examples_in_faker_code_generation/mysql/models/PetFaker.php +++ b/tests/specs/issue_fix/20_consider_openapi_spec_examples_in_faker_code_generation/mysql/models/PetFaker.php @@ -30,73 +30,73 @@ public function generateModel($attributes = []) $uniqueFaker = $this->uniqueFaker; $model = new Pet(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->optional(0.92, 'cat')->sentence; - $model->age = $faker->optional(0.92, 2)->numberBetween(0, 1000000); + $model->name = $faker->optional(0.92)->sentence ?? 'cat'; + $model->age = $faker->optional(0.92)->numberBetween(0, 1000000) ?? 2; $model->tags = array_map(function () use ($faker, $uniqueFaker) { - return $faker->sentence; + return $faker->optional(0.92)->sentence ?? null; }, range(1, 4)); - $model->tags_arbit = $faker->optional(0.92, [ + $model->tags_arbit = $faker->optional(0.92)->words() ?? [ 'long-tail', 'short-tail', 'black', 'white', - ])->words(); + ]; $model->number_arr = array_map(function () use ($faker, $uniqueFaker) { - return $faker->randomFloat(); + return $faker->optional(0.92)->randomFloat() ?? null; }, range(1, 4)); $model->number_arr_min_uniq = array_map(function () use ($faker, $uniqueFaker) { - return $uniqueFaker->randomFloat(); + return $uniqueFaker->optional(0.92)->randomFloat() ?? null; }, range(1, 6)); $model->int_arr = array_map(function () use ($faker, $uniqueFaker) { - return $faker->numberBetween(0, 1000000); + return $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; }, range(1, 4)); $model->int_arr_min_uniq = array_map(function () use ($faker, $uniqueFaker) { - return $uniqueFaker->numberBetween(0, 1000000); + return $uniqueFaker->optional(0.92)->numberBetween(0, 1000000) ?? null; }, range(1, 7)); $model->bool_arr = array_map(function () use ($faker, $uniqueFaker) { - return $faker->boolean; + return $faker->optional(0.92)->boolean ?? null; }, range(1, 4)); $model->arr_arr_int = array_map(function () use ($faker, $uniqueFaker) { return array_map(function () use ($faker, $uniqueFaker) { - return $faker->numberBetween(0, 1000000); - }, range(1, 4)); + return $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + }, range(1, 4)); }, range(1, 4)); $model->arr_arr_str = array_map(function () use ($faker, $uniqueFaker) { return array_map(function () use ($faker, $uniqueFaker) { - return $faker->sentence; - }, range(1, 4)); + return $faker->optional(0.92)->sentence ?? null; + }, range(1, 4)); }, range(1, 4)); $model->arr_arr_arr_str = array_map(function () use ($faker, $uniqueFaker) { return array_map(function () use ($faker, $uniqueFaker) { - return array_map(function () use ($faker, $uniqueFaker) { - return $faker->sentence; - }, range(1, 5)); - }, range(1, 4)); + return array_map(function () use ($faker, $uniqueFaker) { + return $faker->optional(0.92)->sentence ?? null; + }, range(1, 5)); + }, range(1, 4)); }, range(1, 3)); $model->arr_of_obj = array_map(function () use ($faker, $uniqueFaker) { return [ - 'id' => $uniqueFaker->numberBetween(0, 1000000), - 'name' => $faker->sentence, - 'age' => $faker->numberBetween(0, 200), + 'id' => $uniqueFaker?->numberBetween(0, 1000000) ?? null, + 'name' => $faker->optional(0.92)->sentence ?? null, + 'age' => $faker->optional(0.92)->numberBetween(0, 200) ?? null, 'user_id' => $faker->randomElement(\app\models\User::find()->select("id")->column()), 'user_2' => array_map(function () use ($faker, $uniqueFaker) { return (new UserFaker)->generateModel()->attributes; }, range(1, 4)), 'tags' => array_map(function () use ($faker, $uniqueFaker) { - return $uniqueFaker->sentence; + return $uniqueFaker->optional(0.92)->sentence ?? null; }, range(1, 4)), 'arr_arr_int_2' => array_map(function () use ($faker, $uniqueFaker) { return array_map(function () use ($faker, $uniqueFaker) { - return $faker->numberBetween(0, 1000000); + return $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; }, range(1, 11)); }, range(1, 4)), 'appearance' => [ - 'height' => $faker->numberBetween(0, 20), - 'weight' => $faker->numberBetween(0, 1000000), - 'email' => $faker->safeEmail, + 'height' => $faker->optional(0.92)->numberBetween(0, 20) ?? null, + 'weight' => $faker->optional(0.92)->numberBetween(0, 1000000) ?? null, + 'email' => $faker->optional(0.92)->safeEmail ?? null, 'nested_obj' => [ - 'id' => $uniqueFaker->numberBetween(0, 1000000), - 'title' => $faker->title, + 'id' => $uniqueFaker?->numberBetween(0, 1000000) ?? null, + 'title' => is_string($s = $faker->optional(0.92)->title) ? substr($s, 0, 4) : null, ], ], ]; @@ -105,22 +105,22 @@ public function generateModel($attributes = []) return (new UserFaker)->generateModel()->attributes; }, range(1, 3)); $model->one_of_arr = array_map(function () use ($faker, $uniqueFaker) { - $dataType0 = $faker->numberBetween(0, 1000000); - $dataType1 = $faker->sentence; - $dataType2 = $faker->boolean; + $dataType0 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $dataType1 = $faker->optional(0.92)->sentence ?? null; + $dataType2 = $faker->optional(0.92)->boolean ?? null; return ${"dataType".rand(0, 2)}; }, range(1, 4)); $model->one_of_arr_complex = array_map(function () use ($faker, $uniqueFaker) { - $dataType0 = $faker->numberBetween(0, 1000000); - $dataType1 = $faker->sentence; - $dataType2 = $faker->boolean; + $dataType0 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $dataType1 = $faker->optional(0.92)->sentence ?? null; + $dataType2 = $faker->optional(0.92)->boolean ?? null; $dataType3 = []; $dataType4 = array_map(function () use ($faker, $uniqueFaker) { - return $faker->sentence; + return $faker->optional(0.92)->sentence ?? null; }, range(1, 4)); $dataType5 = [ - 'id' => $uniqueFaker->numberBetween(0, 1000000), - ]; + 'id' => $uniqueFaker?->numberBetween(0, 1000000) ?? null, + ] ?? null; $dataType6 = array_map(function () use ($faker, $uniqueFaker) { return (new UserFaker)->generateModel()->attributes; }, range(1, 4)); diff --git a/tests/specs/issue_fix/20_consider_openapi_spec_examples_in_faker_code_generation/mysql/models/UserFaker.php b/tests/specs/issue_fix/20_consider_openapi_spec_examples_in_faker_code_generation/mysql/models/UserFaker.php index 5f389e83..ff077a63 100644 --- a/tests/specs/issue_fix/20_consider_openapi_spec_examples_in_faker_code_generation/mysql/models/UserFaker.php +++ b/tests/specs/issue_fix/20_consider_openapi_spec_examples_in_faker_code_generation/mysql/models/UserFaker.php @@ -29,8 +29,8 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new User(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->sentence; + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; + $model->name = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/22_bug_rules_required_is_generated_before_default/mysql/models/AccountFaker.php b/tests/specs/issue_fix/22_bug_rules_required_is_generated_before_default/mysql/models/AccountFaker.php index aac8dd83..de6ebecf 100644 --- a/tests/specs/issue_fix/22_bug_rules_required_is_generated_before_default/mysql/models/AccountFaker.php +++ b/tests/specs/issue_fix/22_bug_rules_required_is_generated_before_default/mysql/models/AccountFaker.php @@ -31,7 +31,7 @@ public function generateModel($attributes = []) $model = new Account(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); $model->name = substr($faker->text(128), 0, 128); - $model->paymentMethodName = $faker->sentence; + $model->paymentMethodName = $faker->optional(0.92)->sentence ?? null; $model->verified = $faker->boolean; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); diff --git a/tests/specs/issue_fix/23_consider_openapi_extension_x_no_relation_also_in_other_pertinent_place/mysql/models/PaymentsFaker.php b/tests/specs/issue_fix/23_consider_openapi_extension_x_no_relation_also_in_other_pertinent_place/mysql/models/PaymentsFaker.php index 1f3133dd..57c41a81 100644 --- a/tests/specs/issue_fix/23_consider_openapi_extension_x_no_relation_also_in_other_pertinent_place/mysql/models/PaymentsFaker.php +++ b/tests/specs/issue_fix/23_consider_openapi_extension_x_no_relation_also_in_other_pertinent_place/mysql/models/PaymentsFaker.php @@ -29,8 +29,8 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new Payments(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->currency = $faker->currencyCode; + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; + $model->currency = $faker->optional(0.92)->currencyCode ?? null; $model->samples = array_map(function () use ($faker, $uniqueFaker) { return (new SampleFaker)->generateModel()->attributes; }, range(1, 4)); diff --git a/tests/specs/issue_fix/23_consider_openapi_extension_x_no_relation_also_in_other_pertinent_place/mysql/models/SampleFaker.php b/tests/specs/issue_fix/23_consider_openapi_extension_x_no_relation_also_in_other_pertinent_place/mysql/models/SampleFaker.php index 4a0f6d29..de0ec171 100644 --- a/tests/specs/issue_fix/23_consider_openapi_extension_x_no_relation_also_in_other_pertinent_place/mysql/models/SampleFaker.php +++ b/tests/specs/issue_fix/23_consider_openapi_extension_x_no_relation_also_in_other_pertinent_place/mysql/models/SampleFaker.php @@ -29,8 +29,8 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new Sample(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->message = $faker->sentence; + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; + $model->message = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/25_generate_inverse_relations/mysql/models/AccountFaker.php b/tests/specs/issue_fix/25_generate_inverse_relations/mysql/models/AccountFaker.php index 15bf5177..4a32a07b 100644 --- a/tests/specs/issue_fix/25_generate_inverse_relations/mysql/models/AccountFaker.php +++ b/tests/specs/issue_fix/25_generate_inverse_relations/mysql/models/AccountFaker.php @@ -31,7 +31,7 @@ public function generateModel($attributes = []) $model = new Account(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); $model->name = substr($faker->text(128), 0, 128); - $model->paymentMethodName = $faker->sentence; + $model->paymentMethodName = $faker->optional(0.92)->sentence ?? null; $model->user_id = $faker->randomElement(\app\models\User::find()->select("id")->column()); $model->user2_id = $faker->randomElement(\app\models\User::find()->select("id")->column()); $model->user3 = $faker->randomElement(\app\models\User::find()->select("id")->column()); diff --git a/tests/specs/issue_fix/29_extension_fk_column_name_cause_error_in_case_of_column_name_without_underscore/mysql/models/PostFaker.php b/tests/specs/issue_fix/29_extension_fk_column_name_cause_error_in_case_of_column_name_without_underscore/mysql/models/PostFaker.php index c595c8ca..519489d8 100644 --- a/tests/specs/issue_fix/29_extension_fk_column_name_cause_error_in_case_of_column_name_without_underscore/mysql/models/PostFaker.php +++ b/tests/specs/issue_fix/29_extension_fk_column_name_cause_error_in_case_of_column_name_without_underscore/mysql/models/PostFaker.php @@ -29,8 +29,8 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new Post(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->content = $faker->paragraphs(6, true); + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; + $model->content = $faker->optional(0.92)->paragraphs(6, true) ?? null; $model->user = $faker->randomElement(\app\models\User::find()->select("id")->column()); if (!is_callable($attributes)) { $model->setAttributes($attributes, false); diff --git a/tests/specs/issue_fix/29_extension_fk_column_name_cause_error_in_case_of_column_name_without_underscore/mysql/models/UserFaker.php b/tests/specs/issue_fix/29_extension_fk_column_name_cause_error_in_case_of_column_name_without_underscore/mysql/models/UserFaker.php index 5f389e83..ff077a63 100644 --- a/tests/specs/issue_fix/29_extension_fk_column_name_cause_error_in_case_of_column_name_without_underscore/mysql/models/UserFaker.php +++ b/tests/specs/issue_fix/29_extension_fk_column_name_cause_error_in_case_of_column_name_without_underscore/mysql/models/UserFaker.php @@ -29,8 +29,8 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new User(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->sentence; + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; + $model->name = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/AnimalFaker.php b/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/AnimalFaker.php index 02b99b83..47bf1b97 100644 --- a/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/AnimalFaker.php +++ b/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/AnimalFaker.php @@ -29,8 +29,8 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new Animal(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->sentence; + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; + $model->name = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/FruitFaker.php b/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/FruitFaker.php index d4767811..cb0c70e9 100644 --- a/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/FruitFaker.php +++ b/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/FruitFaker.php @@ -29,8 +29,8 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new Fruit(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->sentence; + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; + $model->name = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/InvoiceFaker.php b/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/InvoiceFaker.php index cd835b11..c7fa395a 100644 --- a/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/InvoiceFaker.php +++ b/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/InvoiceFaker.php @@ -29,7 +29,7 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new Invoice(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; $model->reference_invoice_2_id = $faker->randomElement(\app\models\Invoice::find()->select("id")->column()); $model->user_id = $faker->randomElement(\app\models\User::find()->select("id")->column()); $model->fruit_id = $faker->randomElement(\app\models\Fruit::find()->select("id")->column()); diff --git a/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/UserFaker.php b/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/UserFaker.php index 5f389e83..ff077a63 100644 --- a/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/UserFaker.php +++ b/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/UserFaker.php @@ -29,8 +29,8 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new User(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->sentence; + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; + $model->name = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/60_description_of_a_property_in_spec_must_correspond_to_db_table_column_comment/mysql/models/AnimalFaker.php b/tests/specs/issue_fix/60_description_of_a_property_in_spec_must_correspond_to_db_table_column_comment/mysql/models/AnimalFaker.php index 871d9525..92b3169f 100644 --- a/tests/specs/issue_fix/60_description_of_a_property_in_spec_must_correspond_to_db_table_column_comment/mysql/models/AnimalFaker.php +++ b/tests/specs/issue_fix/60_description_of_a_property_in_spec_must_correspond_to_db_table_column_comment/mysql/models/AnimalFaker.php @@ -29,13 +29,13 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new Animal(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->numberBetween(0, 1000000); - $model->g = $faker->sentence; - $model->g2 = $faker->sentence; - $model->g3 = $faker->sentence; - $model->g4 = $faker->numberBetween(0, 1000000); - $model->new_col = $faker->sentence; + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; + $model->name = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->g = $faker->optional(0.92)->sentence ?? null; + $model->g2 = $faker->optional(0.92)->sentence ?? null; + $model->g3 = $faker->optional(0.92)->sentence ?? null; + $model->g4 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->new_col = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/60_description_of_a_property_in_spec_must_correspond_to_db_table_column_comment/mysql/models/FruitFaker.php b/tests/specs/issue_fix/60_description_of_a_property_in_spec_must_correspond_to_db_table_column_comment/mysql/models/FruitFaker.php index 10a1b8f0..9f8793ec 100644 --- a/tests/specs/issue_fix/60_description_of_a_property_in_spec_must_correspond_to_db_table_column_comment/mysql/models/FruitFaker.php +++ b/tests/specs/issue_fix/60_description_of_a_property_in_spec_must_correspond_to_db_table_column_comment/mysql/models/FruitFaker.php @@ -29,9 +29,9 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new Fruit(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->sentence; - $model->description = $faker->randomFloat(); + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; + $model->name = $faker->optional(0.92)->sentence ?? null; + $model->description = $faker->optional(0.92)->randomFloat() ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/60_description_of_a_property_in_spec_must_correspond_to_db_table_column_comment/pgsql/models/AnimalFaker.php b/tests/specs/issue_fix/60_description_of_a_property_in_spec_must_correspond_to_db_table_column_comment/pgsql/models/AnimalFaker.php index 871d9525..92b3169f 100644 --- a/tests/specs/issue_fix/60_description_of_a_property_in_spec_must_correspond_to_db_table_column_comment/pgsql/models/AnimalFaker.php +++ b/tests/specs/issue_fix/60_description_of_a_property_in_spec_must_correspond_to_db_table_column_comment/pgsql/models/AnimalFaker.php @@ -29,13 +29,13 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new Animal(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->numberBetween(0, 1000000); - $model->g = $faker->sentence; - $model->g2 = $faker->sentence; - $model->g3 = $faker->sentence; - $model->g4 = $faker->numberBetween(0, 1000000); - $model->new_col = $faker->sentence; + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; + $model->name = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->g = $faker->optional(0.92)->sentence ?? null; + $model->g2 = $faker->optional(0.92)->sentence ?? null; + $model->g3 = $faker->optional(0.92)->sentence ?? null; + $model->g4 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->new_col = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/60_description_of_a_property_in_spec_must_correspond_to_db_table_column_comment/pgsql/models/FruitFaker.php b/tests/specs/issue_fix/60_description_of_a_property_in_spec_must_correspond_to_db_table_column_comment/pgsql/models/FruitFaker.php index 10a1b8f0..9f8793ec 100644 --- a/tests/specs/issue_fix/60_description_of_a_property_in_spec_must_correspond_to_db_table_column_comment/pgsql/models/FruitFaker.php +++ b/tests/specs/issue_fix/60_description_of_a_property_in_spec_must_correspond_to_db_table_column_comment/pgsql/models/FruitFaker.php @@ -29,9 +29,9 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new Fruit(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->sentence; - $model->description = $faker->randomFloat(); + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; + $model->name = $faker->optional(0.92)->sentence ?? null; + $model->description = $faker->optional(0.92)->randomFloat() ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/74_invalid_schema_reference_error/mysql/models/InvoiceFaker.php b/tests/specs/issue_fix/74_invalid_schema_reference_error/mysql/models/InvoiceFaker.php index a8fe4f81..3abaf4ac 100644 --- a/tests/specs/issue_fix/74_invalid_schema_reference_error/mysql/models/InvoiceFaker.php +++ b/tests/specs/issue_fix/74_invalid_schema_reference_error/mysql/models/InvoiceFaker.php @@ -29,7 +29,7 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new Invoice(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; $model->vat_rate = $faker->randomElement(['standard','none']); if (!is_callable($attributes)) { $model->setAttributes($attributes, false); diff --git a/tests/specs/issue_fix/78_properties_that_are_marked_as_readonly_are_not_read_only/mysql/models/PaymentFaker.php b/tests/specs/issue_fix/78_properties_that_are_marked_as_readonly_are_not_read_only/mysql/models/PaymentFaker.php index d2f22af6..3497fccf 100644 --- a/tests/specs/issue_fix/78_properties_that_are_marked_as_readonly_are_not_read_only/mysql/models/PaymentFaker.php +++ b/tests/specs/issue_fix/78_properties_that_are_marked_as_readonly_are_not_read_only/mysql/models/PaymentFaker.php @@ -29,9 +29,9 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new Payment(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->amount = $faker->numberBetween(0, 1000000); - $model->currency = $faker->currencyCode; + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; + $model->amount = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->currency = $faker->optional(0.92)->currencyCode ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/issue_fix/model_name_more_than_once_in_faker_148/app/models/E123Faker.php b/tests/specs/issue_fix/model_name_more_than_once_in_faker_148/app/models/E123Faker.php index eb46472e..a523f771 100644 --- a/tests/specs/issue_fix/model_name_more_than_once_in_faker_148/app/models/E123Faker.php +++ b/tests/specs/issue_fix/model_name_more_than_once_in_faker_148/app/models/E123Faker.php @@ -30,7 +30,7 @@ public function generateModel($attributes = []) $uniqueFaker = $this->uniqueFaker; $model = new E123(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->sentence; + $model->name = $faker->optional(0.92)->sentence ?? null; $model->account_id = $faker->randomElement(\app\models\Account::find()->select("id")->column()); $model->account_2_id = $faker->randomElement(\app\models\Account::find()->select("id")->column()); $model->account_3_id = $faker->randomElement(\app\models\Account::find()->select("id")->column()); diff --git a/tests/specs/issue_fix/quote_in_alter_table/pgsql/app/models/FruitFaker.php b/tests/specs/issue_fix/quote_in_alter_table/pgsql/app/models/FruitFaker.php index c17d5edd..44ab731e 100644 --- a/tests/specs/issue_fix/quote_in_alter_table/pgsql/app/models/FruitFaker.php +++ b/tests/specs/issue_fix/quote_in_alter_table/pgsql/app/models/FruitFaker.php @@ -30,7 +30,7 @@ public function generateModel($attributes = []) $uniqueFaker = $this->uniqueFaker; $model = new Fruit(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->colourName = $faker->sentence; + $model->colourName = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/json_arr_obj/models/JsonArrObjFaker.php b/tests/specs/json_arr_obj/models/JsonArrObjFaker.php index 0c32f41d..4bd2806c 100644 --- a/tests/specs/json_arr_obj/models/JsonArrObjFaker.php +++ b/tests/specs/json_arr_obj/models/JsonArrObjFaker.php @@ -29,7 +29,7 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new JsonArrObj(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; $model->arr_no_items = []; $model->obj_no_props = (object) []; $model->arr_obj_no_props = []; diff --git a/tests/specs/many2many/models/PostsAttachesFaker.php b/tests/specs/many2many/models/PostsAttachesFaker.php index 18bc295a..2344a141 100644 --- a/tests/specs/many2many/models/PostsAttachesFaker.php +++ b/tests/specs/many2many/models/PostsAttachesFaker.php @@ -29,7 +29,7 @@ public function generateModel($attributes = []) $faker = $this->faker; $uniqueFaker = $this->uniqueFaker; $model = new PostsAttaches(); - //$model->id = $uniqueFaker->numberBetween(0, 1000000); + //$model->id = $uniqueFaker?->numberBetween(0, 1000000) ?? null; $model->attach_id = $faker->randomElement(\app\models\Photo::find()->select("id")->column()); $model->target_id = $faker->randomElement(\app\models\Post::find()->select("id")->column()); if (!is_callable($attributes)) { diff --git a/tests/specs/many2many/models/PostsGalleryFaker.php b/tests/specs/many2many/models/PostsGalleryFaker.php index 972b8e0c..694e0194 100644 --- a/tests/specs/many2many/models/PostsGalleryFaker.php +++ b/tests/specs/many2many/models/PostsGalleryFaker.php @@ -31,7 +31,7 @@ public function generateModel($attributes = []) $model = new PostsGallery(); $model->image_id = $faker->randomElement(\app\models\Photo::find()->select("id")->column()); $model->article_id = $faker->randomElement(\app\models\Post::find()->select("id")->column()); - $model->is_cover = $faker->boolean; + $model->is_cover = $faker->optional(0.92)->boolean ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/petstore_jsonapi/models/PetFaker.php b/tests/specs/petstore_jsonapi/models/PetFaker.php index 3e4a7f25..91cfbc98 100644 --- a/tests/specs/petstore_jsonapi/models/PetFaker.php +++ b/tests/specs/petstore_jsonapi/models/PetFaker.php @@ -32,7 +32,7 @@ public function generateModel($attributes = []) //$model->id = $uniqueFaker->numberBetween(0, 1000000); $model->name = $faker->sentence; $model->tag = $faker->randomElement(['one', 'two', 'three', 'four']); - $model->petCode = substr($faker->text(50), 0, 50); + $model->petCode = is_string($s = $faker->optional(0.92)->text(50)) ? substr($s, 0, 50) : null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/postgres_custom/models/CustomFaker.php b/tests/specs/postgres_custom/models/CustomFaker.php index 3732716d..806752d2 100644 --- a/tests/specs/postgres_custom/models/CustomFaker.php +++ b/tests/specs/postgres_custom/models/CustomFaker.php @@ -30,13 +30,13 @@ public function generateModel($attributes = []) $uniqueFaker = $this->uniqueFaker; $model = new Custom(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->num = $faker->numberBetween(0, 1000000); + $model->num = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; $model->json1 = []; $model->json2 = []; $model->json3 = []; $model->json4 = []; - $model->status = $faker->randomElement(['active','draft']); - $model->status_x = $faker->randomElement(['active','draft']); + $model->status = $faker->optional(0.92)->randomElement(['active','draft']) ?? null; + $model->status_x = is_string($s = $faker->optional(0.92)->randomElement(['active','draft'])) ? substr($s, 0, 10) : null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/relations_in_faker/app/models/fakers/A123Faker.php b/tests/specs/relations_in_faker/app/models/fakers/A123Faker.php index dff3119d..58c24ead 100644 --- a/tests/specs/relations_in_faker/app/models/fakers/A123Faker.php +++ b/tests/specs/relations_in_faker/app/models/fakers/A123Faker.php @@ -31,7 +31,7 @@ public function generateModel($attributes = []) $uniqueFaker = $this->uniqueFaker; $model = new \app\models\A123(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->sentence; + $model->name = $faker->optional(0.92)->sentence ?? null; $model->b123_id = $faker->randomElement(\app\models\B123::find()->select("id")->column()); if (!is_callable($attributes)) { $model->setAttributes($attributes, false); diff --git a/tests/specs/relations_in_faker/app/models/fakers/B123Faker.php b/tests/specs/relations_in_faker/app/models/fakers/B123Faker.php index 7065168e..215fbd39 100644 --- a/tests/specs/relations_in_faker/app/models/fakers/B123Faker.php +++ b/tests/specs/relations_in_faker/app/models/fakers/B123Faker.php @@ -31,7 +31,7 @@ public function generateModel($attributes = []) $uniqueFaker = $this->uniqueFaker; $model = new \app\models\B123(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->sentence; + $model->name = $faker->optional(0.92)->sentence ?? null; $model->c123_id = $faker->randomElement(\app\models\C123::find()->select("id")->column()); if (!is_callable($attributes)) { $model->setAttributes($attributes, false); diff --git a/tests/specs/relations_in_faker/app/models/fakers/C123Faker.php b/tests/specs/relations_in_faker/app/models/fakers/C123Faker.php index 0653a8ce..dbe30a81 100644 --- a/tests/specs/relations_in_faker/app/models/fakers/C123Faker.php +++ b/tests/specs/relations_in_faker/app/models/fakers/C123Faker.php @@ -31,7 +31,7 @@ public function generateModel($attributes = []) $uniqueFaker = $this->uniqueFaker; $model = new \app\models\C123(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->sentence; + $model->name = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/relations_in_faker/app/models/fakers/D123Faker.php b/tests/specs/relations_in_faker/app/models/fakers/D123Faker.php index 23c56326..df04a303 100644 --- a/tests/specs/relations_in_faker/app/models/fakers/D123Faker.php +++ b/tests/specs/relations_in_faker/app/models/fakers/D123Faker.php @@ -31,7 +31,7 @@ public function generateModel($attributes = []) $uniqueFaker = $this->uniqueFaker; $model = new \app\models\D123(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->sentence; + $model->name = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/relations_in_faker/app/models/fakers/E123Faker.php b/tests/specs/relations_in_faker/app/models/fakers/E123Faker.php index 3e300586..0534234f 100644 --- a/tests/specs/relations_in_faker/app/models/fakers/E123Faker.php +++ b/tests/specs/relations_in_faker/app/models/fakers/E123Faker.php @@ -31,7 +31,7 @@ public function generateModel($attributes = []) $uniqueFaker = $this->uniqueFaker; $model = new \app\models\E123(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->name = $faker->sentence; + $model->name = $faker->optional(0.92)->sentence ?? null; $model->b123_id = $faker->randomElement(\app\models\B123::find()->select("id")->column()); if (!is_callable($attributes)) { $model->setAttributes($attributes, false); diff --git a/tests/specs/relations_in_faker/app/models/fakers/RoutingFaker.php b/tests/specs/relations_in_faker/app/models/fakers/RoutingFaker.php index 06d7bff7..cdd312f7 100644 --- a/tests/specs/relations_in_faker/app/models/fakers/RoutingFaker.php +++ b/tests/specs/relations_in_faker/app/models/fakers/RoutingFaker.php @@ -33,10 +33,10 @@ public function generateModel($attributes = []) //$model->id = $uniqueFaker->numberBetween(0, 1000000); $model->domain_id = $faker->randomElement(\app\models\Domain::find()->select("id")->column()); $model->path = $faker->randomElement(["/", "/", "/", "/", "/api", "/tools", "/assets/web"]); - $model->ssl = $faker->boolean; - $model->redirect_to_ssl = $faker->boolean; + $model->ssl = $faker->optional(0.92)->boolean ?? null; + $model->redirect_to_ssl = $faker->optional(0.92)->boolean ?? null; $model->service = "http://tador.cebe.net/" . $faker->domainName; - $model->created_at = $faker->dateTimeThisYear('now', 'UTC')->format('Y-m-d H:i:s'); + $model->created_at = $faker->optional(0.92)->dateTimeThisYear('now', 'UTC')?->format('Y-m-d H:i:s') ?? null; $model->d123_id = $faker->randomElement(\app\models\D123::find()->select("id")->column()); $model->a123_id = $faker->randomElement(\app\models\A123::find()->select("id")->column()); if (!is_callable($attributes)) { diff --git a/tests/specs/x_db_type/rules_and_more/maria/app/models/mariafaker/AlldbdatatypeFaker.php b/tests/specs/x_db_type/rules_and_more/maria/app/models/mariafaker/AlldbdatatypeFaker.php index 32934ebe..a8b0208b 100644 --- a/tests/specs/x_db_type/rules_and_more/maria/app/models/mariafaker/AlldbdatatypeFaker.php +++ b/tests/specs/x_db_type/rules_and_more/maria/app/models/mariafaker/AlldbdatatypeFaker.php @@ -31,45 +31,45 @@ public function generateModel($attributes = []) $uniqueFaker = $this->uniqueFaker; $model = new \app\models\mariamodel\Alldbdatatype(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->string_col = substr($faker->text(255), 0, 255); - $model->varchar_col = substr($faker->text(132), 0, 132); - $model->text_col = $faker->sentence; - $model->varchar_4_col = substr($faker->word(4), 0, 4); - $model->char_4_col = substr($faker->word(4), 0, 4); - $model->char_5_col = $faker->sentence; + $model->string_col = is_string($s = $faker->optional(0.92)->text(255)) ? substr($s, 0, 255) : null; + $model->varchar_col = is_string($s = $faker->optional(0.92)->text(132)) ? substr($s, 0, 132) : null; + $model->text_col = $faker->optional(0.92)->sentence ?? null; + $model->varchar_4_col = is_string($s = $faker->optional(0.92)->word(4)) ? substr($s, 0, 4) : null; + $model->char_4_col = is_string($s = $faker->optional(0.92)->word(4)) ? substr($s, 0, 4) : null; + $model->char_5_col = $faker->optional(0.92)->sentence ?? null; $model->char_6_col = $faker->sentence; $model->char_7_col = substr($faker->text(6), 0, 6); - $model->char_8_col = $faker->sentence; - $model->decimal_col = $faker->randomFloat(); - $model->bit_col = $faker->numberBetween(0, 1000000); - $model->bit_2 = $faker->numberBetween(0, 1000000); - $model->bit_3 = $faker->numberBetween(0, 1000000); - $model->ti = $faker->numberBetween(0, 1000000); - $model->ti_2 = $faker->numberBetween(0, 1000000); - $model->ti_3 = $faker->numberBetween(0, 1000000); - $model->si_col = $faker->numberBetween(0, 1000000); - $model->si_col_2 = $faker->numberBetween(0, 1000000); - $model->mi = $faker->numberBetween(0, 1000000); - $model->bi = $faker->numberBetween(0, 1000000); - $model->int_col = $faker->numberBetween(0, 1000000); - $model->int_col_2 = $faker->numberBetween(0, 1000000); - $model->numeric_col = $faker->randomFloat(); - $model->float_col = $faker->randomFloat(); - $model->float_2 = $faker->randomFloat(); - $model->float_3 = $faker->randomFloat(); - $model->double_col = $faker->randomFloat(); - $model->double_p = $faker->randomFloat(); - $model->double_p_2 = $faker->randomFloat(); - $model->real_col = $faker->randomFloat(); - $model->date_col = $faker->dateTimeThisCentury->format('Y-m-d'); - $model->time_col = $faker->time('H:i:s'); - $model->datetime_col = $faker->dateTimeThisYear('now', 'UTC')->format('Y-m-d H:i:s'); - $model->timestamp_col = $faker->dateTimeThisYear('now', 'UTC')->format('Y-m-d H:i:s'); - $model->year_col = $faker->year; + $model->char_8_col = $faker->optional(0.92)->sentence ?? null; + $model->decimal_col = $faker->optional(0.92)->randomFloat() ?? null; + $model->bit_col = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->bit_2 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->bit_3 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->ti = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->ti_2 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->ti_3 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->si_col = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->si_col_2 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->mi = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->bi = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->int_col = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->int_col_2 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->numeric_col = $faker->optional(0.92)->randomFloat() ?? null; + $model->float_col = $faker->optional(0.92)->randomFloat() ?? null; + $model->float_2 = $faker->optional(0.92)->randomFloat() ?? null; + $model->float_3 = $faker->optional(0.92)->randomFloat() ?? null; + $model->double_col = $faker->optional(0.92)->randomFloat() ?? null; + $model->double_p = $faker->optional(0.92)->randomFloat() ?? null; + $model->double_p_2 = $faker->optional(0.92)->randomFloat() ?? null; + $model->real_col = $faker->optional(0.92)->randomFloat() ?? null; + $model->date_col = $faker->optional(0.92)->dateTimeThisCentury?->format('Y-m-d') ?? null; + $model->time_col = $faker->optional(0.92)->time('H:i:s') ?? null; + $model->datetime_col = $faker->optional(0.92)->dateTimeThisYear('now', 'UTC')?->format('Y-m-d H:i:s') ?? null; + $model->timestamp_col = $faker->optional(0.92)->dateTimeThisYear('now', 'UTC')?->format('Y-m-d H:i:s') ?? null; + $model->year_col = $faker->optional(0.92)->year ?? null; $model->json_col = []; $model->json_col_def = []; $model->json_col_def_2 = []; - $model->text_def = $faker->sentence; + $model->text_def = $faker->optional(0.92)->sentence ?? null; $model->json_def = []; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); diff --git a/tests/specs/x_db_type/rules_and_more/maria/app/models/mariafaker/EditcolumnFaker.php b/tests/specs/x_db_type/rules_and_more/maria/app/models/mariafaker/EditcolumnFaker.php index 2c4ae559..d08888ba 100644 --- a/tests/specs/x_db_type/rules_and_more/maria/app/models/mariafaker/EditcolumnFaker.php +++ b/tests/specs/x_db_type/rules_and_more/maria/app/models/mariafaker/EditcolumnFaker.php @@ -32,14 +32,14 @@ public function generateModel($attributes = []) $model = new \app\models\mariamodel\Editcolumn(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); $model->name = substr($faker->text(254), 0, 254); - $model->tag = $faker->sentence; - $model->first_name = substr($faker->text(255), 0, 255); - $model->string_col = $faker->sentence; - $model->dec_col = $faker->randomFloat(); + $model->tag = $faker->optional(0.92)->sentence ?? null; + $model->first_name = is_string($s = $faker->optional(0.92)->text(255)) ? substr($s, 0, 255) : null; + $model->string_col = $faker->optional(0.92)->sentence ?? null; + $model->dec_col = $faker->optional(0.92)->randomFloat() ?? null; $model->str_col_def = substr($faker->word(3), 0, 3); $model->json_col = $faker->sentence; $model->json_col_2 = $faker->words(); - $model->numeric_col = $faker->randomFloat(); + $model->numeric_col = $faker->optional(0.92)->randomFloat() ?? null; $model->json_col_def_n = []; $model->json_col_def_n_2 = []; if (!is_callable($attributes)) { diff --git a/tests/specs/x_db_type/rules_and_more/maria/app/models/mariafaker/NewcolumnFaker.php b/tests/specs/x_db_type/rules_and_more/maria/app/models/mariafaker/NewcolumnFaker.php index a60800cd..e90b0b29 100644 --- a/tests/specs/x_db_type/rules_and_more/maria/app/models/mariafaker/NewcolumnFaker.php +++ b/tests/specs/x_db_type/rules_and_more/maria/app/models/mariafaker/NewcolumnFaker.php @@ -32,11 +32,11 @@ public function generateModel($attributes = []) $model = new \app\models\mariamodel\Newcolumn(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); $model->name = substr($faker->text(255), 0, 255); - $model->last_name = $faker->sentence; - $model->dec_col = $faker->randomFloat(); + $model->last_name = $faker->optional(0.92)->sentence ?? null; + $model->dec_col = $faker->optional(0.92)->randomFloat() ?? null; $model->json_col = []; - $model->varchar_col = substr($faker->text(5), 0, 5); - $model->numeric_col = $faker->randomFloat(); + $model->varchar_col = is_string($s = $faker->optional(0.92)->text(5)) ? substr($s, 0, 5) : null; + $model->numeric_col = $faker->optional(0.92)->randomFloat() ?? null; $model->json_col_def_n = []; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); diff --git a/tests/specs/x_db_type/rules_and_more/maria/app/models/mariafaker/PristineFaker.php b/tests/specs/x_db_type/rules_and_more/maria/app/models/mariafaker/PristineFaker.php index 2fdf01e5..7183a429 100644 --- a/tests/specs/x_db_type/rules_and_more/maria/app/models/mariafaker/PristineFaker.php +++ b/tests/specs/x_db_type/rules_and_more/maria/app/models/mariafaker/PristineFaker.php @@ -32,16 +32,16 @@ public function generateModel($attributes = []) $model = new \app\models\mariamodel\Pristine(); $model->custom_id_col = $faker->numberBetween(0, 1000000); $model->name = $faker->sentence; - $model->tag = $faker->sentence; - $model->new_col = substr($faker->text(17), 0, 17); - $model->col_5 = $faker->randomFloat(); - $model->col_6 = $faker->randomFloat(); - $model->col_7 = $faker->randomFloat(); + $model->tag = $faker->optional(0.92)->sentence ?? null; + $model->new_col = is_string($s = $faker->optional(0.92)->text(17)) ? substr($s, 0, 17) : null; + $model->col_5 = $faker->optional(0.92)->randomFloat() ?? null; + $model->col_6 = $faker->optional(0.92)->randomFloat() ?? null; + $model->col_7 = $faker->optional(0.92)->randomFloat() ?? null; $model->col_8 = []; - $model->col_9 = substr($faker->text(9), 0, 9); - $model->col_10 = substr($faker->text(10), 0, 10); - $model->col_11 = $faker->sentence; - $model->price = $faker->randomFloat(); + $model->col_9 = is_string($s = $faker->optional(0.92)->text(9)) ? substr($s, 0, 9) : null; + $model->col_10 = is_string($s = $faker->optional(0.92)->text(10)) ? substr($s, 0, 10) : null; + $model->col_11 = $faker->optional(0.92)->sentence ?? null; + $model->price = $faker->optional(0.92)->randomFloat() ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/x_db_type/rules_and_more/mysql/app/models/AlldbdatatypeFaker.php b/tests/specs/x_db_type/rules_and_more/mysql/app/models/AlldbdatatypeFaker.php index 9c3e308b..d4311ddd 100644 --- a/tests/specs/x_db_type/rules_and_more/mysql/app/models/AlldbdatatypeFaker.php +++ b/tests/specs/x_db_type/rules_and_more/mysql/app/models/AlldbdatatypeFaker.php @@ -30,45 +30,45 @@ public function generateModel($attributes = []) $uniqueFaker = $this->uniqueFaker; $model = new Alldbdatatype(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->string_col = substr($faker->text(255), 0, 255); - $model->varchar_col = substr($faker->text(132), 0, 132); - $model->text_col = $faker->sentence; - $model->varchar_4_col = substr($faker->word(4), 0, 4); - $model->char_4_col = substr($faker->word(4), 0, 4); - $model->char_5_col = $faker->sentence; + $model->string_col = is_string($s = $faker->optional(0.92)->text(255)) ? substr($s, 0, 255) : null; + $model->varchar_col = is_string($s = $faker->optional(0.92)->text(132)) ? substr($s, 0, 132) : null; + $model->text_col = $faker->optional(0.92)->sentence ?? null; + $model->varchar_4_col = is_string($s = $faker->optional(0.92)->word(4)) ? substr($s, 0, 4) : null; + $model->char_4_col = is_string($s = $faker->optional(0.92)->word(4)) ? substr($s, 0, 4) : null; + $model->char_5_col = $faker->optional(0.92)->sentence ?? null; $model->char_6_col = $faker->sentence; $model->char_7_col = substr($faker->text(6), 0, 6); - $model->char_8_col = $faker->sentence; - $model->decimal_col = $faker->randomFloat(); - $model->bit_col = $faker->numberBetween(0, 1000000); - $model->bit_2 = $faker->numberBetween(0, 1000000); - $model->bit_3 = $faker->numberBetween(0, 1000000); - $model->ti = $faker->numberBetween(0, 1000000); - $model->ti_2 = $faker->numberBetween(0, 1000000); - $model->ti_3 = $faker->numberBetween(0, 1000000); - $model->si_col = $faker->numberBetween(0, 1000000); - $model->si_col_2 = $faker->numberBetween(0, 1000000); - $model->mi = $faker->numberBetween(0, 1000000); - $model->bi = $faker->numberBetween(0, 1000000); - $model->int_col = $faker->numberBetween(0, 1000000); - $model->int_col_2 = $faker->numberBetween(0, 1000000); - $model->numeric_col = $faker->randomFloat(); - $model->float_col = $faker->randomFloat(); - $model->float_2 = $faker->randomFloat(); - $model->float_3 = $faker->randomFloat(); - $model->double_col = $faker->randomFloat(); - $model->double_p = $faker->randomFloat(); - $model->double_p_2 = $faker->randomFloat(); - $model->real_col = $faker->randomFloat(); - $model->date_col = $faker->dateTimeThisCentury->format('Y-m-d'); - $model->time_col = $faker->time('H:i:s'); - $model->datetime_col = $faker->dateTimeThisYear('now', 'UTC')->format('Y-m-d H:i:s'); - $model->timestamp_col = $faker->dateTimeThisYear('now', 'UTC')->format('Y-m-d H:i:s'); - $model->year_col = $faker->year; + $model->char_8_col = $faker->optional(0.92)->sentence ?? null; + $model->decimal_col = $faker->optional(0.92)->randomFloat() ?? null; + $model->bit_col = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->bit_2 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->bit_3 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->ti = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->ti_2 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->ti_3 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->si_col = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->si_col_2 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->mi = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->bi = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->int_col = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->int_col_2 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->numeric_col = $faker->optional(0.92)->randomFloat() ?? null; + $model->float_col = $faker->optional(0.92)->randomFloat() ?? null; + $model->float_2 = $faker->optional(0.92)->randomFloat() ?? null; + $model->float_3 = $faker->optional(0.92)->randomFloat() ?? null; + $model->double_col = $faker->optional(0.92)->randomFloat() ?? null; + $model->double_p = $faker->optional(0.92)->randomFloat() ?? null; + $model->double_p_2 = $faker->optional(0.92)->randomFloat() ?? null; + $model->real_col = $faker->optional(0.92)->randomFloat() ?? null; + $model->date_col = $faker->optional(0.92)->dateTimeThisCentury?->format('Y-m-d') ?? null; + $model->time_col = $faker->optional(0.92)->time('H:i:s') ?? null; + $model->datetime_col = $faker->optional(0.92)->dateTimeThisYear('now', 'UTC')?->format('Y-m-d H:i:s') ?? null; + $model->timestamp_col = $faker->optional(0.92)->dateTimeThisYear('now', 'UTC')?->format('Y-m-d H:i:s') ?? null; + $model->year_col = $faker->optional(0.92)->year ?? null; $model->json_col = []; $model->json_col_def = []; $model->json_col_def_2 = []; - $model->text_def = $faker->sentence; + $model->text_def = $faker->optional(0.92)->sentence ?? null; $model->json_def = []; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); diff --git a/tests/specs/x_db_type/rules_and_more/mysql/app/models/EditcolumnFaker.php b/tests/specs/x_db_type/rules_and_more/mysql/app/models/EditcolumnFaker.php index c2318f0d..1d0606b6 100644 --- a/tests/specs/x_db_type/rules_and_more/mysql/app/models/EditcolumnFaker.php +++ b/tests/specs/x_db_type/rules_and_more/mysql/app/models/EditcolumnFaker.php @@ -31,14 +31,14 @@ public function generateModel($attributes = []) $model = new Editcolumn(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); $model->name = substr($faker->text(254), 0, 254); - $model->tag = $faker->sentence; - $model->first_name = substr($faker->text(255), 0, 255); - $model->string_col = $faker->sentence; - $model->dec_col = $faker->randomFloat(); + $model->tag = $faker->optional(0.92)->sentence ?? null; + $model->first_name = is_string($s = $faker->optional(0.92)->text(255)) ? substr($s, 0, 255) : null; + $model->string_col = $faker->optional(0.92)->sentence ?? null; + $model->dec_col = $faker->optional(0.92)->randomFloat() ?? null; $model->str_col_def = substr($faker->word(3), 0, 3); $model->json_col = $faker->sentence; $model->json_col_2 = $faker->words(); - $model->numeric_col = $faker->randomFloat(); + $model->numeric_col = $faker->optional(0.92)->randomFloat() ?? null; $model->json_col_def_n = []; $model->json_col_def_n_2 = []; if (!is_callable($attributes)) { diff --git a/tests/specs/x_db_type/rules_and_more/mysql/app/models/NewcolumnFaker.php b/tests/specs/x_db_type/rules_and_more/mysql/app/models/NewcolumnFaker.php index 87763eb3..4d34774f 100644 --- a/tests/specs/x_db_type/rules_and_more/mysql/app/models/NewcolumnFaker.php +++ b/tests/specs/x_db_type/rules_and_more/mysql/app/models/NewcolumnFaker.php @@ -31,11 +31,11 @@ public function generateModel($attributes = []) $model = new Newcolumn(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); $model->name = substr($faker->text(255), 0, 255); - $model->last_name = $faker->sentence; - $model->dec_col = $faker->randomFloat(); + $model->last_name = $faker->optional(0.92)->sentence ?? null; + $model->dec_col = $faker->optional(0.92)->randomFloat() ?? null; $model->json_col = []; - $model->varchar_col = substr($faker->text(5), 0, 5); - $model->numeric_col = $faker->randomFloat(); + $model->varchar_col = is_string($s = $faker->optional(0.92)->text(5)) ? substr($s, 0, 5) : null; + $model->numeric_col = $faker->optional(0.92)->randomFloat() ?? null; $model->json_col_def_n = []; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); diff --git a/tests/specs/x_db_type/rules_and_more/mysql/app/models/PristineFaker.php b/tests/specs/x_db_type/rules_and_more/mysql/app/models/PristineFaker.php index 41b186d9..34368a20 100644 --- a/tests/specs/x_db_type/rules_and_more/mysql/app/models/PristineFaker.php +++ b/tests/specs/x_db_type/rules_and_more/mysql/app/models/PristineFaker.php @@ -31,16 +31,16 @@ public function generateModel($attributes = []) $model = new Pristine(); $model->custom_id_col = $faker->numberBetween(0, 1000000); $model->name = $faker->sentence; - $model->tag = $faker->sentence; - $model->new_col = substr($faker->text(17), 0, 17); - $model->col_5 = $faker->randomFloat(); - $model->col_6 = $faker->randomFloat(); - $model->col_7 = $faker->randomFloat(); + $model->tag = $faker->optional(0.92)->sentence ?? null; + $model->new_col = is_string($s = $faker->optional(0.92)->text(17)) ? substr($s, 0, 17) : null; + $model->col_5 = $faker->optional(0.92)->randomFloat() ?? null; + $model->col_6 = $faker->optional(0.92)->randomFloat() ?? null; + $model->col_7 = $faker->optional(0.92)->randomFloat() ?? null; $model->col_8 = []; - $model->col_9 = substr($faker->text(9), 0, 9); - $model->col_10 = substr($faker->text(10), 0, 10); - $model->col_11 = $faker->sentence; - $model->price = $faker->randomFloat(); + $model->col_9 = is_string($s = $faker->optional(0.92)->text(9)) ? substr($s, 0, 9) : null; + $model->col_10 = is_string($s = $faker->optional(0.92)->text(10)) ? substr($s, 0, 10) : null; + $model->col_11 = $faker->optional(0.92)->sentence ?? null; + $model->price = $faker->optional(0.92)->randomFloat() ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/x_db_type/rules_and_more/pgsql/app/models/pgsqlfaker/AlldbdatatypeFaker.php b/tests/specs/x_db_type/rules_and_more/pgsql/app/models/pgsqlfaker/AlldbdatatypeFaker.php index e2af0af0..c398b2b5 100644 --- a/tests/specs/x_db_type/rules_and_more/pgsql/app/models/pgsqlfaker/AlldbdatatypeFaker.php +++ b/tests/specs/x_db_type/rules_and_more/pgsql/app/models/pgsqlfaker/AlldbdatatypeFaker.php @@ -31,95 +31,95 @@ public function generateModel($attributes = []) $uniqueFaker = $this->uniqueFaker; $model = new \app\models\pgsqlmodel\Alldbdatatype(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); - $model->string_col = $faker->sentence; - $model->varchar_col = $faker->sentence; - $model->text_col = $faker->sentence; + $model->string_col = $faker->optional(0.92)->sentence ?? null; + $model->varchar_col = $faker->optional(0.92)->sentence ?? null; + $model->text_col = $faker->optional(0.92)->sentence ?? null; $model->text_col_array = []; - $model->varchar_4_col = substr($faker->word(4), 0, 4); - $model->varchar_5_col = substr($faker->text(5), 0, 5); - $model->char_4_col = substr($faker->word(4), 0, 4); - $model->char_5_col = $faker->sentence; + $model->varchar_4_col = is_string($s = $faker->optional(0.92)->word(4)) ? substr($s, 0, 4) : null; + $model->varchar_5_col = is_string($s = $faker->optional(0.92)->text(5)) ? substr($s, 0, 5) : null; + $model->char_4_col = is_string($s = $faker->optional(0.92)->word(4)) ? substr($s, 0, 4) : null; + $model->char_5_col = $faker->optional(0.92)->sentence ?? null; $model->char_6_col = $faker->sentence; $model->char_7_col = substr($faker->text(6), 0, 6); - $model->char_8_col = $faker->sentence; - $model->decimal_col = $faker->randomFloat(); - $model->bit_col = $faker->numberBetween(0, 1000000); - $model->bit_2 = $faker->numberBetween(0, 1000000); - $model->bit_3 = $faker->numberBetween(0, 1000000); - $model->ti = $faker->numberBetween(0, 1000000); - $model->int2_col = $faker->numberBetween(0, 1000000); + $model->char_8_col = $faker->optional(0.92)->sentence ?? null; + $model->decimal_col = $faker->optional(0.92)->randomFloat() ?? null; + $model->bit_col = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->bit_2 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->bit_3 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->ti = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->int2_col = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; $model->smallserial_col = $faker->numberBetween(0, 1000000); $model->serial2_col = $faker->numberBetween(0, 1000000); - $model->si_col = $faker->numberBetween(0, 1000000); - $model->si_col_2 = $faker->numberBetween(0, 1000000); - $model->bi = $faker->numberBetween(0, 1000000); - $model->bi2 = $faker->numberBetween(0, 1000000); - $model->int4_col = $faker->numberBetween(0, 1000000); + $model->si_col = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->si_col_2 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->bi = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->bi2 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->int4_col = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; $model->bigserial_col = $faker->numberBetween(0, 1000000); $model->bigserial_col_2 = $faker->numberBetween(0, 1000000); - $model->int_col = $faker->numberBetween(0, 1000000); - $model->int_col_2 = $faker->numberBetween(0, 1000000); - $model->numeric_col = $faker->randomFloat(); - $model->numeric_col_2 = $faker->randomFloat(); - $model->numeric_col_3 = $faker->randomFloat(); - $model->double_p_2 = $faker->randomFloat(); - $model->double_p_3 = $faker->randomFloat(); - $model->real_col = $faker->randomFloat(); - $model->float4_col = $faker->randomFloat(); - $model->date_col = $faker->dateTimeThisCentury->format('Y-m-d'); - $model->time_col = $faker->time('H:i:s'); - $model->time_col_2 = $faker->sentence; - $model->time_col_3 = $faker->sentence; - $model->time_col_4 = substr($faker->word(3), 0, 3); - $model->timetz_col = $faker->sentence; - $model->timetz_col_2 = substr($faker->word(3), 0, 3); - $model->timestamp_col = $faker->dateTimeThisYear('now', 'UTC')->format('Y-m-d H:i:s'); - $model->timestamp_col_2 = $faker->unixTime; - $model->timestamp_col_3 = $faker->unixTime; - $model->timestamp_col_4 = substr($faker->unixTime, 0, 3); - $model->timestamptz_col = $faker->unixTime; - $model->timestamptz_col_2 = substr($faker->unixTime, 0, 3); - $model->date2 = $faker->dateTimeThisCentury->format('Y-m-d'); - $model->timestamp_col_z = $faker->dateTimeThisYear('now', 'UTC')->format('Y-m-d H:i:s'); - $model->bit_varying = $faker->numberBetween(0, 1000000); - $model->bit_varying_n = $faker->numberBetween(0, 1000000); - $model->bit_varying_n_2 = $faker->numberBetween(0, 1000000); - $model->bit_varying_n_3 = $faker->numberBetween(0, 1000000); - $model->box_col = $faker->sentence; - $model->character_col = $faker->sentence; - $model->character_n = substr($faker->text(12), 0, 12); - $model->character_varying = $faker->sentence; - $model->character_varying_n = substr($faker->text(12), 0, 12); + $model->int_col = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->int_col_2 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->numeric_col = $faker->optional(0.92)->randomFloat() ?? null; + $model->numeric_col_2 = $faker->optional(0.92)->randomFloat() ?? null; + $model->numeric_col_3 = $faker->optional(0.92)->randomFloat() ?? null; + $model->double_p_2 = $faker->optional(0.92)->randomFloat() ?? null; + $model->double_p_3 = $faker->optional(0.92)->randomFloat() ?? null; + $model->real_col = $faker->optional(0.92)->randomFloat() ?? null; + $model->float4_col = $faker->optional(0.92)->randomFloat() ?? null; + $model->date_col = $faker->optional(0.92)->dateTimeThisCentury?->format('Y-m-d') ?? null; + $model->time_col = $faker->optional(0.92)->time('H:i:s') ?? null; + $model->time_col_2 = $faker->optional(0.92)->sentence ?? null; + $model->time_col_3 = $faker->optional(0.92)->sentence ?? null; + $model->time_col_4 = is_string($s = $faker->optional(0.92)->word(3)) ? substr($s, 0, 3) : null; + $model->timetz_col = $faker->optional(0.92)->sentence ?? null; + $model->timetz_col_2 = is_string($s = $faker->optional(0.92)->word(3)) ? substr($s, 0, 3) : null; + $model->timestamp_col = $faker->optional(0.92)->dateTimeThisYear('now', 'UTC')?->format('Y-m-d H:i:s') ?? null; + $model->timestamp_col_2 = $faker->optional(0.92)->unixTime ?? null; + $model->timestamp_col_3 = $faker->optional(0.92)->unixTime ?? null; + $model->timestamp_col_4 = is_string($s = $faker->optional(0.92)->unixTime) ? substr($s, 0, 3) : null; + $model->timestamptz_col = $faker->optional(0.92)->unixTime ?? null; + $model->timestamptz_col_2 = is_string($s = $faker->optional(0.92)->unixTime) ? substr($s, 0, 3) : null; + $model->date2 = $faker->optional(0.92)->dateTimeThisCentury?->format('Y-m-d') ?? null; + $model->timestamp_col_z = $faker->optional(0.92)->dateTimeThisYear('now', 'UTC')?->format('Y-m-d H:i:s') ?? null; + $model->bit_varying = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->bit_varying_n = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->bit_varying_n_2 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->bit_varying_n_3 = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->box_col = $faker->optional(0.92)->sentence ?? null; + $model->character_col = $faker->optional(0.92)->sentence ?? null; + $model->character_n = is_string($s = $faker->optional(0.92)->text(12)) ? substr($s, 0, 12) : null; + $model->character_varying = $faker->optional(0.92)->sentence ?? null; + $model->character_varying_n = is_string($s = $faker->optional(0.92)->text(12)) ? substr($s, 0, 12) : null; $model->json_col = []; $model->jsonb_col = []; $model->json_col_def = []; $model->json_col_def_2 = []; - $model->text_def = $faker->sentence; + $model->text_def = $faker->optional(0.92)->sentence ?? null; $model->json_def = []; $model->jsonb_def = []; - $model->cidr_col = $faker->sentence; - $model->circle_col = $faker->sentence; - $model->date_col_z = $faker->dateTimeThisCentury->format('Y-m-d'); - $model->float8_col = $faker->randomFloat(); - $model->inet_col = $faker->sentence; - $model->interval_col = $faker->sentence; - $model->interval_col_2 = $faker->sentence; - $model->interval_col_3 = substr($faker->word(3), 0, 3); - $model->line_col = $faker->sentence; - $model->lseg_col = $faker->sentence; - $model->macaddr_col = $faker->sentence; - $model->money_col = $faker->sentence; - $model->path_col = $faker->sentence; - $model->pg_lsn_col = $faker->numberBetween(0, 1000000); - $model->point_col = $faker->sentence; - $model->polygon_col = $faker->sentence; + $model->cidr_col = $faker->optional(0.92)->sentence ?? null; + $model->circle_col = $faker->optional(0.92)->sentence ?? null; + $model->date_col_z = $faker->optional(0.92)->dateTimeThisCentury?->format('Y-m-d') ?? null; + $model->float8_col = $faker->optional(0.92)->randomFloat() ?? null; + $model->inet_col = $faker->optional(0.92)->sentence ?? null; + $model->interval_col = $faker->optional(0.92)->sentence ?? null; + $model->interval_col_2 = $faker->optional(0.92)->sentence ?? null; + $model->interval_col_3 = is_string($s = $faker->optional(0.92)->word(3)) ? substr($s, 0, 3) : null; + $model->line_col = $faker->optional(0.92)->sentence ?? null; + $model->lseg_col = $faker->optional(0.92)->sentence ?? null; + $model->macaddr_col = $faker->optional(0.92)->sentence ?? null; + $model->money_col = $faker->optional(0.92)->sentence ?? null; + $model->path_col = $faker->optional(0.92)->sentence ?? null; + $model->pg_lsn_col = $faker->optional(0.92)->numberBetween(0, 1000000) ?? null; + $model->point_col = $faker->optional(0.92)->sentence ?? null; + $model->polygon_col = $faker->optional(0.92)->sentence ?? null; $model->serial_col = $faker->numberBetween(0, 1000000); $model->serial4_col = $faker->numberBetween(0, 1000000); - $model->tsquery_col = $faker->sentence; - $model->tsvector_col = $faker->sentence; - $model->txid_snapshot_col = $faker->sentence; - $model->uuid_col = $faker->sentence; - $model->xml_col = $faker->sentence; + $model->tsquery_col = $faker->optional(0.92)->sentence ?? null; + $model->tsvector_col = $faker->optional(0.92)->sentence ?? null; + $model->txid_snapshot_col = $faker->optional(0.92)->sentence ?? null; + $model->uuid_col = $faker->optional(0.92)->sentence ?? null; + $model->xml_col = $faker->optional(0.92)->sentence ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/x_db_type/rules_and_more/pgsql/app/models/pgsqlfaker/EditcolumnFaker.php b/tests/specs/x_db_type/rules_and_more/pgsql/app/models/pgsqlfaker/EditcolumnFaker.php index 6488870c..a579b152 100644 --- a/tests/specs/x_db_type/rules_and_more/pgsql/app/models/pgsqlfaker/EditcolumnFaker.php +++ b/tests/specs/x_db_type/rules_and_more/pgsql/app/models/pgsqlfaker/EditcolumnFaker.php @@ -32,10 +32,10 @@ public function generateModel($attributes = []) $model = new \app\models\pgsqlmodel\Editcolumn(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); $model->name = substr($faker->text(254), 0, 254); - $model->tag = $faker->sentence; - $model->first_name = $faker->sentence; - $model->string_col = $faker->sentence; - $model->dec_col = $faker->randomFloat(); + $model->tag = $faker->optional(0.92)->sentence ?? null; + $model->first_name = $faker->optional(0.92)->sentence ?? null; + $model->string_col = $faker->optional(0.92)->sentence ?? null; + $model->dec_col = $faker->optional(0.92)->randomFloat() ?? null; $model->str_col_def = $faker->sentence; $model->json_col = $faker->sentence; $model->json_col_2 = $faker->words(); diff --git a/tests/specs/x_db_type/rules_and_more/pgsql/app/models/pgsqlfaker/NewcolumnFaker.php b/tests/specs/x_db_type/rules_and_more/pgsql/app/models/pgsqlfaker/NewcolumnFaker.php index 1b41dae7..1adeb07f 100644 --- a/tests/specs/x_db_type/rules_and_more/pgsql/app/models/pgsqlfaker/NewcolumnFaker.php +++ b/tests/specs/x_db_type/rules_and_more/pgsql/app/models/pgsqlfaker/NewcolumnFaker.php @@ -32,12 +32,12 @@ public function generateModel($attributes = []) $model = new \app\models\pgsqlmodel\Newcolumn(); //$model->id = $uniqueFaker->numberBetween(0, 1000000); $model->name = $faker->sentence; - $model->first_name = $faker->sentence; - $model->last_name = $faker->sentence; - $model->dec_col = $faker->randomFloat(); + $model->first_name = $faker->optional(0.92)->sentence ?? null; + $model->last_name = $faker->optional(0.92)->sentence ?? null; + $model->dec_col = $faker->optional(0.92)->randomFloat() ?? null; $model->json_col = []; - $model->varchar_col = $faker->sentence; - $model->numeric_col = $faker->randomFloat(); + $model->varchar_col = $faker->optional(0.92)->sentence ?? null; + $model->numeric_col = $faker->optional(0.92)->randomFloat() ?? null; $model->json_col_def_n = []; $model->json_col_def_n_2 = []; $model->text_col_array = []; diff --git a/tests/specs/x_db_type/rules_and_more/pgsql/app/models/pgsqlfaker/PristineFaker.php b/tests/specs/x_db_type/rules_and_more/pgsql/app/models/pgsqlfaker/PristineFaker.php index aac33ab7..d57af010 100644 --- a/tests/specs/x_db_type/rules_and_more/pgsql/app/models/pgsqlfaker/PristineFaker.php +++ b/tests/specs/x_db_type/rules_and_more/pgsql/app/models/pgsqlfaker/PristineFaker.php @@ -32,16 +32,16 @@ public function generateModel($attributes = []) $model = new \app\models\pgsqlmodel\Pristine(); $model->custom_id_col = $faker->numberBetween(0, 1000000); $model->name = $faker->sentence; - $model->tag = $faker->sentence; - $model->new_col = $faker->sentence; - $model->col_5 = $faker->randomFloat(); - $model->col_6 = $faker->randomFloat(); - $model->col_7 = $faker->randomFloat(); + $model->tag = $faker->optional(0.92)->sentence ?? null; + $model->new_col = $faker->optional(0.92)->sentence ?? null; + $model->col_5 = $faker->optional(0.92)->randomFloat() ?? null; + $model->col_6 = $faker->optional(0.92)->randomFloat() ?? null; + $model->col_7 = $faker->optional(0.92)->randomFloat() ?? null; $model->col_8 = []; - $model->col_9 = $faker->sentence; - $model->col_10 = $faker->sentence; - $model->col_11 = $faker->sentence; - $model->price = $faker->randomFloat(); + $model->col_9 = $faker->optional(0.92)->sentence ?? null; + $model->col_10 = $faker->optional(0.92)->sentence ?? null; + $model->col_11 = $faker->optional(0.92)->sentence ?? null; + $model->price = $faker->optional(0.92)->randomFloat() ?? null; if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/unit/FakerStubResolverTest.php b/tests/unit/FakerStubResolverTest.php index 649928d4..681d6745 100644 --- a/tests/unit/FakerStubResolverTest.php +++ b/tests/unit/FakerStubResolverTest.php @@ -31,69 +31,70 @@ public function dataProvider() $schema = new ComponentSchema($openApiSchema, 'Fakerable'); return [ [ - (new Attribute('id'))->setPhpType('int')->setDbType(YiiDbSchema::TYPE_BIGPK), + (new Attribute('id'))->setPhpType('int')->setDbType(YiiDbSchema::TYPE_BIGPK)->setRequired(), $schema->getProperty('id'), '$uniqueFaker->numberBetween(0, 1000000)', ], [ - (new Attribute('someint'))->setPhpType('int')->setDbType(YiiDbSchema::TYPE_BIGPK), + (new Attribute('someint'))->setPhpType('int')->setDbType(YiiDbSchema::TYPE_BIGPK)->setRequired(), $schema->getProperty('id'), '$faker->numberBetween(0, 1000000)', ], [ - (new Attribute('active'))->setPhpType('bool')->setDbType(YiiDbSchema::TYPE_BOOLEAN), + (new Attribute('active'))->setPhpType('bool')->setDbType(YiiDbSchema::TYPE_BOOLEAN)->setRequired(), $schema->getProperty('active'), '$faker->boolean', ], [ - (new Attribute('floatval'))->setPhpType('float')->setDbType(YiiDbSchema::TYPE_FLOAT), + (new Attribute('floatval'))->setPhpType('float')->setDbType(YiiDbSchema::TYPE_FLOAT)->setRequired(), $schema->getProperty('floatval'), '$faker->randomFloat()', ], [ (new Attribute('doubleval')) ->setPhpType($schema->getProperty('doubleval')->guessPhpType()) - ->setDbType($schema->getProperty('doubleval')->guessDbType()), + ->setDbType($schema->getProperty('doubleval')->guessDbType()) + ->setRequired(), $schema->getProperty('doubleval'), '$faker->randomFloat()', ], [ (new Attribute('floatval_lim')) ->setPhpType('float')->setDbType(YiiDbSchema::TYPE_FLOAT) - ->setLimits(0, 1, null), + ->setLimits(0, 1, null)->setRequired(), $schema->getProperty('floatval_lim'), '$faker->randomFloat(null, 0, 1)', ], [ (new Attribute('int_simple')) - ->setPhpType('int')->setDbType(YiiDbSchema::TYPE_INTEGER), + ->setPhpType('int')->setDbType(YiiDbSchema::TYPE_INTEGER)->setRequired(), $schema->getProperty('int_simple'), '$faker->numberBetween(0, 1000000)', ], [ (new Attribute('int_created_at')) - ->setPhpType('int')->setDbType(YiiDbSchema::TYPE_INTEGER), + ->setPhpType('int')->setDbType(YiiDbSchema::TYPE_INTEGER)->setRequired(), $schema->getProperty('int_created_at'), '$faker->unixTime', ], [ (new Attribute('int_min')) ->setPhpType('int')->setDbType(YiiDbSchema::TYPE_INTEGER) - ->setLimits(5, null, null), + ->setLimits(5, null, null)->setRequired(), $schema->getProperty('int_min'), '$faker->numberBetween(5, 1000000)', ], [ (new Attribute('int_max')) ->setPhpType('int')->setDbType(YiiDbSchema::TYPE_INTEGER) - ->setLimits(null, 5, null), + ->setLimits(null, 5, null)->setRequired(), $schema->getProperty('int_max'), '$faker->numberBetween(0, 5)', ], [ (new Attribute('int_minmax')) ->setPhpType('int')->setDbType(YiiDbSchema::TYPE_INTEGER) - ->setLimits(5, 25, null), + ->setLimits(5, 25, null)->setRequired(), $schema->getProperty('int_minmax'), '$faker->numberBetween(5, 25)', ], @@ -103,30 +104,66 @@ public function dataProvider() // '$faker->uuid', // ], [ - (new Attribute('str_text'))->setPhpType('string')->setDbType(YiiDbSchema::TYPE_TEXT), + (new Attribute('str_text'))->setPhpType('string')->setDbType(YiiDbSchema::TYPE_TEXT)->setRequired(), $schema->getProperty('str_text'), '$faker->sentence', ], [ - (new Attribute('str_varchar'))->setPhpType('string')->setDbType(YiiDbSchema::TYPE_STRING), + (new Attribute('str_varchar'))->setPhpType('string')->setDbType(YiiDbSchema::TYPE_STRING)->setRequired(), $schema->getProperty('str_varchar'), '$faker->sentence', ], [ - (new Attribute('str_varchar'))->setPhpType('string')->setDbType(YiiDbSchema::TYPE_STRING)->setSize(100), + (new Attribute('str_varchar'))->setPhpType('string')->setDbType(YiiDbSchema::TYPE_STRING) + ->setSize(100)->setRequired(), $schema->getProperty('str_varchar'), 'substr($faker->text(100), 0, 100)', ], [ - (new Attribute('str_date'))->setPhpType('string')->setDbType(YiiDbSchema::TYPE_DATE), + (new Attribute('str_date'))->setPhpType('string')->setDbType(YiiDbSchema::TYPE_DATE)->setRequired(), $schema->getProperty('str_date'), '$faker->dateTimeThisCentury->format(\'Y-m-d\')', ], [ - (new Attribute('str_datetime'))->setPhpType('string')->setDbType(YiiDbSchema::TYPE_DATETIME), + (new Attribute('str_datetime'))->setPhpType('string')->setDbType(YiiDbSchema::TYPE_DATETIME)->setRequired(), $schema->getProperty('str_datetime'), '$faker->dateTimeThisYear(\'now\', \'UTC\')->format(\'Y-m-d H:i:s\')', ], + + // optional() wrapping — the 4 combinations of required×example for the date type + // (date is the most visible case: ->format() chain exercises the nullsafe ?-> replacement) + + // not required + no example → null fallback + [ + (new Attribute('str_date'))->setPhpType('string')->setDbType(YiiDbSchema::TYPE_DATE), + $schema->getProperty('str_date'), + '$faker->optional(0.92)->dateTimeThisCentury?->format(\'Y-m-d\') ?? null', + ], + // not required + has example → example as fallback + [ + (new Attribute('str_date_ex'))->setPhpType('string')->setDbType(YiiDbSchema::TYPE_DATE), + $schema->getProperty('str_date_ex'), + '$faker->optional(0.92)->dateTimeThisCentury?->format(\'Y-m-d\') ?? \'2020-03-14\'', + ], + // required + no example → no wrapping (covered by str_date above, repeated for clarity) + // required + has example → example as fallback (required does NOT block wrapping when example present) + [ + (new Attribute('str_date_ex'))->setPhpType('string')->setDbType(YiiDbSchema::TYPE_DATE)->setRequired(), + $schema->getProperty('str_date_ex'), + '$faker->optional(0.92)->dateTimeThisCentury?->format(\'Y-m-d\') ?? \'2020-03-14\'', + ], + // nullable=false + no example → no wrapping (treated like required) + [ + (new Attribute('str_date'))->setPhpType('string')->setDbType(YiiDbSchema::TYPE_DATE)->setNullable(false), + $schema->getProperty('str_date'), + '$faker->dateTimeThisCentury->format(\'Y-m-d\')', + ], + // datetime: verify nullsafe chain with ->format() and example fallback + [ + (new Attribute('str_datetime_ex'))->setPhpType('string')->setDbType(YiiDbSchema::TYPE_DATETIME), + $schema->getProperty('str_datetime_ex'), + '$faker->optional(0.92)->dateTimeThisYear(\'now\', \'UTC\')?->format(\'Y-m-d H:i:s\') ?? \'2020-03-14 21:42:17\'', + ], ]; } }