diff --git a/src/Autocomplete/composer.json b/src/Autocomplete/composer.json index 040fdf157f6..f8253d95b9d 100644 --- a/src/Autocomplete/composer.json +++ b/src/Autocomplete/composer.json @@ -48,7 +48,7 @@ "symfony/uid": "^6.3|^7.0", "twig/twig": "^2.14.7|^3.0.4", "zenstruck/browser": "^1.1", - "zenstruck/foundry": "1.37.*" + "zenstruck/foundry": "^2.0" }, "conflict": { "doctrine/orm": "2.9.0 || 2.9.1" diff --git a/src/Autocomplete/tests/Fixtures/Factory/CategoryFactory.php b/src/Autocomplete/tests/Fixtures/Factory/CategoryFactory.php index 8e255cb2052..71ef991a6ca 100644 --- a/src/Autocomplete/tests/Fixtures/Factory/CategoryFactory.php +++ b/src/Autocomplete/tests/Fixtures/Factory/CategoryFactory.php @@ -11,33 +11,15 @@ namespace Symfony\UX\Autocomplete\Tests\Fixtures\Factory; -use Doctrine\ORM\EntityRepository; use Symfony\UX\Autocomplete\Tests\Fixtures\Entity\Category; -use Zenstruck\Foundry\ModelFactory; -use Zenstruck\Foundry\Proxy; -use Zenstruck\Foundry\RepositoryProxy; +use Zenstruck\Foundry\Persistence\PersistentObjectFactory; /** - * @extends ModelFactory - * - * @method static Category|Proxy createOne(array $attributes = []) - * @method static Category[]|Proxy[] createMany(int $number, array|callable $attributes = []) - * @method static Category|Proxy find(object|array|mixed $criteria) - * @method static Category|Proxy findOrCreate(array $attributes) - * @method static Category|Proxy first(string $sortedField = 'id') - * @method static Category|Proxy last(string $sortedField = 'id') - * @method static Category|Proxy random(array $attributes = []) - * @method static Category|Proxy randomOrCreate(array $attributes = [])) - * @method static Category[]|Proxy[] all() - * @method static Category[]|Proxy[] findBy(array $attributes) - * @method static Category[]|Proxy[] randomSet(int $number, array $attributes = [])) - * @method static Category[]|Proxy[] randomRange(int $min, int $max, array $attributes = [])) - * @method static EntityRepository|RepositoryProxy repository() - * @method Category|Proxy create(array|callable $attributes = []) + * @extends PersistentObjectFactory */ -final class CategoryFactory extends ModelFactory +final class CategoryFactory extends PersistentObjectFactory { - protected function getDefaults(): array + protected function defaults(): array { $name = self::faker()->name(); return [ @@ -46,12 +28,7 @@ protected function getDefaults(): array ]; } - protected function initialize(): self - { - return $this; - } - - protected static function getClass(): string + public static function class(): string { return Category::class; } diff --git a/src/Autocomplete/tests/Fixtures/Factory/CategoryTagFactory.php b/src/Autocomplete/tests/Fixtures/Factory/CategoryTagFactory.php index 32eec81c1a2..9234df82aab 100644 --- a/src/Autocomplete/tests/Fixtures/Factory/CategoryTagFactory.php +++ b/src/Autocomplete/tests/Fixtures/Factory/CategoryTagFactory.php @@ -11,46 +11,23 @@ namespace Symfony\UX\Autocomplete\Tests\Fixtures\Factory; -use Doctrine\ORM\EntityRepository; use Symfony\UX\Autocomplete\Tests\Fixtures\Entity\CategoryTag; -use Zenstruck\Foundry\ModelFactory; -use Zenstruck\Foundry\Proxy; -use Zenstruck\Foundry\RepositoryProxy; +use Zenstruck\Foundry\Persistence\PersistentObjectFactory; /** - * @extends ModelFactory - * - * @method static CategoryTag|Proxy createOne(array $attributes = []) - * @method static CategoryTag[]|Proxy[] createMany(int $number, array|callable $attributes = []) - * @method static CategoryTag|Proxy find(object|array|mixed $criteria) - * @method static CategoryTag|Proxy findOrCreate(array $attributes) - * @method static CategoryTag|Proxy first(string $sortedField = 'id') - * @method static CategoryTag|Proxy last(string $sortedField = 'id') - * @method static CategoryTag|Proxy random(array $attributes = []) - * @method static CategoryTag|Proxy randomOrCreate(array $attributes = []) - * @method static CategoryTag[]|Proxy[] all() - * @method static CategoryTag[]|Proxy[] findBy(array $attributes) - * @method static CategoryTag[]|Proxy[] randomSet(int $number, array $attributes = []) - * @method static CategoryTag[]|Proxy[] randomRange(int $min, int $max, array $attributes = []) - * @method static EntityRepository|RepositoryProxy repository() - * @method CategoryTag|Proxy create(array|callable $attributes = []) + * @extends PersistentObjectFactory */ -final class CategoryTagFactory extends ModelFactory +final class CategoryTagFactory extends PersistentObjectFactory { - protected function getDefaults(): array - { - return [ - 'name' => self::faker()->word(), - ]; - } - - protected function initialize(): self + public static function class(): string { - return $this; + return CategoryTag::class; } - protected static function getClass(): string + protected function defaults(): array { - return CategoryTag::class; + return [ + 'name' => self::faker()->word(), + ]; } } diff --git a/src/Autocomplete/tests/Fixtures/Factory/IngredientFactory.php b/src/Autocomplete/tests/Fixtures/Factory/IngredientFactory.php index 4669fa9899b..6f12a56aab7 100644 --- a/src/Autocomplete/tests/Fixtures/Factory/IngredientFactory.php +++ b/src/Autocomplete/tests/Fixtures/Factory/IngredientFactory.php @@ -11,48 +11,25 @@ namespace Symfony\UX\Autocomplete\Tests\Fixtures\Factory; -use Doctrine\ORM\EntityRepository; use Symfony\Component\Uid\UuidV4; use Symfony\UX\Autocomplete\Tests\Fixtures\Entity\Ingredient; -use Zenstruck\Foundry\ModelFactory; -use Zenstruck\Foundry\Proxy; -use Zenstruck\Foundry\RepositoryProxy; +use Zenstruck\Foundry\Persistence\PersistentObjectFactory; /** - * @extends ModelFactory - * - * @method static Ingredient|Proxy createOne(array $attributes = []) - * @method static Ingredient[]|Proxy[] createMany(int $number, array|callable $attributes = []) - * @method static Ingredient|Proxy find(object|array|mixed $criteria) - * @method static Ingredient|Proxy findOrCreate(array $attributes) - * @method static Ingredient|Proxy first(string $sortedField = 'id') - * @method static Ingredient|Proxy last(string $sortedField = 'id') - * @method static Ingredient|Proxy random(array $attributes = []) - * @method static Ingredient|Proxy randomOrCreate(array $attributes = [])) - * @method static Ingredient[]|Proxy[] all() - * @method static Ingredient[]|Proxy[] findBy(array $attributes) - * @method static Ingredient[]|Proxy[] randomSet(int $number, array $attributes = [])) - * @method static Ingredient[]|Proxy[] randomRange(int $min, int $max, array $attributes = [])) - * @method static EntityRepository|RepositoryProxy repository() - * @method Ingredient|Proxy create(array|callable $attributes = []) + * @extends PersistentObjectFactory */ -final class IngredientFactory extends ModelFactory +final class IngredientFactory extends PersistentObjectFactory { - protected function getDefaults(): array + public static function class(): string + { + return Ingredient::class; + } + + protected function defaults(): array { return [ 'id' => new UuidV4(), 'name' => self::faker()->text(), ]; } - - protected function initialize(): self - { - return $this; - } - - protected static function getClass(): string - { - return Ingredient::class; - } } diff --git a/src/Autocomplete/tests/Fixtures/Factory/ProductFactory.php b/src/Autocomplete/tests/Fixtures/Factory/ProductFactory.php index 975c10be792..264486d1d96 100644 --- a/src/Autocomplete/tests/Fixtures/Factory/ProductFactory.php +++ b/src/Autocomplete/tests/Fixtures/Factory/ProductFactory.php @@ -13,31 +13,19 @@ use Doctrine\ORM\EntityRepository; use Symfony\UX\Autocomplete\Tests\Fixtures\Entity\Product; -use Zenstruck\Foundry\ModelFactory; -use Zenstruck\Foundry\Proxy; -use Zenstruck\Foundry\RepositoryProxy; +use Zenstruck\Foundry\Persistence\PersistentObjectFactory; /** - * @extends ModelFactory - * - * @method static Product|Proxy createOne(array $attributes = []) - * @method static Product[]|Proxy[] createMany(int $number, array|callable $attributes = []) - * @method static Product|Proxy find(object|array|mixed $criteria) - * @method static Product|Proxy findOrCreate(array $attributes) - * @method static Product|Proxy first(string $sortedField = 'id') - * @method static Product|Proxy last(string $sortedField = 'id') - * @method static Product|Proxy random(array $attributes = []) - * @method static Product|Proxy randomOrCreate(array $attributes = [])) - * @method static Product[]|Proxy[] all() - * @method static Product[]|Proxy[] findBy(array $attributes) - * @method static Product[]|Proxy[] randomSet(int $number, array $attributes = [])) - * @method static Product[]|Proxy[] randomRange(int $min, int $max, array $attributes = [])) - * @method static EntityRepository|RepositoryProxy repository() - * @method Product|Proxy create(array|callable $attributes = []) + * @extends PersistentObjectFactory */ -final class ProductFactory extends ModelFactory +final class ProductFactory extends PersistentObjectFactory { - protected function getDefaults(): array + public static function class(): string + { + return Product::class; + } + + protected function defaults(): array { return [ 'name' => self::faker()->text(), @@ -47,18 +35,8 @@ protected function getDefaults(): array ]; } - protected function initialize(): self - { - return $this; - } - public function disable(): self { - return $this->addState(['isEnabled' => false]); - } - - protected static function getClass(): string - { - return Product::class; + return $this->with(['isEnabled' => false]); } } diff --git a/src/Autocomplete/tests/Fixtures/Factory/ProductTagFactory.php b/src/Autocomplete/tests/Fixtures/Factory/ProductTagFactory.php index 868d61fca4d..424f76f5c58 100644 --- a/src/Autocomplete/tests/Fixtures/Factory/ProductTagFactory.php +++ b/src/Autocomplete/tests/Fixtures/Factory/ProductTagFactory.php @@ -14,43 +14,24 @@ use Doctrine\ORM\EntityRepository; use Symfony\UX\Autocomplete\Tests\Fixtures\Entity\ProductTag; use Zenstruck\Foundry\ModelFactory; +use Zenstruck\Foundry\Persistence\PersistentObjectFactory; use Zenstruck\Foundry\Proxy; use Zenstruck\Foundry\RepositoryProxy; /** - * @extends ModelFactory - * - * @method static ProductTag|Proxy createOne(array $attributes = []) - * @method static ProductTag[]|Proxy[] createMany(int $number, array|callable $attributes = []) - * @method static ProductTag|Proxy find(object|array|mixed $criteria) - * @method static ProductTag|Proxy findOrCreate(array $attributes) - * @method static ProductTag|Proxy first(string $sortedField = 'id') - * @method static ProductTag|Proxy last(string $sortedField = 'id') - * @method static ProductTag|Proxy random(array $attributes = []) - * @method static ProductTag|Proxy randomOrCreate(array $attributes = []) - * @method static ProductTag[]|Proxy[] all() - * @method static ProductTag[]|Proxy[] findBy(array $attributes) - * @method static ProductTag[]|Proxy[] randomSet(int $number, array $attributes = []) - * @method static ProductTag[]|Proxy[] randomRange(int $min, int $max, array $attributes = []) - * @method static EntityRepository|RepositoryProxy repository() - * @method ProductTag|Proxy create(array|callable $attributes = []) + * @extends PersistentObjectFactory */ -final class ProductTagFactory extends ModelFactory +final class ProductTagFactory extends PersistentObjectFactory { - protected function getDefaults(): array - { - return [ - 'name' => self::faker()->word(), - ]; - } - - protected function initialize(): self + public static function class(): string { - return $this; + return ProductTag::class; } - protected static function getClass(): string + protected function defaults(): array { - return ProductTag::class; + return [ + 'name' => self::faker()->word(), + ]; } } diff --git a/src/Autocomplete/tests/Fixtures/Kernel.php b/src/Autocomplete/tests/Fixtures/Kernel.php index 7fc8adcf64c..b8439ae40a4 100644 --- a/src/Autocomplete/tests/Fixtures/Kernel.php +++ b/src/Autocomplete/tests/Fixtures/Kernel.php @@ -101,9 +101,7 @@ protected function configureContainer(ContainerConfigurator $c): void 'default_path' => '%kernel.project_dir%/tests/Fixtures/templates', ]); - $c->extension('zenstruck_foundry', [ - 'auto_refresh_proxies' => false, - ]); + $c->extension('zenstruck_foundry', []); $doctrineConfig = [ 'dbal' => ['url' => '%env(resolve:DATABASE_URL)%'], @@ -155,10 +153,6 @@ protected function configureContainer(ContainerConfigurator $c): void ], ]); - $c->extension('zenstruck_foundry', [ - 'auto_refresh_proxies' => false, - ]); - $services = $c->services(); $services ->defaults() diff --git a/src/Autocomplete/tests/Integration/Doctrine/EntityMetadataTest.php b/src/Autocomplete/tests/Integration/Doctrine/EntityMetadataTest.php index 40bed6f795d..0d6a73df4ac 100644 --- a/src/Autocomplete/tests/Integration/Doctrine/EntityMetadataTest.php +++ b/src/Autocomplete/tests/Integration/Doctrine/EntityMetadataTest.php @@ -43,7 +43,7 @@ public function testIsAssociation(): void public function testGetIdValue(): void { $product = ProductFactory::createOne(); - $this->assertEquals($product->getId(), $this->getMetadata()->getIdValue($product->object())); + $this->assertEquals($product->getId(), $this->getMetadata()->getIdValue($product)); } public function testGetPropertyDataType(): void diff --git a/src/Autocomplete/tests/Integration/Doctrine/EntitySearchUtilTest.php b/src/Autocomplete/tests/Integration/Doctrine/EntitySearchUtilTest.php index e10560fc7ab..90dd33b354e 100644 --- a/src/Autocomplete/tests/Integration/Doctrine/EntitySearchUtilTest.php +++ b/src/Autocomplete/tests/Integration/Doctrine/EntitySearchUtilTest.php @@ -34,7 +34,7 @@ public function testItCreatesBasicStringSearchQuery(): void $prod4 = ProductFactory::createOne(['description' => 'all about prod 4']); $results = $this->callAddSearchClass('prod'); - $this->assertSame([$prod1->object(), $prod2->object(), $prod4->object()], $results); + $this->assertSame([$prod1, $prod2, $prod4], $results); } public function testItSearchesOnCorrectFields(): void @@ -43,7 +43,7 @@ public function testItSearchesOnCorrectFields(): void ProductFactory::createOne(['description' => 'foo prod2']); $results = $this->callAddSearchClass('prod', ['name']); - $this->assertSame([$prod1->object()], $results); + $this->assertSame([$prod1], $results); } public function testItCanSearchOnRelationFields(): void @@ -55,7 +55,7 @@ public function testItCanSearchOnRelationFields(): void ProductFactory::createOne(['name' => 'puzzle', 'category' => $category2]); $results = $this->callAddSearchClass('food', ['name', 'category.name']); - $this->assertSame([$prod1->object(), $prod2->object()], $results); + $this->assertSame([$prod1, $prod2], $results); } /** diff --git a/src/LiveComponent/tests/Fixtures/Kernel.php b/src/LiveComponent/tests/Fixtures/Kernel.php index 4b0cd90d143..9b39acb9a27 100644 --- a/src/LiveComponent/tests/Fixtures/Kernel.php +++ b/src/LiveComponent/tests/Fixtures/Kernel.php @@ -143,9 +143,7 @@ protected function configureContainer(ContainerConfigurator $c): void 'anonymous_template_directory' => 'components/', ]); - $c->extension('zenstruck_foundry', [ - 'auto_refresh_proxies' => false, - ]); + $c->extension('zenstruck_foundry', []); $doctrineConfig = [ 'dbal' => [