From 40ccd76594a0e688114273778a3577a004c804b2 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 15 Jun 2024 00:34:59 +0200 Subject: [PATCH 1/4] test handling of special "value" constraint option --- Tests/Validator/Constraints/UniqueEntityTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Tests/Validator/Constraints/UniqueEntityTest.php b/Tests/Validator/Constraints/UniqueEntityTest.php index 2c9c3815..5d9edce2 100644 --- a/Tests/Validator/Constraints/UniqueEntityTest.php +++ b/Tests/Validator/Constraints/UniqueEntityTest.php @@ -63,6 +63,13 @@ public function testAttributeWithGroupsAndPaylod() self::assertSame('some attached data', $constraint->payload); self::assertSame(['some_group'], $constraint->groups); } + + public function testValueOptionConfiguresFields() + { + $constraint = new UniqueEntity(['value' => 'email']); + + $this->assertSame('email', $constraint->fields); + } } #[UniqueEntity(['email'], message: 'myMessage')] From 6f26ed3f6927f7c4dc6946bbf0324f17c8c3ba75 Mon Sep 17 00:00:00 2001 From: MatTheCat Date: Fri, 21 Jun 2024 15:04:29 +0200 Subject: [PATCH 2/4] [DoctrineBridge] Test reset with a true manager --- Tests/Fixtures/DummyManager.php | 69 +++++++++++++++++++++++++++++++++ Tests/ManagerRegistryTest.php | 25 +++++++----- 2 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 Tests/Fixtures/DummyManager.php diff --git a/Tests/Fixtures/DummyManager.php b/Tests/Fixtures/DummyManager.php new file mode 100644 index 00000000..04e5a2ac --- /dev/null +++ b/Tests/Fixtures/DummyManager.php @@ -0,0 +1,69 @@ +testDumpContainerWithProxyServiceWillShareProxies(); + $container = new ContainerBuilder(); + + $container->register('foo', DummyManager::class)->setPublic(true); + $container->getDefinition('foo')->setLazy(true); + $container->compile(); + + $dumper = new PhpDumper($container); + $dumper->setProxyDumper(new ProxyDumper()); + eval('?>'.$dumper->dump(['class' => 'LazyServiceDoctrineBridgeContainer'])); } public function testResetService() { - $container = new \LazyServiceProjectServiceContainer(); + $container = new \LazyServiceDoctrineBridgeContainer(); $registry = new TestManagerRegistry('name', [], ['defaultManager' => 'foo'], 'defaultConnection', 'defaultManager', 'proxyInterfaceName'); $registry->setTestContainer($container); @@ -44,8 +51,8 @@ public function testResetService() $registry->resetManager(); $this->assertSame($foo, $container->get('foo')); - $this->assertInstanceOf(\stdClass::class, $foo); - $this->assertFalse(property_exists($foo, 'bar')); + $this->assertInstanceOf(DummyManager::class, $foo); + $this->assertFalse(isset($foo->bar)); } /** @@ -77,7 +84,7 @@ public function testResetServiceWillNotNestFurtherLazyServicesWithinEachOther() $service = $container->get('foo'); - self::assertInstanceOf(\stdClass::class, $service); + self::assertInstanceOf(DummyManager::class, $service); self::assertInstanceOf(LazyLoadingInterface::class, $service); self::assertInstanceOf(ValueHolderInterface::class, $service); self::assertFalse($service->isProxyInitialized()); @@ -91,7 +98,7 @@ public function testResetServiceWillNotNestFurtherLazyServicesWithinEachOther() $service->initializeProxy(); $wrappedValue = $service->getWrappedValueHolderValue(); - self::assertInstanceOf(\stdClass::class, $wrappedValue); + self::assertInstanceOf(DummyManager::class, $wrappedValue); self::assertNotInstanceOf(LazyLoadingInterface::class, $wrappedValue); self::assertNotInstanceOf(ValueHolderInterface::class, $wrappedValue); } @@ -104,7 +111,7 @@ private function dumpLazyServiceProjectAsFilesServiceContainer() $container = new ContainerBuilder(); - $container->register('foo', \stdClass::class) + $container->register('foo', DummyManager::class) ->setPublic(true) ->setLazy(true); $container->compile(); From 7f174fe622067ac77f83e265a83f07bde424eaba Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 22 Jun 2024 07:12:06 +0200 Subject: [PATCH 3/4] change test to use a real ObjectManager --- Tests/LegacyManagerRegistryTest.php | 26 +++++++++++++++++--------- Tests/ManagerRegistryTest.php | 4 ---- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Tests/LegacyManagerRegistryTest.php b/Tests/LegacyManagerRegistryTest.php index d3426651..87965db3 100644 --- a/Tests/LegacyManagerRegistryTest.php +++ b/Tests/LegacyManagerRegistryTest.php @@ -11,11 +11,12 @@ namespace Symfony\Bridge\Doctrine\Tests; +use Doctrine\Persistence\ObjectManager; use PHPUnit\Framework\TestCase; use ProxyManager\Proxy\LazyLoadingInterface; use ProxyManager\Proxy\ValueHolderInterface; +use Symfony\Bridge\Doctrine\Tests\Fixtures\DummyManager; use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper; -use Symfony\Bridge\ProxyManager\Tests\LazyProxy\Dumper\PhpDumperTest; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; @@ -28,9 +29,16 @@ class LegacyManagerRegistryTest extends TestCase { public static function setUpBeforeClass(): void { - if (!class_exists(\LazyServiceProjectServiceContainer::class, false)) { - eval('?>'.PhpDumperTest::dumpLazyServiceProjectServiceContainer()); - } + $container = new ContainerBuilder(); + + $container->register('foo', DummyManager::class)->setPublic(true); + $container->getDefinition('foo')->setLazy(true)->addTag('proxy', ['interface' => ObjectManager::class]); + $container->compile(); + + $dumper = new PhpDumper($container); + $dumper->setProxyDumper(new ProxyDumper()); + + eval('?>'.$dumper->dump(['class' => 'LazyServiceProjectServiceContainer'])); } public function testResetService() @@ -47,8 +55,8 @@ public function testResetService() $registry->resetManager(); $this->assertSame($foo, $container->get('foo')); - $this->assertInstanceOf(\stdClass::class, $foo); - $this->assertFalse(property_exists($foo, 'bar')); + $this->assertInstanceOf(ObjectManager::class, $foo); + $this->assertFalse(isset($foo->bar)); } /** @@ -80,7 +88,7 @@ public function testResetServiceWillNotNestFurtherLazyServicesWithinEachOther() $service = $container->get('foo'); - self::assertInstanceOf(\stdClass::class, $service); + self::assertInstanceOf(DummyManager::class, $service); self::assertInstanceOf(LazyLoadingInterface::class, $service); self::assertInstanceOf(ValueHolderInterface::class, $service); self::assertFalse($service->isProxyInitialized()); @@ -94,7 +102,7 @@ public function testResetServiceWillNotNestFurtherLazyServicesWithinEachOther() $service->initializeProxy(); $wrappedValue = $service->getWrappedValueHolderValue(); - self::assertInstanceOf(\stdClass::class, $wrappedValue); + self::assertInstanceOf(DummyManager::class, $wrappedValue); self::assertNotInstanceOf(LazyLoadingInterface::class, $wrappedValue); self::assertNotInstanceOf(ValueHolderInterface::class, $wrappedValue); } @@ -107,7 +115,7 @@ private function dumpLazyServiceProjectAsFilesServiceContainer() $container = new ContainerBuilder(); - $container->register('foo', \stdClass::class) + $container->register('foo', DummyManager::class) ->setPublic(true) ->setLazy(true); $container->compile(); diff --git a/Tests/ManagerRegistryTest.php b/Tests/ManagerRegistryTest.php index a8d1f738..fa44ba0a 100644 --- a/Tests/ManagerRegistryTest.php +++ b/Tests/ManagerRegistryTest.php @@ -13,11 +13,7 @@ use Doctrine\Persistence\ObjectManager; use PHPUnit\Framework\TestCase; -use ProxyManager\Proxy\LazyLoadingInterface; -use ProxyManager\Proxy\ValueHolderInterface; -use Symfony\Bridge\Doctrine\ManagerRegistry; use Symfony\Bridge\Doctrine\Tests\Fixtures\DummyManager; -use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; From 934e8260debaf6557ec759988428d9eb291b1f1d Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 22 Jun 2024 10:10:52 +0200 Subject: [PATCH 4/4] fix test --- Tests/LegacyManagerRegistryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/LegacyManagerRegistryTest.php b/Tests/LegacyManagerRegistryTest.php index 87965db3..65944b40 100644 --- a/Tests/LegacyManagerRegistryTest.php +++ b/Tests/LegacyManagerRegistryTest.php @@ -56,7 +56,7 @@ public function testResetService() $this->assertSame($foo, $container->get('foo')); $this->assertInstanceOf(ObjectManager::class, $foo); - $this->assertFalse(isset($foo->bar)); + $this->assertFalse(property_exists($foo, 'bar')); } /**