From 4616e54c559b0274c2be1c7c212e5204bc4b079f Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Wed, 5 Jun 2019 17:42:54 -0400 Subject: [PATCH] Removed legacy code related to DoctrineChoiceLoader --- src/Symfony/Bridge/Doctrine/CHANGELOG.md | 6 ++ .../Form/ChoiceList/DoctrineChoiceLoader.php | 15 +--- .../ChoiceList/DoctrineChoiceLoaderTest.php | 76 +------------------ 3 files changed, 10 insertions(+), 87 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/CHANGELOG.md b/src/Symfony/Bridge/Doctrine/CHANGELOG.md index 7123b527eb..983a7d939c 100644 --- a/src/Symfony/Bridge/Doctrine/CHANGELOG.md +++ b/src/Symfony/Bridge/Doctrine/CHANGELOG.md @@ -1,6 +1,12 @@ CHANGELOG ========= +5.0.0 +----- + + * passing an `IdReader` to the `DoctrineChoiceLoader` when the query cannot be optimized with single id field, throws an exception; pass `null` instead + * not explicitly passing an instance of `IdReader` to `DoctrineChoiceLoader` when it can optimize single id field, will not apply any optimization + 4.4.0 ----- diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php index cd040d12a9..38e97ceba0 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php @@ -50,20 +50,7 @@ class DoctrineChoiceLoader implements ChoiceLoaderInterface $classMetadata = $manager->getClassMetadata($class); if ($idReader && !$idReader->isSingleId()) { - @trigger_error(sprintf('Passing an instance of "%s" to "%s" with an entity class "%s" that has a composite id is deprecated since Symfony 4.3 and will throw an exception in 5.0.', IdReader::class, __CLASS__, $class), E_USER_DEPRECATED); - - // In Symfony 5.0 - // throw new \InvalidArgumentException(sprintf('The second argument `$idReader` of "%s" must be null when the query cannot be optimized because of composite id fields.', __METHOD__)); - } - - if ((5 > \func_num_args() || false !== func_get_arg(4)) && null === $idReader) { - $idReader = new IdReader($manager, $classMetadata); - - if ($idReader->isSingleId()) { - @trigger_error(sprintf('Not explicitly passing an instance of "%s" to "%s" when it can optimize single id entity "%s" has been deprecated in 4.3 and will not apply any optimization in 5.0.', IdReader::class, __CLASS__, $class), E_USER_DEPRECATED); - } else { - $idReader = null; - } + throw new \InvalidArgumentException(sprintf('The second argument `$idReader` of "%s" must be null when the query cannot be optimized because of composite id fields.', __METHOD__)); } $this->manager = $manager; diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php index 5a5fba5afa..3aeff05a83 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php @@ -18,7 +18,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader; use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface; use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader; -use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity; use Symfony\Component\Form\ChoiceList\ArrayChoiceList; use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface; @@ -377,70 +376,8 @@ class DoctrineChoiceLoaderTest extends TestCase } /** - * @group legacy - * - * @expectedDeprecation Not explicitly passing an instance of "Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader" to "Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader" when it can optimize single id entity "%s" has been deprecated in 4.3 and will not apply any optimization in 5.0. - */ - public function testLoaderWithoutIdReaderCanBeOptimized() - { - $obj1 = new SingleIntIdEntity('1', 'one'); - $obj2 = new SingleIntIdEntity('2', 'two'); - - $metadata = $this->createMock(ClassMetadata::class); - $metadata->expects($this->once()) - ->method('getIdentifierFieldNames') - ->willReturn(['idField']) - ; - $metadata->expects($this->any()) - ->method('getIdentifierValues') - ->willReturnCallback(function ($obj) use ($obj1, $obj2) { - if ($obj === $obj1) { - return ['idField' => '1']; - } - if ($obj === $obj2) { - return ['idField' => '2']; - } - - return null; - }) - ; - - $this->om = $this->createMock(ObjectManager::class); - $this->om->expects($this->once()) - ->method('getClassMetadata') - ->with(SingleIntIdEntity::class) - ->willReturn($metadata) - ; - $this->om->expects($this->any()) - ->method('contains') - ->with($this->isInstanceOf(SingleIntIdEntity::class)) - ->willReturn(true) - ; - - $loader = new DoctrineChoiceLoader( - $this->om, - SingleIntIdEntity::class, - null, - $this->objectLoader - ); - - $choices = [$obj1, $obj2]; - - $this->repository->expects($this->never()) - ->method('findAll'); - - $this->objectLoader->expects($this->once()) - ->method('getEntitiesByIds') - ->with('idField', ['1']) - ->willReturn($choices); - - $this->assertSame([$obj1], $loader->loadChoicesForValues(['1'])); - } - - /** - * @group legacy - * - * @deprecationMessage Passing an instance of "Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader" to "Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader" with an entity class "stdClass" that has a composite id is deprecated since Symfony 4.3 and will throw an exception in 5.0. + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The second argument `$idReader` of "Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader::__construct" must be null when the query cannot be optimized because of composite id fields. */ public function testPassingIdReaderWithoutSingleIdEntity() { @@ -450,13 +387,6 @@ class DoctrineChoiceLoaderTest extends TestCase ->willReturn(false) ; - $loader = new DoctrineChoiceLoader( - $this->om, - $this->class, - $idReader, - $this->objectLoader - ); - - $this->assertInstanceOf(DoctrineChoiceLoader::class, $loader); + new DoctrineChoiceLoader($this->om, $this->class, $idReader, $this->objectLoader); } }