Skip to content

Commit 2e2e3e8

Browse files
committed
minor #2928 [Autocomplete] Upgrade Foundry to ^2.0 (Kocal)
This PR was merged into the 2.x branch. Discussion ---------- [Autocomplete] Upgrade Foundry to ^2.0 | Q | A | ------------- | --- | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Docs? | no <!-- required for new features --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT <!-- Replace this notice by a description of your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - For new features, provide some code snippets to help understand usage. - Features and deprecations must be submitted against branch main. - Update/add documentation as required (we can help!) - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> Minor work to upgrade Foundry 1.37.* to ^2.0 on Autocomplete, and remove some Foundry deprecations (also applied to LiveComponent) Commits ------- 5160681 [Autocomplete] Upgrade Foundry to ^2.0
2 parents ebdb5bd + 5160681 commit 2e2e3e8

File tree

10 files changed

+49
-167
lines changed

10 files changed

+49
-167
lines changed

src/Autocomplete/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"symfony/uid": "^6.3|^7.0",
4949
"twig/twig": "^2.14.7|^3.0.4",
5050
"zenstruck/browser": "^1.1",
51-
"zenstruck/foundry": "1.37.*"
51+
"zenstruck/foundry": "^2.0"
5252
},
5353
"conflict": {
5454
"doctrine/orm": "2.9.0 || 2.9.1"

src/Autocomplete/tests/Fixtures/Factory/CategoryFactory.php

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,15 @@
1111

1212
namespace Symfony\UX\Autocomplete\Tests\Fixtures\Factory;
1313

14-
use Doctrine\ORM\EntityRepository;
1514
use Symfony\UX\Autocomplete\Tests\Fixtures\Entity\Category;
16-
use Zenstruck\Foundry\ModelFactory;
17-
use Zenstruck\Foundry\Proxy;
18-
use Zenstruck\Foundry\RepositoryProxy;
15+
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
1916

2017
/**
21-
* @extends ModelFactory<Category>
22-
*
23-
* @method static Category|Proxy createOne(array $attributes = [])
24-
* @method static Category[]|Proxy[] createMany(int $number, array|callable $attributes = [])
25-
* @method static Category|Proxy find(object|array|mixed $criteria)
26-
* @method static Category|Proxy findOrCreate(array $attributes)
27-
* @method static Category|Proxy first(string $sortedField = 'id')
28-
* @method static Category|Proxy last(string $sortedField = 'id')
29-
* @method static Category|Proxy random(array $attributes = [])
30-
* @method static Category|Proxy randomOrCreate(array $attributes = []))
31-
* @method static Category[]|Proxy[] all()
32-
* @method static Category[]|Proxy[] findBy(array $attributes)
33-
* @method static Category[]|Proxy[] randomSet(int $number, array $attributes = []))
34-
* @method static Category[]|Proxy[] randomRange(int $min, int $max, array $attributes = []))
35-
* @method static EntityRepository|RepositoryProxy repository()
36-
* @method Category|Proxy create(array|callable $attributes = [])
18+
* @extends PersistentObjectFactory<Category>
3719
*/
38-
final class CategoryFactory extends ModelFactory
20+
final class CategoryFactory extends PersistentObjectFactory
3921
{
40-
protected function getDefaults(): array
22+
protected function defaults(): array
4123
{
4224
$name = self::faker()->name();
4325
return [
@@ -46,12 +28,7 @@ protected function getDefaults(): array
4628
];
4729
}
4830

49-
protected function initialize(): self
50-
{
51-
return $this;
52-
}
53-
54-
protected static function getClass(): string
31+
public static function class(): string
5532
{
5633
return Category::class;
5734
}

src/Autocomplete/tests/Fixtures/Factory/CategoryTagFactory.php

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,23 @@
1111

1212
namespace Symfony\UX\Autocomplete\Tests\Fixtures\Factory;
1313

14-
use Doctrine\ORM\EntityRepository;
1514
use Symfony\UX\Autocomplete\Tests\Fixtures\Entity\CategoryTag;
16-
use Zenstruck\Foundry\ModelFactory;
17-
use Zenstruck\Foundry\Proxy;
18-
use Zenstruck\Foundry\RepositoryProxy;
15+
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
1916

2017
/**
21-
* @extends ModelFactory<CategoryTag>
22-
*
23-
* @method static CategoryTag|Proxy createOne(array $attributes = [])
24-
* @method static CategoryTag[]|Proxy[] createMany(int $number, array|callable $attributes = [])
25-
* @method static CategoryTag|Proxy find(object|array|mixed $criteria)
26-
* @method static CategoryTag|Proxy findOrCreate(array $attributes)
27-
* @method static CategoryTag|Proxy first(string $sortedField = 'id')
28-
* @method static CategoryTag|Proxy last(string $sortedField = 'id')
29-
* @method static CategoryTag|Proxy random(array $attributes = [])
30-
* @method static CategoryTag|Proxy randomOrCreate(array $attributes = [])
31-
* @method static CategoryTag[]|Proxy[] all()
32-
* @method static CategoryTag[]|Proxy[] findBy(array $attributes)
33-
* @method static CategoryTag[]|Proxy[] randomSet(int $number, array $attributes = [])
34-
* @method static CategoryTag[]|Proxy[] randomRange(int $min, int $max, array $attributes = [])
35-
* @method static EntityRepository|RepositoryProxy repository()
36-
* @method CategoryTag|Proxy create(array|callable $attributes = [])
18+
* @extends PersistentObjectFactory<CategoryTag>
3719
*/
38-
final class CategoryTagFactory extends ModelFactory
20+
final class CategoryTagFactory extends PersistentObjectFactory
3921
{
40-
protected function getDefaults(): array
41-
{
42-
return [
43-
'name' => self::faker()->word(),
44-
];
45-
}
46-
47-
protected function initialize(): self
22+
public static function class(): string
4823
{
49-
return $this;
24+
return CategoryTag::class;
5025
}
5126

52-
protected static function getClass(): string
27+
protected function defaults(): array
5328
{
54-
return CategoryTag::class;
29+
return [
30+
'name' => self::faker()->word(),
31+
];
5532
}
5633
}

src/Autocomplete/tests/Fixtures/Factory/IngredientFactory.php

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,25 @@
1111

1212
namespace Symfony\UX\Autocomplete\Tests\Fixtures\Factory;
1313

14-
use Doctrine\ORM\EntityRepository;
1514
use Symfony\Component\Uid\UuidV4;
1615
use Symfony\UX\Autocomplete\Tests\Fixtures\Entity\Ingredient;
17-
use Zenstruck\Foundry\ModelFactory;
18-
use Zenstruck\Foundry\Proxy;
19-
use Zenstruck\Foundry\RepositoryProxy;
16+
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
2017

2118
/**
22-
* @extends ModelFactory<Ingredient>
23-
*
24-
* @method static Ingredient|Proxy createOne(array $attributes = [])
25-
* @method static Ingredient[]|Proxy[] createMany(int $number, array|callable $attributes = [])
26-
* @method static Ingredient|Proxy find(object|array|mixed $criteria)
27-
* @method static Ingredient|Proxy findOrCreate(array $attributes)
28-
* @method static Ingredient|Proxy first(string $sortedField = 'id')
29-
* @method static Ingredient|Proxy last(string $sortedField = 'id')
30-
* @method static Ingredient|Proxy random(array $attributes = [])
31-
* @method static Ingredient|Proxy randomOrCreate(array $attributes = []))
32-
* @method static Ingredient[]|Proxy[] all()
33-
* @method static Ingredient[]|Proxy[] findBy(array $attributes)
34-
* @method static Ingredient[]|Proxy[] randomSet(int $number, array $attributes = []))
35-
* @method static Ingredient[]|Proxy[] randomRange(int $min, int $max, array $attributes = []))
36-
* @method static EntityRepository|RepositoryProxy repository()
37-
* @method Ingredient|Proxy create(array|callable $attributes = [])
19+
* @extends PersistentObjectFactory<Ingredient>
3820
*/
39-
final class IngredientFactory extends ModelFactory
21+
final class IngredientFactory extends PersistentObjectFactory
4022
{
41-
protected function getDefaults(): array
23+
public static function class(): string
24+
{
25+
return Ingredient::class;
26+
}
27+
28+
protected function defaults(): array
4229
{
4330
return [
4431
'id' => new UuidV4(),
4532
'name' => self::faker()->text(),
4633
];
4734
}
48-
49-
protected function initialize(): self
50-
{
51-
return $this;
52-
}
53-
54-
protected static function getClass(): string
55-
{
56-
return Ingredient::class;
57-
}
5835
}

src/Autocomplete/tests/Fixtures/Factory/ProductFactory.php

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,19 @@
1313

1414
use Doctrine\ORM\EntityRepository;
1515
use Symfony\UX\Autocomplete\Tests\Fixtures\Entity\Product;
16-
use Zenstruck\Foundry\ModelFactory;
17-
use Zenstruck\Foundry\Proxy;
18-
use Zenstruck\Foundry\RepositoryProxy;
16+
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
1917

2018
/**
21-
* @extends ModelFactory<Product>
22-
*
23-
* @method static Product|Proxy createOne(array $attributes = [])
24-
* @method static Product[]|Proxy[] createMany(int $number, array|callable $attributes = [])
25-
* @method static Product|Proxy find(object|array|mixed $criteria)
26-
* @method static Product|Proxy findOrCreate(array $attributes)
27-
* @method static Product|Proxy first(string $sortedField = 'id')
28-
* @method static Product|Proxy last(string $sortedField = 'id')
29-
* @method static Product|Proxy random(array $attributes = [])
30-
* @method static Product|Proxy randomOrCreate(array $attributes = []))
31-
* @method static Product[]|Proxy[] all()
32-
* @method static Product[]|Proxy[] findBy(array $attributes)
33-
* @method static Product[]|Proxy[] randomSet(int $number, array $attributes = []))
34-
* @method static Product[]|Proxy[] randomRange(int $min, int $max, array $attributes = []))
35-
* @method static EntityRepository|RepositoryProxy repository()
36-
* @method Product|Proxy create(array|callable $attributes = [])
19+
* @extends PersistentObjectFactory<Product>
3720
*/
38-
final class ProductFactory extends ModelFactory
21+
final class ProductFactory extends PersistentObjectFactory
3922
{
40-
protected function getDefaults(): array
23+
public static function class(): string
24+
{
25+
return Product::class;
26+
}
27+
28+
protected function defaults(): array
4129
{
4230
return [
4331
'name' => self::faker()->text(),
@@ -47,18 +35,8 @@ protected function getDefaults(): array
4735
];
4836
}
4937

50-
protected function initialize(): self
51-
{
52-
return $this;
53-
}
54-
5538
public function disable(): self
5639
{
57-
return $this->addState(['isEnabled' => false]);
58-
}
59-
60-
protected static function getClass(): string
61-
{
62-
return Product::class;
40+
return $this->with(['isEnabled' => false]);
6341
}
6442
}

src/Autocomplete/tests/Fixtures/Factory/ProductTagFactory.php

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,24 @@
1414
use Doctrine\ORM\EntityRepository;
1515
use Symfony\UX\Autocomplete\Tests\Fixtures\Entity\ProductTag;
1616
use Zenstruck\Foundry\ModelFactory;
17+
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
1718
use Zenstruck\Foundry\Proxy;
1819
use Zenstruck\Foundry\RepositoryProxy;
1920

2021
/**
21-
* @extends ModelFactory<ProductTag>
22-
*
23-
* @method static ProductTag|Proxy createOne(array $attributes = [])
24-
* @method static ProductTag[]|Proxy[] createMany(int $number, array|callable $attributes = [])
25-
* @method static ProductTag|Proxy find(object|array|mixed $criteria)
26-
* @method static ProductTag|Proxy findOrCreate(array $attributes)
27-
* @method static ProductTag|Proxy first(string $sortedField = 'id')
28-
* @method static ProductTag|Proxy last(string $sortedField = 'id')
29-
* @method static ProductTag|Proxy random(array $attributes = [])
30-
* @method static ProductTag|Proxy randomOrCreate(array $attributes = [])
31-
* @method static ProductTag[]|Proxy[] all()
32-
* @method static ProductTag[]|Proxy[] findBy(array $attributes)
33-
* @method static ProductTag[]|Proxy[] randomSet(int $number, array $attributes = [])
34-
* @method static ProductTag[]|Proxy[] randomRange(int $min, int $max, array $attributes = [])
35-
* @method static EntityRepository|RepositoryProxy repository()
36-
* @method ProductTag|Proxy create(array|callable $attributes = [])
22+
* @extends PersistentObjectFactory<ProductTag>
3723
*/
38-
final class ProductTagFactory extends ModelFactory
24+
final class ProductTagFactory extends PersistentObjectFactory
3925
{
40-
protected function getDefaults(): array
41-
{
42-
return [
43-
'name' => self::faker()->word(),
44-
];
45-
}
46-
47-
protected function initialize(): self
26+
public static function class(): string
4827
{
49-
return $this;
28+
return ProductTag::class;
5029
}
5130

52-
protected static function getClass(): string
31+
protected function defaults(): array
5332
{
54-
return ProductTag::class;
33+
return [
34+
'name' => self::faker()->word(),
35+
];
5536
}
5637
}

src/Autocomplete/tests/Fixtures/Kernel.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ protected function configureContainer(ContainerConfigurator $c): void
101101
'default_path' => '%kernel.project_dir%/tests/Fixtures/templates',
102102
]);
103103

104-
$c->extension('zenstruck_foundry', [
105-
'auto_refresh_proxies' => false,
106-
]);
104+
$c->extension('zenstruck_foundry', []);
107105

108106
$doctrineConfig = [
109107
'dbal' => ['url' => '%env(resolve:DATABASE_URL)%'],
@@ -155,10 +153,6 @@ protected function configureContainer(ContainerConfigurator $c): void
155153
],
156154
]);
157155

158-
$c->extension('zenstruck_foundry', [
159-
'auto_refresh_proxies' => false,
160-
]);
161-
162156
$services = $c->services();
163157
$services
164158
->defaults()

src/Autocomplete/tests/Integration/Doctrine/EntityMetadataTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testIsAssociation(): void
4343
public function testGetIdValue(): void
4444
{
4545
$product = ProductFactory::createOne();
46-
$this->assertEquals($product->getId(), $this->getMetadata()->getIdValue($product->object()));
46+
$this->assertEquals($product->getId(), $this->getMetadata()->getIdValue($product));
4747
}
4848

4949
public function testGetPropertyDataType(): void

src/Autocomplete/tests/Integration/Doctrine/EntitySearchUtilTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testItCreatesBasicStringSearchQuery(): void
3434
$prod4 = ProductFactory::createOne(['description' => 'all about prod 4']);
3535

3636
$results = $this->callAddSearchClass('prod');
37-
$this->assertSame([$prod1->object(), $prod2->object(), $prod4->object()], $results);
37+
$this->assertSame([$prod1, $prod2, $prod4], $results);
3838
}
3939

4040
public function testItSearchesOnCorrectFields(): void
@@ -43,7 +43,7 @@ public function testItSearchesOnCorrectFields(): void
4343
ProductFactory::createOne(['description' => 'foo prod2']);
4444

4545
$results = $this->callAddSearchClass('prod', ['name']);
46-
$this->assertSame([$prod1->object()], $results);
46+
$this->assertSame([$prod1], $results);
4747
}
4848

4949
public function testItCanSearchOnRelationFields(): void
@@ -55,7 +55,7 @@ public function testItCanSearchOnRelationFields(): void
5555
ProductFactory::createOne(['name' => 'puzzle', 'category' => $category2]);
5656

5757
$results = $this->callAddSearchClass('food', ['name', 'category.name']);
58-
$this->assertSame([$prod1->object(), $prod2->object()], $results);
58+
$this->assertSame([$prod1, $prod2], $results);
5959
}
6060

6161
/**

src/LiveComponent/tests/Fixtures/Kernel.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ protected function configureContainer(ContainerConfigurator $c): void
143143
'anonymous_template_directory' => 'components/',
144144
]);
145145

146-
$c->extension('zenstruck_foundry', [
147-
'auto_refresh_proxies' => false,
148-
]);
146+
$c->extension('zenstruck_foundry', []);
149147

150148
$doctrineConfig = [
151149
'dbal' => [

0 commit comments

Comments
 (0)