From b8a86cb58dce91fea8c74e0d7816427c10d17197 Mon Sep 17 00:00:00 2001 From: Hugo Alliaume Date: Fri, 19 Sep 2025 07:54:11 +0200 Subject: [PATCH] [Autocomplete][LiveComponent] Fix deprecations with zenstruck/foundry:^2.7 --- .../Factory/CategoryFixtureEntityFactory.php | 6 ++-- .../Factory/CompositeIdEntityFactory.php | 6 ++-- .../Factory/ForeignKeyIdEntityFactory.php | 6 ++-- .../Factory/ProductFixtureEntityFactory.php | 33 +++++++++++++++++++ .../DoctrineEntityHydrationExtensionTest.php | 4 +-- .../Integration/LiveComponentHydratorTest.php | 9 ++--- 6 files changed, 49 insertions(+), 15 deletions(-) create mode 100644 src/LiveComponent/tests/Fixtures/Factory/ProductFixtureEntityFactory.php diff --git a/src/LiveComponent/tests/Fixtures/Factory/CategoryFixtureEntityFactory.php b/src/LiveComponent/tests/Fixtures/Factory/CategoryFixtureEntityFactory.php index e9e53e9abdf..65e4e468b72 100644 --- a/src/LiveComponent/tests/Fixtures/Factory/CategoryFixtureEntityFactory.php +++ b/src/LiveComponent/tests/Fixtures/Factory/CategoryFixtureEntityFactory.php @@ -12,12 +12,12 @@ namespace Symfony\UX\LiveComponent\Tests\Fixtures\Factory; use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\CategoryFixtureEntity; -use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory; +use Zenstruck\Foundry\Persistence\PersistentObjectFactory; /** - * @extends PersistentProxyObjectFactory + * @extends PersistentObjectFactory */ -final class CategoryFixtureEntityFactory extends PersistentProxyObjectFactory +final class CategoryFixtureEntityFactory extends PersistentObjectFactory { protected function defaults(): array|callable { diff --git a/src/LiveComponent/tests/Fixtures/Factory/CompositeIdEntityFactory.php b/src/LiveComponent/tests/Fixtures/Factory/CompositeIdEntityFactory.php index dcb3cdc532e..70e77eb2b1a 100644 --- a/src/LiveComponent/tests/Fixtures/Factory/CompositeIdEntityFactory.php +++ b/src/LiveComponent/tests/Fixtures/Factory/CompositeIdEntityFactory.php @@ -12,12 +12,12 @@ namespace Symfony\UX\LiveComponent\Tests\Fixtures\Factory; use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\CompositeIdEntity; -use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory; +use Zenstruck\Foundry\Persistence\PersistentObjectFactory; /** - * @extends PersistentProxyObjectFactory + * @extends PersistentObjectFactory */ -class CompositeIdEntityFactory extends PersistentProxyObjectFactory +class CompositeIdEntityFactory extends PersistentObjectFactory { public static function class(): string { diff --git a/src/LiveComponent/tests/Fixtures/Factory/ForeignKeyIdEntityFactory.php b/src/LiveComponent/tests/Fixtures/Factory/ForeignKeyIdEntityFactory.php index 241eec7eb81..6d094716a21 100644 --- a/src/LiveComponent/tests/Fixtures/Factory/ForeignKeyIdEntityFactory.php +++ b/src/LiveComponent/tests/Fixtures/Factory/ForeignKeyIdEntityFactory.php @@ -13,14 +13,14 @@ use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\Entity1; use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\ForeignKeyIdEntity; -use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory; +use Zenstruck\Foundry\Persistence\PersistentObjectFactory; use function Zenstruck\Foundry\lazy; /** - * @extends PersistentProxyObjectFactory + * @extends PersistentObjectFactory */ -class ForeignKeyIdEntityFactory extends PersistentProxyObjectFactory +class ForeignKeyIdEntityFactory extends PersistentObjectFactory { public static function class(): string { diff --git a/src/LiveComponent/tests/Fixtures/Factory/ProductFixtureEntityFactory.php b/src/LiveComponent/tests/Fixtures/Factory/ProductFixtureEntityFactory.php new file mode 100644 index 00000000000..603d03b94f3 --- /dev/null +++ b/src/LiveComponent/tests/Fixtures/Factory/ProductFixtureEntityFactory.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\UX\LiveComponent\Tests\Fixtures\Factory; + +use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\ProductFixtureEntity; +use Zenstruck\Foundry\Persistence\PersistentObjectFactory; + +/** + * @extends PersistentObjectFactory + */ +final class ProductFixtureEntityFactory extends PersistentObjectFactory +{ + protected function defaults(): array|callable + { + return [ + 'name' => self::faker()->name(), + ]; + } + + public static function class(): string + { + return ProductFixtureEntity::class; + } +} diff --git a/src/LiveComponent/tests/Integration/Hydration/DoctrineEntityHydrationExtensionTest.php b/src/LiveComponent/tests/Integration/Hydration/DoctrineEntityHydrationExtensionTest.php index 47b9ccd8920..93115a798ec 100644 --- a/src/LiveComponent/tests/Integration/Hydration/DoctrineEntityHydrationExtensionTest.php +++ b/src/LiveComponent/tests/Integration/Hydration/DoctrineEntityHydrationExtensionTest.php @@ -27,7 +27,7 @@ class DoctrineEntityHydrationExtensionTest extends KernelTestCase public function testCompositeId() { - $compositeIdEntity = CompositeIdEntityFactory::createOne()->_real(); + $compositeIdEntity = CompositeIdEntityFactory::createOne(); /** @var DoctrineEntityHydrationExtension $extension */ $extension = self::getContainer()->get('ux.live_component.doctrine_entity_hydration_extension'); @@ -40,7 +40,7 @@ public function testCompositeId() public function testForeignKeyId() { - $foreignKeyIdEntity = ForeignKeyIdEntityFactory::createOne()->_real(); + $foreignKeyIdEntity = ForeignKeyIdEntityFactory::createOne(); /** @var DoctrineEntityHydrationExtension $extension */ $extension = self::getContainer()->get('ux.live_component.doctrine_entity_hydration_extension'); diff --git a/src/LiveComponent/tests/Integration/LiveComponentHydratorTest.php b/src/LiveComponent/tests/Integration/LiveComponentHydratorTest.php index 99c155b407a..f34715299c3 100644 --- a/src/LiveComponent/tests/Integration/LiveComponentHydratorTest.php +++ b/src/LiveComponent/tests/Integration/LiveComponentHydratorTest.php @@ -44,6 +44,7 @@ use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\IntEnum; use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\StringEnum; use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\ZeroIntEnum; +use Symfony\UX\LiveComponent\Tests\Fixtures\Factory\ProductFixtureEntityFactory; use Symfony\UX\LiveComponent\Tests\LiveComponentTestHelper; use Symfony\UX\TwigComponent\ComponentAttributes; use Symfony\UX\TwigComponent\ComponentMetadata; @@ -53,8 +54,8 @@ use Zenstruck\Foundry\Test\ResetDatabase; use function Zenstruck\Foundry\object; +use function Zenstruck\Foundry\Persistence\delete; use function Zenstruck\Foundry\Persistence\persist; -use function Zenstruck\Foundry\Persistence\proxy; /** * @author Kevin Bond @@ -434,16 +435,16 @@ public function onEntireEntityUpdated($oldValue) }]; yield 'Persisted entity: deleting entity between dehydration and hydration sets it to null' => [function () { - $product = proxy(persist(ProductFixtureEntity::class)); + $product = ProductFixtureEntityFactory::createOne(); return HydrationTest::create(new class { // test that event the writable path doesn't cause problems #[LiveProp(writable: ['name'])] public ?ProductFixtureEntity $product; }) - ->mountWith(['product' => $product->_real()]) + ->mountWith(['product' => $product]) ->beforeHydration(function () use ($product) { - $product->_delete(); + delete($product); }) ->assertObjectAfterHydration(function (object $object) { self::assertNull(