minor #31887 [DoctrineBridge] Removed legacy code related to DoctrineChoiceLoader (yceruto)

This PR was merged into the 5.0-dev branch.

Discussion
----------

[DoctrineBridge] Removed legacy code related to DoctrineChoiceLoader

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Ref: https://github.com/symfony/symfony/pull/30966 and https://github.com/symfony/symfony/pull/30962

Commits
-------

4616e54c55 Removed legacy code related to DoctrineChoiceLoader
This commit is contained in:
Nicolas Grekas 2019-06-06 09:10:36 +02:00
commit 01273b9d65
3 changed files with 10 additions and 87 deletions

View File

@ -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
-----

View File

@ -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;

View File

@ -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);
}
}