Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing ids in exception message #1515

Merged
merged 2 commits into from May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)));
Copy link
Contributor Author

@deguif deguif May 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should find a better wording for the exception message, but I'm not the best for this kind of things.

}

$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