Skip to content

Commit

Permalink
Add missing ids in exception message (#1515)
Browse files Browse the repository at this point in the history
* Add missing ids in exception message

* Adapt tests
  • Loading branch information
deguif authored and XWB committed May 6, 2019
1 parent 3f2707d commit b08530d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/Doctrine/AbstractElasticaToModelTransformer.php
Expand Up @@ -95,12 +95,16 @@ public function transform(array $elasticaObjects)
$objects = $this->findByIdentifiers($ids, $this->options['hydrate']);
$objectsCnt = count($objects);
$elasticaObjectsCnt = count($elasticaObjects);
$propertyAccessor = $this->propertyAccessor;
$identifier = $this->options['identifier'];
if (!$this->options['ignore_missing'] && $objectsCnt < $elasticaObjectsCnt) {
throw new \RuntimeException(sprintf('Cannot find corresponding Doctrine objects (%d) for all Elastica results (%d). IDs: %s', $objectsCnt, $elasticaObjectsCnt, implode(', ', $ids)));
$missingIds = array_diff($ids, array_map(function ($object) use ($propertyAccessor, $identifier) {
return $propertyAccessor->getValue($object, $identifier);
}, $objects));

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

$propertyAccessor = $this->propertyAccessor;
$identifier = $this->options['identifier'];
foreach ($objects as $object) {
if ($object instanceof HighlightableModelInterface) {
$id = $propertyAccessor->getValue($object, $identifier);
Expand Down
Expand Up @@ -125,7 +125,7 @@ public function testAnExceptionIsThrownWhenTheNumberOfFoundObjectsIsLessThanTheN
->will($this->returnValue([]));

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

$transformer->transform($elasticaResults);
}
Expand Down

0 comments on commit b08530d

Please sign in to comment.