Skip to content

Commit b08530d

Browse files
deguifXWB
authored andcommitted
Add missing ids in exception message (#1515)
* Add missing ids in exception message * Adapt tests
1 parent 3f2707d commit b08530d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/Doctrine/AbstractElasticaToModelTransformer.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,16 @@ public function transform(array $elasticaObjects)
9595
$objects = $this->findByIdentifiers($ids, $this->options['hydrate']);
9696
$objectsCnt = count($objects);
9797
$elasticaObjectsCnt = count($elasticaObjects);
98+
$propertyAccessor = $this->propertyAccessor;
99+
$identifier = $this->options['identifier'];
98100
if (!$this->options['ignore_missing'] && $objectsCnt < $elasticaObjectsCnt) {
99-
throw new \RuntimeException(sprintf('Cannot find corresponding Doctrine objects (%d) for all Elastica results (%d). IDs: %s', $objectsCnt, $elasticaObjectsCnt, implode(', ', $ids)));
101+
$missingIds = array_diff($ids, array_map(function ($object) use ($propertyAccessor, $identifier) {
102+
return $propertyAccessor->getValue($object, $identifier);
103+
}, $objects));
104+
105+
throw new \RuntimeException(sprintf('Cannot find corresponding Doctrine objects (%d) for all Elastica results (%d). Missing IDs: %s. IDs: %s', $objectsCnt, $elasticaObjectsCnt, implode(', ', $missingIds), implode(', ', $ids)));
100106
}
101107

102-
$propertyAccessor = $this->propertyAccessor;
103-
$identifier = $this->options['identifier'];
104108
foreach ($objects as $object) {
105109
if ($object instanceof HighlightableModelInterface) {
106110
$id = $propertyAccessor->getValue($object, $identifier);

tests/Unit/Doctrine/AbstractElasticaToModelTransformerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function testAnExceptionIsThrownWhenTheNumberOfFoundObjectsIsLessThanTheN
125125
->will($this->returnValue([]));
126126

127127
$this->expectExceptionMessage(\RuntimeException::class);
128-
$this->expectExceptionMessage('Cannot find corresponding Doctrine objects (0) for all Elastica results (3). IDs: 1, 2, 3');
128+
$this->expectExceptionMessage('Cannot find corresponding Doctrine objects (0) for all Elastica results (3). Missing IDs: 1, 2, 3. IDs: 1, 2, 3');
129129

130130
$transformer->transform($elasticaResults);
131131
}

0 commit comments

Comments
 (0)