Create a simple test to play with foundry - problem with test db remaining

This commit is contained in:
2024-02-13 16:04:10 +01:00
parent aee8e17cfa
commit 1a213ab5f8
5 changed files with 366 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
<?php
namespace Chill\MainBundle\Factory\Embeddable;
use Chill\MainBundle\Entity\Embeddable\PrivateCommentEmbeddable;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Proxy;
/**
* @extends ModelFactory<PrivateCommentEmbeddable>
*
* @method PrivateCommentEmbeddable|Proxy create(array|callable $attributes = [])
* @method static PrivateCommentEmbeddable|Proxy createOne(array $attributes = [])
* @method static PrivateCommentEmbeddable[]|Proxy[] createMany(int $number, array|callable $attributes = [])
* @method static PrivateCommentEmbeddable[]|Proxy[] createSequence(iterable|callable $sequence)
*
* @phpstan-method Proxy<PrivateCommentEmbeddable> create(array|callable $attributes = [])
* @phpstan-method static Proxy<PrivateCommentEmbeddable> createOne(array $attributes = [])
*/
final class PrivateCommentEmbeddableFactory 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 [
];
}
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
*/
protected function initialize(): self
{
return $this
->withoutPersisting()
// ->afterInstantiate(function(PrivateCommentEmbeddable $privateCommentEmbeddable): void {})
;
}
protected static function getClass(): string
{
return PrivateCommentEmbeddable::class;
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace Chill\MainBundle\Factory;
use Chill\MainBundle\Entity\User;
use Doctrine\ORM\EntityRepository;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Proxy;
use Zenstruck\Foundry\RepositoryProxy;
/**
* @extends ModelFactory<User>
*
* @method User|Proxy create(array|callable $attributes = [])
* @method static User|Proxy createOne(array $attributes = [])
* @method static User|Proxy find(object|array|mixed $criteria)
* @method static User|Proxy findOrCreate(array $attributes)
* @method static User|Proxy first(string $sortedField = 'id')
* @method static User|Proxy last(string $sortedField = 'id')
* @method static User|Proxy random(array $attributes = [])
* @method static User|Proxy randomOrCreate(array $attributes = [])
* @method static EntityRepository|RepositoryProxy repository()
* @method static User[]|Proxy[] all()
* @method static User[]|Proxy[] createMany(int $number, array|callable $attributes = [])
* @method static User[]|Proxy[] createSequence(iterable|callable $sequence)
* @method static User[]|Proxy[] findBy(array $attributes)
* @method static User[]|Proxy[] randomRange(int $min, int $max, array $attributes = [])
* @method static User[]|Proxy[] randomSet(int $number, array $attributes = [])
*
* @phpstan-method Proxy<User> create(array|callable $attributes = [])
* @phpstan-method static Proxy<User> createOne(array $attributes = [])
* @phpstan-method static Proxy<User> find(object|array|mixed $criteria)
* @phpstan-method static Proxy<User> findOrCreate(array $attributes)
* @phpstan-method static Proxy<User> first(string $sortedField = 'id')
* @phpstan-method static Proxy<User> last(string $sortedField = 'id')
* @phpstan-method static Proxy<User> random(array $attributes = [])
* @phpstan-method static Proxy<User> randomOrCreate(array $attributes = [])
* @phpstan-method static RepositoryProxy<User> repository()
*/
final class UserFactory 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 [
'attributes' => [],
'enabled' => self::faker()->boolean(),
'label' => self::faker()->text(200),
'locked' => self::faker()->boolean(),
'password' => self::faker()->text(255),
'username' => self::faker()->text(80),
];
}
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
*/
protected function initialize(): self
{
return $this
// ->afterInstantiate(function(User $user): void {})
;
}
protected static function getClass(): string
{
return User::class;
}
}