-
-
Notifications
You must be signed in to change notification settings - Fork 107
feat(make:factory): default value for enum types #393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
tests/Fixtures/Maker/expected/can_create_factory_with_default_enum_with_data_set_odm.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| <?php | ||
|
|
||
| namespace App\Factory; | ||
|
|
||
| use Zenstruck\Foundry\ModelFactory; | ||
| use Zenstruck\Foundry\Proxy; | ||
| use Zenstruck\Foundry\Tests\Fixtures\PHP81\DocumentWithEnum; | ||
| use Zenstruck\Foundry\Tests\Fixtures\PHP81\SomeEnum; | ||
|
|
||
| /** | ||
| * @extends ModelFactory<DocumentWithEnum> | ||
| * | ||
| * @method DocumentWithEnum|Proxy create(array|callable $attributes = []) | ||
| * @method static DocumentWithEnum|Proxy createOne(array $attributes = []) | ||
| * @method static DocumentWithEnum|Proxy find(object|array|mixed $criteria) | ||
| * @method static DocumentWithEnum|Proxy findOrCreate(array $attributes) | ||
| * @method static DocumentWithEnum|Proxy first(string $sortedField = 'id') | ||
| * @method static DocumentWithEnum|Proxy last(string $sortedField = 'id') | ||
| * @method static DocumentWithEnum|Proxy random(array $attributes = []) | ||
| * @method static DocumentWithEnum|Proxy randomOrCreate(array $attributes = []) | ||
| * @method static DocumentWithEnum[]|Proxy[] all() | ||
| * @method static DocumentWithEnum[]|Proxy[] createMany(int $number, array|callable $attributes = []) | ||
| * @method static DocumentWithEnum[]|Proxy[] createSequence(array|callable $sequence) | ||
| * @method static DocumentWithEnum[]|Proxy[] findBy(array $attributes) | ||
| * @method static DocumentWithEnum[]|Proxy[] randomRange(int $min, int $max, array $attributes = []) | ||
| * @method static DocumentWithEnum[]|Proxy[] randomSet(int $number, array $attributes = []) | ||
| */ | ||
| final class DocumentWithEnumFactory extends ModelFactory | ||
| { | ||
| /** | ||
| * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services | ||
| * | ||
| * @todo inject services if required | ||
| */ | ||
| public function __construct() | ||
| { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| /** | ||
| * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories | ||
| * | ||
| * @todo add your default values here | ||
| */ | ||
| protected function getDefaults(): array | ||
| { | ||
| return [ | ||
| 'enum' => self::faker()->randomElement(SomeEnum::cases()), | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization | ||
| */ | ||
| protected function initialize(): self | ||
| { | ||
| return $this | ||
| // ->afterInstantiate(function(DocumentWithEnum $documentWithEnum): void {}) | ||
| ; | ||
| } | ||
|
|
||
| protected static function getClass(): string | ||
| { | ||
| return DocumentWithEnum::class; | ||
| } | ||
| } |
66 changes: 66 additions & 0 deletions
66
tests/Fixtures/Maker/expected/can_create_factory_with_default_enum_with_data_set_orm.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| <?php | ||
|
|
||
| namespace App\Factory; | ||
|
|
||
| use Zenstruck\Foundry\ModelFactory; | ||
| use Zenstruck\Foundry\Proxy; | ||
| use Zenstruck\Foundry\Tests\Fixtures\PHP81\EntityWithEnum; | ||
| use Zenstruck\Foundry\Tests\Fixtures\PHP81\SomeEnum; | ||
|
|
||
| /** | ||
| * @extends ModelFactory<EntityWithEnum> | ||
| * | ||
| * @method EntityWithEnum|Proxy create(array|callable $attributes = []) | ||
| * @method static EntityWithEnum|Proxy createOne(array $attributes = []) | ||
| * @method static EntityWithEnum|Proxy find(object|array|mixed $criteria) | ||
| * @method static EntityWithEnum|Proxy findOrCreate(array $attributes) | ||
| * @method static EntityWithEnum|Proxy first(string $sortedField = 'id') | ||
| * @method static EntityWithEnum|Proxy last(string $sortedField = 'id') | ||
| * @method static EntityWithEnum|Proxy random(array $attributes = []) | ||
| * @method static EntityWithEnum|Proxy randomOrCreate(array $attributes = []) | ||
| * @method static EntityWithEnum[]|Proxy[] all() | ||
| * @method static EntityWithEnum[]|Proxy[] createMany(int $number, array|callable $attributes = []) | ||
| * @method static EntityWithEnum[]|Proxy[] createSequence(array|callable $sequence) | ||
| * @method static EntityWithEnum[]|Proxy[] findBy(array $attributes) | ||
| * @method static EntityWithEnum[]|Proxy[] randomRange(int $min, int $max, array $attributes = []) | ||
| * @method static EntityWithEnum[]|Proxy[] randomSet(int $number, array $attributes = []) | ||
| */ | ||
| final class EntityWithEnumFactory extends ModelFactory | ||
| { | ||
| /** | ||
| * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services | ||
| * | ||
| * @todo inject services if required | ||
| */ | ||
| public function __construct() | ||
| { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| /** | ||
| * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories | ||
| * | ||
| * @todo add your default values here | ||
| */ | ||
| protected function getDefaults(): array | ||
| { | ||
| return [ | ||
| 'enum' => self::faker()->randomElement(SomeEnum::cases()), | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization | ||
| */ | ||
| protected function initialize(): self | ||
| { | ||
| return $this | ||
| // ->afterInstantiate(function(EntityWithEnum $entityWithEnum): void {}) | ||
| ; | ||
| } | ||
|
|
||
| protected static function getClass(): string | ||
| { | ||
| return EntityWithEnum::class; | ||
| } | ||
| } |
57 changes: 57 additions & 0 deletions
57
...Maker/expected/can_create_factory_with_default_enum_with_data_set_without_persistance.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <?php | ||
|
|
||
| namespace App\Factory; | ||
|
|
||
| use Zenstruck\Foundry\ModelFactory; | ||
| use Zenstruck\Foundry\Proxy; | ||
| use Zenstruck\Foundry\Tests\Fixtures\PHP81\EntityWithEnum; | ||
| use Zenstruck\Foundry\Tests\Fixtures\PHP81\SomeEnum; | ||
|
|
||
| /** | ||
| * @extends ModelFactory<EntityWithEnum> | ||
| * | ||
| * @method EntityWithEnum|Proxy create(array|callable $attributes = []) | ||
| * @method static EntityWithEnum|Proxy createOne(array $attributes = []) | ||
| * @method static EntityWithEnum[]|Proxy[] createMany(int $number, array|callable $attributes = []) | ||
| * @method static EntityWithEnum[]|Proxy[] createSequence(array|callable $sequence) | ||
| */ | ||
| final class EntityWithEnumFactory extends ModelFactory | ||
| { | ||
| /** | ||
| * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services | ||
| * | ||
| * @todo inject services if required | ||
| */ | ||
| public function __construct() | ||
| { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| /** | ||
| * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories | ||
| * | ||
| * @todo add your default values here | ||
| */ | ||
| protected function getDefaults(): array | ||
| { | ||
| return [ | ||
| 'enum' => self::faker()->randomElement(SomeEnum::cases()), | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization | ||
| */ | ||
| protected function initialize(): self | ||
| { | ||
| return $this | ||
| ->withoutPersisting() | ||
| // ->afterInstantiate(function(EntityWithEnum $entityWithEnum): void {}) | ||
| ; | ||
| } | ||
|
|
||
| protected static function getClass(): string | ||
| { | ||
| return EntityWithEnum::class; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.