Skip to content

Commit

Permalink
add more information to exception-message
Browse files Browse the repository at this point in the history
  • Loading branch information
floriansemm committed Dec 28, 2016
1 parent 6fdd30a commit b35e293
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions Doctrine/Mapper/Factory/DocumentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function createDocument(MetaInformationInterface $metaInformation)

$value = $field->getValue();
if ($value instanceof Collection) {
$document->addField($field->getNameWithAlias(), $this->mapCollection($field), $field->getBoost());
$document->addField($field->getNameWithAlias(), $this->mapCollection($field, $metaInformation->getClassName()), $field->getBoost());
} elseif (is_object($value)) {
$document->addField($field->getNameWithAlias(), $this->mapObject($field), $field->getBoost());
} else {
Expand Down Expand Up @@ -90,7 +90,7 @@ private function mapObject(Field $field)
$getterReturnValue = $this->callGetterMethod($value, $getter);

if (is_object($getterReturnValue)) {
throw new SolrMappingException('The configured getter must return a string or array, got object');
throw new SolrMappingException(sprintf('The configured getter "%s" in "%s" must return a string or array, got object', $getter, get_class($value)));
}

return $getterReturnValue;
Expand Down Expand Up @@ -141,19 +141,20 @@ private function callGetterMethod($object, $getter)
}

/**
* @param Field $field
* @param Field $field
* @param string $sourceTargetClass
*
* @return array
*
* @throws SolrMappingException if no getter method was found
*/
private function mapCollection(Field $field)
private function mapCollection(Field $field, $sourceTargetClass)
{
/** @var Collection $value */
$value = $field->getValue();
$getter = $field->getGetterName();
if ($getter == '') {
throw new SolrMappingException(sprintf('No getter method for property "%s" found', $field->name));
throw new SolrMappingException(sprintf('No getter method for property "%s" configured in class "%s"', $field->name, $sourceTargetClass));
}

$values = array();
Expand Down
4 changes: 2 additions & 2 deletions Tests/Doctrine/Mapper/EntityMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public function mapRelationFieldAllFields()
/**
* @test
* @expectedException \FS\SolrBundle\Doctrine\Mapper\SolrMappingException
* @expectedExceptionMessage No getter method for property "collection" found
* @expectedExceptionMessage No getter method for property "collection" configured in class "FS\SolrBundle\Tests\Fixtures\ValidTestEntityWithCollection"
*/
public function throwExceptionIfEmbbededObjectsHasNoGetter()
{
Expand Down Expand Up @@ -414,7 +414,7 @@ public function callGetterWithParameters()
/**
* @test
* @expectedException \FS\SolrBundle\Doctrine\Mapper\SolrMappingException
* @expectedExceptionMessage The configured getter must return a string or array, got object
* @expectedExceptionMessage The configured getter "asString" in "FS\SolrBundle\Tests\Doctrine\Mapper\TestObject" must return a string or array, got object
*/
public function callGetterWithObjectAsReturnValue()
{
Expand Down

0 comments on commit b35e293

Please sign in to comment.