Skip to content

Commit 85ee8d5

Browse files
committed
remove deprecated code
1 parent 31b533c commit 85ee8d5

File tree

2 files changed

+13
-35
lines changed

2 files changed

+13
-35
lines changed

Form/ChoiceList/DoctrineChoiceLoader.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\Persistence\ObjectManager;
1515
use Symfony\Component\Form\ChoiceList\Loader\AbstractChoiceLoader;
16+
use Symfony\Component\Form\Exception\LogicException;
1617

1718
/**
1819
* Loads choices using a Doctrine object manager.
@@ -68,36 +69,23 @@ protected function doLoadValuesForChoices(array $choices): array
6869
// know that the IDs are used as values
6970
// Attention: This optimization does not check choices for existence
7071
if ($this->idReader) {
71-
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__);
72-
// Maintain order and indices of the given objects
73-
$values = [];
74-
foreach ($choices as $i => $object) {
75-
if ($object instanceof $this->class) {
76-
$values[$i] = $this->idReader->getIdValue($object);
77-
}
78-
}
79-
80-
return $values;
72+
throw new LogicException('Not defining the IdReader explicitly as a value callback when the query can be optimized is not supported.');
8173
}
8274

8375
return parent::doLoadValuesForChoices($choices);
8476
}
8577

8678
protected function doLoadChoicesForValues(array $values, ?callable $value): array
8779
{
88-
$legacy = $this->idReader && null === $value;
89-
90-
if ($legacy) {
91-
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__);
80+
if ($this->idReader && null === $value) {
81+
throw new LogicException('Not defining the IdReader explicitly as a value callback when the query can be optimized is not supported.');
9282
}
9383

9484
$idReader = null;
9585
if (\is_array($value) && $value[0] instanceof IdReader) {
9686
$idReader = $value[0];
9787
} elseif ($value instanceof \Closure && ($rThis = (new \ReflectionFunction($value))->getClosureThis()) instanceof IdReader) {
9888
$idReader = $rThis;
99-
} elseif ($legacy) {
100-
$idReader = $this->idReader;
10189
}
10290

10391
// Optimize performance in case we have an object loader and

Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
2323
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
2424
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;
25+
use Symfony\Component\Form\Exception\LogicException;
2526

2627
/**
2728
* @author Bernhard Schussek <[email protected]>
@@ -191,12 +192,11 @@ public function testLoadValuesForChoicesDoesNotLoadIfEmptyChoices()
191192
$this->assertSame([], $loader->loadValuesForChoices([]));
192193
}
193194

194-
/**
195-
* @group legacy
196-
*/
197195
public function testLoadValuesForChoicesDoesNotLoadIfSingleIntId()
198196
{
199-
$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.');
197+
$this->expectException(LogicException::class);
198+
$this->expectExceptionMessage('Not defining the IdReader explicitly as a value callback when the query can be optimized is not supported.');
199+
200200
$loader = new DoctrineChoiceLoader(
201201
$this->om,
202202
$this->class,
@@ -293,12 +293,11 @@ public function testLoadChoicesForValuesDoesNotLoadIfEmptyValues()
293293
$this->assertSame([], $loader->loadChoicesForValues([]));
294294
}
295295

296-
/**
297-
* @group legacy
298-
*/
299296
public function testLegacyLoadChoicesForValuesLoadsOnlyChoicesIfValueUseIdReader()
300297
{
301-
$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.');
298+
$this->expectException(LogicException::class);
299+
$this->expectExceptionMessage('Not defining the IdReader explicitly as a value callback when the query can be optimized is not supported.');
300+
302301
$loader = new DoctrineChoiceLoader(
303302
$this->om,
304303
$this->class,
@@ -315,17 +314,8 @@ public function testLegacyLoadChoicesForValuesLoadsOnlyChoicesIfValueUseIdReader
315314
$this->repository->expects($this->never())
316315
->method('findAll');
317316

318-
$this->objectLoader->expects($this->once())
319-
->method('getEntitiesByIds')
320-
->with('idField', [4 => '3', 7 => '2'])
321-
->willReturn($choices);
322-
323-
$this->idReader->expects($this->any())
324-
->method('getIdValue')
325-
->willReturnMap([
326-
[$this->obj2, '2'],
327-
[$this->obj3, '3'],
328-
]);
317+
$this->objectLoader->expects($this->never())
318+
->method('getEntitiesByIds');
329319

330320
$this->assertSame(
331321
[4 => $this->obj3, 7 => $this->obj2],

0 commit comments

Comments
 (0)