8000 fixup · symfony/symfony@a0b15c6 · GitHub
[go: up one dir, main page]

Skip to content

Commit a0b15c6

Browse files
committed
fixup
1 parent 591fd35 commit a0b15c6

File tree

2 files changed

+8
-45
lines changed

2 files changed

+8
-45
lines changed

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,10 @@ public function configureOptions(OptionsResolver $resolver)
163163
};
164164

165165
$choiceName = function (Options $options) {
166-
/** @var IdReader $idReader */
167-
$idReader = $options['id_reader'];
168-
169166
// If the object has a single-column, numeric ID, use that ID as
170167
// field name. We can only use numeric IDs as names, as we cannot
171168
// guarantee that a non-numeric ID contains a valid form name
172-
if ($idReader->isIntId()) {
169+
if ($options['id_reader'] instanceof IdReader && $options['id_reader']->isIntId()) {
173170
return [__CLASS__, 'createChoiceName'];
174171
}
175172

@@ -181,12 +178,9 @@ public function configureOptions(OptionsResolver $resolver)
181178
// are indexed by an incrementing integer.
182179
// Use the ID/incrementing integer as choice value.
183180
$choiceValue = function (Options $options) {
184-
/** @var IdReader $idReader */
185-
$idReader = $options['id_reader'];
186-
187181
// If the entity has a single-column ID, use that ID as value
188-
if ($idReader->isSingleId()) {
189-
return [$idReader, 'getIdValue'];
182+
if ($options['id_reader'] instanceof IdReader && $options['id_reader']->isSingleId()) {
183+
return [$options['id_reader'], 'getIdValue'];
190184
}
191185

192186
// Otherwise, an incrementing integer is used as value automatically
@@ -240,7 +234,11 @@ public function configureOptions(OptionsResolver $resolver)
240234
$this->idReaders[$hash] = new IdReader($options['em'], $classMetadata);
241235
}
242236

243-
return $this->idReaders[$hash];
237+
if ($this->idReaders[$hash]->isSingleId()) {
238+
return $this->idReaders[$hash];
239+
}
240+
241+
return null;
244242
};
245243

246244
$resolver->setDefaults([

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

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,6 @@ public function testLoadValuesForChoicesLoadsIfSingleIntIdAndValueGiven()
216216
$choices = [$this->obj1, $this->obj2, $this->obj3];
217217
$value = function (\stdClass $object) { return $object->name; };
218218

219-
$this->idReader->expects($this->any())
220-
->method('isSingleId')
221-
->willReturn(true);
222-
223219
$this->repository->expects($this->once())
224220
->method('findAll')
225221
->willReturn($choices);
@@ -240,10 +236,6 @@ public function testLoadValuesForChoicesDoesNotLoadIfValueIsIdReader()
240236

241237
$value = [$this->idReader, 'getIdValue'];
242238

243-
$this->idReader->expects($this->any())
244-
->method('isSingleId')
245-
->willReturn(true);
246-
247239
$this->repository->expects($this->never())
248240
->method('findAll');
249241

@@ -304,10 +296,6 @@ public function testLoadChoicesForValuesLoadsOnlyChoicesIfSingleIntId()
304296

305297
$choices = [$this->obj2, $this->obj3];
306298

307-
$this->idReader->expects($this->any())
308-
->method('isSingleId')
309-
->willReturn(true);
310-
311299
$this->idReader->expects($this->any())
312300
->method('getIdField')
313301
->willReturn('idField');
@@ -344,10 +332,6 @@ public function testLoadChoicesForValuesLoadsAllIfSingleIntIdAndValueGiven()
344332
$choices = [$this->obj1, $this->obj2, $this->obj3];
345333
$value = function (\stdClass $object) { return $object->name; };
346334

347-
$this->idReader->expects($this->any())
348-
->method('isSingleId')
349-
->willReturn(true);
350-
351335
$this->repository->expects($this->once())
352336
->method('findAll')
353337
->willReturn($choices);
@@ -370,10 +354,6 @@ public function testLoadChoicesForValuesLoadsOnlyChoicesIfValueIsIdReader()
370354
$choices = [$this->obj2, $this->obj3];
371355
$value = [$this->idReader, 'getIdValue'];
372356

373-
$this->idReader->expects($this->any())
374-
->method('isSingleId')
375-
->willReturn(true);
376-
377357
$this->idReader->expects($this->any())
378358
->method('getIdField')
379359
->willReturn('idField');
@@ -446,14 +426,6 @@ public function testLoaderWithoutIdReaderCanBeOptimized()
446426

447427
$choices = [$obj1, $obj2];
448428

449-
$this->idReader->expects($this->any())
450-
->method('isSingleId')
451-
->willReturn(true);
452-
453-
$this->idReader->expects($this->any())
454-
->method('getIdField')
455-
->willReturn('idField');
456-
457429
$this->repository->expects($this->never())
458430
->method('findAll');
459431

@@ -462,13 +434,6 @@ public function testLoaderWithoutIdReaderCanBeOptimized()
462434
->with('idField', ['1'])
463435
->willReturn($choices);
464436

465-
$this->idReader->expects($this->any())
466-
->method('getIdValue')
467-
->willReturnMap([
468-
[$obj1, '1'],
469-
[$obj2, '2'],
470-
]);
471-
472437
$this->assertSame([$obj1], $loader->loadChoicesForValues(['1']));
473438
}
474439

0 commit comments

Comments
 (0)
0