minor #24006 [PropertyAccess] Update NoSuchPropertyException message for writeProperty (ScullWM)

This PR was merged into the 3.3 branch.

Discussion
----------

[PropertyAccess] Update NoSuchPropertyException message for writeProperty

| Q             | A
| ------------- | ---
| Branch?       | 3.1
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no
| License       | MIT

Hi,
I've get a NoSuchPropertyException error while creating REST API forms.
Having the property name in the exception is great, but in some case, this property is available in many objects. Having more information about the object that generate this exception is better.

I simply suggest to add a get_class of the current object in the error message.

Before:
`Could not determine access type for property "id".`

After (edit)
`Could not determine access type for property "id" in class "App\Command\UserUpdateCommand".`

Commits
-------

7855748c78 Update NoSuchPropertyException message for writeProperty
This commit is contained in:
Fabien Potencier 2017-08-31 10:41:28 -07:00
commit bd1bf2c28d
2 changed files with 2 additions and 2 deletions

View File

@ -649,7 +649,7 @@ class PropertyAccessor implements PropertyAccessorInterface
} elseif (self::ACCESS_TYPE_MAGIC === $access[self::ACCESS_TYPE]) {
$object->{$access[self::ACCESS_NAME]}($value);
} elseif (self::ACCESS_TYPE_NOT_FOUND === $access[self::ACCESS_TYPE]) {
throw new NoSuchPropertyException(sprintf('Could not determine access type for property "%s".', $property));
throw new NoSuchPropertyException(sprintf('Could not determine access type for property "%s" in class "%s".', $property, get_class($object)));
} else {
throw new NoSuchPropertyException($access[self::ACCESS_NAME]);
}

View File

@ -148,7 +148,7 @@ abstract class PropertyAccessorCollectionTest extends PropertyAccessorArrayAcces
/**
* @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException
* @expectedExceptionMessage Could not determine access type for property "axes".
* @expectedExceptionMessageRegExp /Could not determine access type for property "axes" in class "Mock_PropertyAccessorCollectionTest_CarNoAdderAndRemover_[^"]*"./
*/
public function testSetValueFailsIfNoAdderNorRemoverFound()
{