From 25a0f0793883be22d9bb8520eec93ef72091c6d9 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 20 Sep 2021 09:11:58 +0200 Subject: [PATCH] remove deprecated code --- .../Form/ChoiceList/DoctrineChoiceLoader.php | 20 +++---------- .../ChoiceList/DoctrineChoiceLoaderTest.php | 28 ++++++------------- 2 files changed, 13 insertions(+), 35 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php index 9779de3cbfeb2..e191bea3ca16d 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php @@ -13,6 +13,7 @@ use Doctrine\Persistence\ObjectManager; use Symfony\Component\Form\ChoiceList\Loader\AbstractChoiceLoader; +use Symfony\Component\Form\Exception\LogicException; /** * Loads choices using a Doctrine object manager. @@ -68,16 +69,7 @@ protected function doLoadValuesForChoices(array $choices): array // know that the IDs are used as values // Attention: This optimization does not check choices for existence if ($this->idReader) { - trigger_deprecation('symfony/doctrine-bridge', '5.1', 'Not defining explicitly the IdReader as value callback when query can be optimized is deprecated. Don\'t pass the IdReader to "%s" or define the "choice_value" option instead.', __CLASS__); - // Maintain order and indices of the given objects - $values = []; - foreach ($choices as $i => $object) { - if ($object instanceof $this->class) { - $values[$i] = $this->idReader->getIdValue($object); - } - } - - return $values; + throw new LogicException('Not defining the IdReader explicitly as a value callback when the query can be optimized is not supported.'); } return parent::doLoadValuesForChoices($choices); @@ -85,10 +77,8 @@ protected function doLoadValuesForChoices(array $choices): array protected function doLoadChoicesForValues(array $values, ?callable $value): array { - $legacy = $this->idReader && null === $value; - - if ($legacy) { - trigger_deprecation('symfony/doctrine-bridge', '5.1', 'Not defining explicitly the IdReader as value callback when query can be optimized is deprecated. Don\'t pass the IdReader to "%s" or define the "choice_value" option instead.', __CLASS__); + if ($this->idReader && null === $value) { + throw new LogicException('Not defining the IdReader explicitly as a value callback when the query can be optimized is not supported.'); } $idReader = null; @@ -96,8 +86,6 @@ protected function doLoadChoicesForValues(array $values, ?callable $value): arra $idReader = $value[0]; } elseif ($value instanceof \Closure && ($rThis = (new \ReflectionFunction($value))->getClosureThis()) instanceof IdReader) { $idReader = $rThis; - } elseif ($legacy) { - $idReader = $this->idReader; } // Optimize performance in case we have an object loader and diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php index 90cf50684d5d9..98b3c96d9b3a7 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php @@ -22,6 +22,7 @@ use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Form\ChoiceList\ArrayChoiceList; use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface; +use Symfony\Component\Form\Exception\LogicException; /** * @author Bernhard Schussek @@ -191,12 +192,11 @@ public function testLoadValuesForChoicesDoesNotLoadIfEmptyChoices() $this->assertSame([], $loader->loadValuesForChoices([])); } - /** - * @group legacy - */ public function testLoadValuesForChoicesDoesNotLoadIfSingleIntId() { - $this->expectDeprecation('Since symfony/doctrine-bridge 5.1: Not defining explicitly the IdReader as value callback when query can be optimized is deprecated. Don\'t pass the IdReader to "Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader" or define the "choice_value" option instead.'); + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Not defining the IdReader explicitly as a value callback when the query can be optimized is not supported.'); + $loader = new DoctrineChoiceLoader( $this->om, $this->class, @@ -293,12 +293,11 @@ public function testLoadChoicesForValuesDoesNotLoadIfEmptyValues() $this->assertSame([], $loader->loadChoicesForValues([])); } - /** - * @group legacy - */ public function testLegacyLoadChoicesForValuesLoadsOnlyChoicesIfValueUseIdReader() { - $this->expectDeprecation('Since symfony/doctrine-bridge 5.1: Not defining explicitly the IdReader as value callback when query can be optimized is deprecated. Don\'t pass the IdReader to "Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader" or define the "choice_value" option instead.'); + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Not defining the IdReader explicitly as a value callback when the query can be optimized is not supported.'); + $loader = new DoctrineChoiceLoader( $this->om, $this->class, @@ -315,17 +314,8 @@ public function testLegacyLoadChoicesForValuesLoadsOnlyChoicesIfValueUseIdReader $this->repository->expects($this->never()) ->method('findAll'); - $this->objectLoader->expects($this->once()) - ->method('getEntitiesByIds') - ->with('idField', [4 => '3', 7 => '2']) - ->willReturn($choices); - - $this->idReader->expects($this->any()) - ->method('getIdValue') - ->willReturnMap([ - [$this->obj2, '2'], - [$this->obj3, '3'], - ]); + $this->objectLoader->expects($this->never()) + ->method('getEntitiesByIds'); $this->assertSame( [4 => $this->obj3, 7 => $this->obj2],