Skip to content

Conversation

cezarystepkowski
Copy link
Contributor

Array matcher is throwing an exception when array has a key with brackets.

See example below:

Value:

{
  "foo[key]": "value"
}

Pattern:

{
  "foo[key]": "@string@"
}

The reason for that is because Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException is thrown in Symfony\Component\PropertyAccess\PropertyPath constructor because such key does not match regex for valid property.

This PR attempts to fix it.

I looked into the usage of PropertyPath and PropertyAccessor in ArrayMatcher and it seems that it was needed only to perform simple operation (basically stripping [ and ] from beginning and end of a path string). I simplified the operation by adding a method getKeyFromAccessPath instead of relying on PropertyAccessor.

All tests passed so I assume that it will not break anything else :)

Additionally, it turned out that symfony/property-access is not used anywhere else in the project so I removed it from Composer dependencies.

@norberttech norberttech changed the base branch from master to 5.x July 6, 2020 19:57
@norberttech
Copy link
Member

@cezarystepkowski sorry for a long time it took me to review your work. I merged this PR into #204, which also remove few other hard dependencies making phpmatcher free nice and small.
Thank you for your contribution 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants