[PropertyAccess][DX] Enhance exception that say that some methods are missing if they don't
This commit is contained in:
parent
a53aba327e
commit
c46519b40b
@ -714,6 +714,17 @@ class PropertyAccessor implements PropertyAccessorInterface
|
|||||||
// we call the getter and hope the __call do the job
|
// we call the getter and hope the __call do the job
|
||||||
$access[self::ACCESS_TYPE] = self::ACCESS_TYPE_MAGIC;
|
$access[self::ACCESS_TYPE] = self::ACCESS_TYPE_MAGIC;
|
||||||
$access[self::ACCESS_NAME] = $setter;
|
$access[self::ACCESS_NAME] = $setter;
|
||||||
|
} elseif (null !== $methods = $this->findAdderAndRemover($reflClass, $singulars)) {
|
||||||
|
$access[self::ACCESS_TYPE] = self::ACCESS_TYPE_NOT_FOUND;
|
||||||
|
$access[self::ACCESS_NAME] = sprintf(
|
||||||
|
'The property "%s" in class "%s" can be defined with the methods "%s()" but '.
|
||||||
|
'the new value must be an array or an instance of \Traversable, '.
|
||||||
|
'"%s" given.',
|
||||||
|
$property,
|
||||||
|
$reflClass->name,
|
||||||
|
implode('()", "', $methods),
|
||||||
|
is_object($value) ? get_class($value) : gettype($value)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$access[self::ACCESS_TYPE] = self::ACCESS_TYPE_NOT_FOUND;
|
$access[self::ACCESS_TYPE] = self::ACCESS_TYPE_NOT_FOUND;
|
||||||
$access[self::ACCESS_NAME] = sprintf(
|
$access[self::ACCESS_NAME] = sprintf(
|
||||||
|
@ -194,4 +194,15 @@ abstract class PropertyAccessorCollectionTest extends PropertyAccessorArrayAcces
|
|||||||
|
|
||||||
$this->assertFalse($this->propertyAccessor->isWritable($car, 'axes', $axes));
|
$this->assertFalse($this->propertyAccessor->isWritable($car, 'axes', $axes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException
|
||||||
|
* expectedExceptionMessageRegExp /The property "axes" in class "Mock_PropertyAccessorCollectionTest_Car[^"]*" can be defined with the methods "addAxis()", "removeAxis()" but the new value must be an array or an instance of \Traversable, "string" given./
|
||||||
|
*/
|
||||||
|
public function testSetValueFailsIfAdderAndRemoverExistButValueIsNotTraversable()
|
||||||
|
{
|
||||||
|
$car = $this->getMock(__CLASS__.'_Car');
|
||||||
|
|
||||||
|
$this->propertyAccessor->setValue($car, 'axes', 'Not an array or Traversable');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user