-
Notifications
You must be signed in to change notification settings - Fork 3
Errors from Symfony's PropertyAccessor now result in Purgatory's PropertyNotAccessibleException #110
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
Open
klezaic
wants to merge
9
commits into
sofascore:2.x
Choose a base branch
from
klezaic:throw-custom-property-access-exception
base: 2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Errors from Symfony's PropertyAccessor now result in Purgatory's PropertyNotAccessibleException #110
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
91ab85c
Errors from symfony property accessor now result in PropertyNotAccess…
klezaic 3ba9030
Static code analysis fix
klezaic e427672
Lint
klezaic 3dfd226
Static code analysis fix
klezaic a9a5ba3
Improve test coverage
klezaic f931880
Improve test coverage
klezaic ca27025
Improve test coverage
klezaic 7af442d
Added previous throwable to exception
klezaic 76eca5b
Previous should be optional
klezaic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| use PHPUnit\Framework\Attributes\CoversClass; | ||
| use PHPUnit\Framework\Attributes\DataProvider; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Sofascore\PurgatoryBundle\Exception\PropertyNotAccessibleException; | ||
| use Sofascore\PurgatoryBundle\Exception\ValueNotIterableException; | ||
| use Sofascore\PurgatoryBundle\RouteProvider\PropertyAccess\PurgatoryPropertyAccessor; | ||
| use Sofascore\PurgatoryBundle\Tests\RouteProvider\PropertyAccess\Fixtures\Foo; | ||
|
|
@@ -130,6 +131,60 @@ public static function traversableProvider(): iterable | |
| ]; | ||
| } | ||
|
|
||
| public function testReadPathPropertyNotExist(): void | ||
| { | ||
| self::assertFalse($this->purgatoryPropertyAccessor->isReadable( | ||
| objectOrArray: new Foo( | ||
| id: 1, | ||
| children: new ArrayCollection([]), | ||
| ), | ||
| propertyPath: 'nonExistentProperty', | ||
| )); | ||
| } | ||
|
|
||
| public function testReadPathPropertyNotAccessible(): void | ||
| { | ||
| self::assertFalse($this->purgatoryPropertyAccessor->isReadable( | ||
| objectOrArray: new Foo( | ||
| id: 1, | ||
| children: new ArrayCollection([]), | ||
| ), | ||
| propertyPath: 'privateProperty', | ||
| )); | ||
| } | ||
|
|
||
| public function testReadTraversableChildPropertyNotExist(): void | ||
| { | ||
| self::assertFalse($this->purgatoryPropertyAccessor->isReadable( | ||
| objectOrArray: new Foo( | ||
| id: 1, | ||
| children: new ArrayCollection([ | ||
| new Foo( | ||
| id: 1, | ||
| children: new ArrayCollection([]), | ||
| ), | ||
| ]), | ||
| ), | ||
| propertyPath: 'children[*].nonExistentProperty', | ||
| )); | ||
| } | ||
|
|
||
| public function testReadTraversableChildPropertyNotAccessible(): void | ||
| { | ||
| self::assertFalse($this->purgatoryPropertyAccessor->isReadable( | ||
| objectOrArray: new Foo( | ||
| id: 1, | ||
| children: new ArrayCollection([ | ||
| new Foo( | ||
| id: 1, | ||
| children: new ArrayCollection([]), | ||
| ), | ||
| ]), | ||
| ), | ||
| propertyPath: 'children[*].privateProperty', | ||
| )); | ||
| } | ||
|
|
||
| public function testNotTraversable(): void | ||
| { | ||
| $this->expectException(ValueNotIterableException::class); | ||
|
|
@@ -143,4 +198,138 @@ public function testNotTraversable(): void | |
| propertyPath: 'id[*].id', | ||
| ); | ||
| } | ||
|
|
||
| public function testPropertyNotAccessible(): void | ||
| { | ||
| $this->expectException(PropertyNotAccessibleException::class); | ||
| $this->expectExceptionMessage( | ||
| \sprintf( | ||
| 'Unable to create a getter for property "%s::%s".', | ||
|
||
| Foo::class, | ||
| 'privateProperty', | ||
| ), | ||
| ); | ||
|
|
||
| $this->purgatoryPropertyAccessor->getValue( | ||
| objectOrArray: new Foo( | ||
| id: 1, | ||
| children: new ArrayCollection([]), | ||
| ), | ||
| propertyPath: 'privateProperty', | ||
| ); | ||
| } | ||
|
|
||
| public function testTraversablePropertyNotAccessible(): void | ||
| { | ||
| $this->expectException(PropertyNotAccessibleException::class); | ||
| $this->expectExceptionMessage( | ||
| \sprintf( | ||
| 'Unable to create a getter for property "%s::%s".', | ||
| Foo::class, | ||
| 'privateProperty', | ||
| ), | ||
| ); | ||
|
|
||
| $this->purgatoryPropertyAccessor->getValue( | ||
| objectOrArray: new Foo( | ||
| id: 1, | ||
| children: new ArrayCollection([]), | ||
| ), | ||
| propertyPath: 'privateProperty[*].values', | ||
| ); | ||
| } | ||
|
|
||
| public function testTraversableChildPropertyNotAccessible(): void | ||
| { | ||
| $this->expectException(PropertyNotAccessibleException::class); | ||
| $this->expectExceptionMessage( | ||
| \sprintf( | ||
| 'Unable to create a getter for property "%s::%s".', | ||
| Foo::class, | ||
| 'privateProperty', | ||
| ), | ||
| ); | ||
|
|
||
| $this->purgatoryPropertyAccessor->getValue( | ||
| objectOrArray: new Foo( | ||
| id: 1, | ||
| children: new ArrayCollection( | ||
| [ | ||
| new Foo( | ||
| id: 1, | ||
| children: new ArrayCollection([]), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| propertyPath: 'children[*].privateProperty', | ||
| ); | ||
| } | ||
|
|
||
| public function testPropertyNotExist(): void | ||
| { | ||
| $this->expectException(PropertyNotAccessibleException::class); | ||
| $this->expectExceptionMessage( | ||
| \sprintf( | ||
| 'Unable to create a getter for property "%s::%s".', | ||
| Foo::class, | ||
| 'nonExistentProperty', | ||
| ), | ||
| ); | ||
|
|
||
| $this->purgatoryPropertyAccessor->getValue( | ||
| objectOrArray: new Foo( | ||
| id: 1, | ||
| children: new ArrayCollection([]), | ||
| ), | ||
| propertyPath: 'nonExistentProperty', | ||
| ); | ||
| } | ||
|
|
||
| public function testTraversablePropertyNotExist(): void | ||
| { | ||
| $this->expectException(PropertyNotAccessibleException::class); | ||
| $this->expectExceptionMessage( | ||
| \sprintf( | ||
| 'Unable to create a getter for property "%s::%s".', | ||
| Foo::class, | ||
| 'nonExistentProperty', | ||
| ), | ||
| ); | ||
|
|
||
| $this->purgatoryPropertyAccessor->getValue( | ||
| objectOrArray: new Foo( | ||
| id: 1, | ||
| children: new ArrayCollection([]), | ||
| ), | ||
| propertyPath: 'nonExistentProperty[*].values', | ||
| ); | ||
| } | ||
|
|
||
| public function testTraversableChildPropertyNotExist(): void | ||
| { | ||
| $this->expectException(PropertyNotAccessibleException::class); | ||
| $this->expectExceptionMessage( | ||
| \sprintf( | ||
| 'Unable to create a getter for property "%s::%s".', | ||
| Foo::class, | ||
| 'nonExistentProperty', | ||
| ), | ||
| ); | ||
|
|
||
| $this->purgatoryPropertyAccessor->getValue( | ||
| objectOrArray: new Foo( | ||
| id: 1, | ||
| children: new ArrayCollection( | ||
| [ | ||
| new Foo( | ||
| id: 1, | ||
| children: new ArrayCollection([]), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| propertyPath: 'children[*].nonExistentProperty', | ||
| ); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should probably add
previousthrowable toPropertyNotAccessibleExceptionso we don't lose error context from property accessorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 7af442d