Skip to content

Commit 01273b9

Browse files
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: #30966 and #30962 Commits ------- 4616e54 Removed legacy code related to DoctrineChoiceLoader
2 parents fbf5c34 + 4616e54 commit 01273b9

File tree

3 files changed

+10
-87
lines changed

3 files changed

+10
-87
lines changed

src/Symfony/Bridge/Doctrine/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
5.0.0
5+
-----
6+
7+
* passing an `IdReader` to the `DoctrineChoiceLoader` when the query cannot be optimized with single id field, throws an exception; pass `null` instead
8+
* not explicitly passing an instance of `IdReader` to `DoctrineChoiceLoader` when it can optimize single id field, will not apply any optimization
9+
410
4.4.0
511
-----
612

src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php

+1-14
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,7 @@ public function __construct(ObjectManager $manager, string $class, IdReader $idR
5050
$classMetadata = $manager->getClassMetadata($class);
5151

5252
if ($idReader && !$idReader->isSingleId()) {
53-
@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);
54-
55-
// In Symfony 5.0
56-
// 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__));
57-
}
58-
59-
if ((5 > \func_num_args() || false !== func_get_arg(4)) && null === $idReader) {
60-
$idReader = new IdReader($manager, $classMetadata);
61-
62-
if ($idReader->isSingleId()) {
63-
@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);
64-
} else {
65-
$idReader = null;
66-
}
53+
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__));
6754
}
6855

6956
$this->manager = $manager;

src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php

+3-73
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader;
1919
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
2020
use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader;
21-
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
2221
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
2322
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;
2423

@@ -377,70 +376,8 @@ public function testLoadChoicesForValuesLoadsOnlyChoicesIfValueIsIdReader()
377376
}
378377

379378
/**
380-
* @group legacy
381-
*
382-
* @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.
383-
*/
384-
public function testLoaderWithoutIdReaderCanBeOptimized()
385-
{
386-
$obj1 = new SingleIntIdEntity('1', 'one');
387-
$obj2 = new SingleIntIdEntity('2', 'two');
388-
389-
$metadata = $this->createMock(ClassMetadata::class);
390-
$metadata->expects($this->once())
391-
->method('getIdentifierFieldNames')
392-
->willReturn(['idField'])
393-
;
394-
$metadata->expects($this->any())
395-
->method('getIdentifierValues')
396-
->willReturnCallback(function ($obj) use ($obj1, $obj2) {
397-
if ($obj === $obj1) {
398-
return ['idField' => '1'];
399-
}
400-
if ($obj === $obj2) {
401-
return ['idField' => '2'];
402-
}
403-
404-
return null;
405-
})
406-
;
407-
408-
$this->om = $this->createMock(ObjectManager::class);
409-
$this->om->expects($this->once())
410-
->method('getClassMetadata')
411-
->with(SingleIntIdEntity::class)
412-
->willReturn($metadata)
413-
;
414-
$this->om->expects($this->any())
415-
->method('contains')
416-
->with($this->isInstanceOf(SingleIntIdEntity::class))
417-
->willReturn(true)
418-
;
419-
420-
$loader = new DoctrineChoiceLoader(
421-
$this->om,
422-
SingleIntIdEntity::class,
423-
null,
424-
$this->objectLoader
425-
);
426-
427-
$choices = [$obj1, $obj2];
428-
429-
$this->repository->expects($this->never())
430-
->method('findAll');
431-
432-
$this->objectLoader->expects($this->once())
433-
->method('getEntitiesByIds')
434-
->with('idField', ['1'])
435-
->willReturn($choices);
436-
437-
$this->assertSame([$obj1], $loader->loadChoicesForValues(['1']));
438-
}
439-
440-
/**
441-
* @group legacy
442-
*
443-
* @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.
379+
* @expectedException \InvalidArgumentException
380+
* @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.
444381
*/
445382
public function testPassingIdReaderWithoutSingleIdEntity()
446383
{
@@ -450,13 +387,6 @@ public function testPassingIdReaderWithoutSingleIdEntity()
450387
->willReturn(false)
451388
;
452389

453-
$loader = new DoctrineChoiceLoader(
454-
$this->om,
455-
$this->class,
456-
$idReader,
457-
$this->objectLoader
458-
);
459-
460-
$this->assertInstanceOf(DoctrineChoiceLoader::class, $loader);
390+
new DoctrineChoiceLoader($this->om, $this->class, $idReader, $this->objectLoader);
461391
}
462392
}

0 commit comments

Comments
 (0)