-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] add default for Mongo properties in (#340)
- Loading branch information
Showing
11 changed files
with
152 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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 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
61 changes: 61 additions & 0 deletions
61
tests/Fixtures/Maker/expected/can-create-factory-for-odm-with-data-set-document.php
This file contains 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,61 @@ | ||
<?php | ||
|
||
namespace App\Factory; | ||
|
||
use Zenstruck\Foundry\Tests\Fixtures\Document\Post; | ||
use Zenstruck\Foundry\ModelFactory; | ||
use Zenstruck\Foundry\Proxy; | ||
|
||
/** | ||
* @extends ModelFactory<Post> | ||
* | ||
* @method Post|Proxy create(array|callable $attributes = []) | ||
* @method static Post|Proxy createOne(array $attributes = []) | ||
* @method static Post|Proxy find(object|array|mixed $criteria) | ||
* @method static Post|Proxy findOrCreate(array $attributes) | ||
* @method static Post|Proxy first(string $sortedField = 'id') | ||
* @method static Post|Proxy last(string $sortedField = 'id') | ||
* @method static Post|Proxy random(array $attributes = []) | ||
* @method static Post|Proxy randomOrCreate(array $attributes = []) | ||
* @method static list<Post>|list<Proxy> all() | ||
* @method static list<Post>|list<Proxy> createMany(int $number, array|callable $attributes = []) | ||
* @method static list<Post>|list<Proxy> createSequence(array|callable $sequence) | ||
* @method static list<Post>|list<Proxy> findBy(array $attributes) | ||
* @method static list<Post>|list<Proxy> randomRange(int $min, int $max, array $attributes = []) | ||
* @method static list<Post>|list<Proxy> randomSet(int $number, array $attributes = []) | ||
*/ | ||
final class PostFactory extends ModelFactory | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
|
||
// TODO inject services if required (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services) | ||
} | ||
|
||
protected function getDefaults(): array | ||
{ | ||
return [ | ||
// TODO add your default values here (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories) | ||
'title' => self::faker()->text(), | ||
'body' => self::faker()->text(), | ||
'viewCount' => null, // TODO add INT ODM type manually | ||
'createdAt' => self::faker()->dateTime(), | ||
'comments' => null, // TODO add MANY ODM type manually | ||
'user' => null, // TODO add ONE ODM type manually | ||
]; | ||
} | ||
|
||
protected function initialize(): self | ||
{ | ||
// see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization | ||
return $this | ||
// ->afterInstantiate(function(Post $post): void {}) | ||
; | ||
} | ||
|
||
protected static function getClass(): string | ||
{ | ||
return Post::class; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
tests/Fixtures/Maker/expected/can-create-factory-for-odm-with-data-set-embedded-document.php
This file contains 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,59 @@ | ||
<?php | ||
|
||
namespace App\Factory; | ||
|
||
use Zenstruck\Foundry\Tests\Fixtures\Document\Comment; | ||
use Zenstruck\Foundry\ModelFactory; | ||
use Zenstruck\Foundry\Proxy; | ||
|
||
/** | ||
* @extends ModelFactory<Comment> | ||
* | ||
* @method Comment|Proxy create(array|callable $attributes = []) | ||
* @method static Comment|Proxy createOne(array $attributes = []) | ||
* @method static Comment|Proxy find(object|array|mixed $criteria) | ||
* @method static Comment|Proxy findOrCreate(array $attributes) | ||
* @method static Comment|Proxy first(string $sortedField = 'id') | ||
* @method static Comment|Proxy last(string $sortedField = 'id') | ||
* @method static Comment|Proxy random(array $attributes = []) | ||
* @method static Comment|Proxy randomOrCreate(array $attributes = []) | ||
* @method static list<Comment>|list<Proxy> all() | ||
* @method static list<Comment>|list<Proxy> createMany(int $number, array|callable $attributes = []) | ||
* @method static list<Comment>|list<Proxy> createSequence(array|callable $sequence) | ||
* @method static list<Comment>|list<Proxy> findBy(array $attributes) | ||
* @method static list<Comment>|list<Proxy> randomRange(int $min, int $max, array $attributes = []) | ||
* @method static list<Comment>|list<Proxy> randomSet(int $number, array $attributes = []) | ||
*/ | ||
final class CommentFactory extends ModelFactory | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
|
||
// TODO inject services if required (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services) | ||
} | ||
|
||
protected function getDefaults(): array | ||
{ | ||
return [ | ||
// TODO add your default values here (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories) | ||
'user' => null, // TODO add ONE ODM type manually | ||
'body' => self::faker()->text(), | ||
'createdAt' => self::faker()->dateTime(), | ||
'approved' => self::faker()->boolean(), | ||
]; | ||
} | ||
|
||
protected function initialize(): self | ||
{ | ||
// see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization | ||
return $this | ||
// ->afterInstantiate(function(Comment $comment): void {}) | ||
; | ||
} | ||
|
||
protected static function getClass(): string | ||
{ | ||
return Comment::class; | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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 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