-
-
Notifications
You must be signed in to change notification settings - Fork 504
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
Fix deprecation notices Indexes annotation #2622
Conversation
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.
I think we are missing tests for deprecation messages. Should we add them in this PR then?
I'll make an attempt to do so before wrapping this up. We have some prior art for doing this in PHPLIB, but Expecting Deprecations (E_USER_DEPRECATED) may have a better approach. |
I made some progress in asserting deprecation messages, but ran into a roadblock attempting to use Indexes as an attribute (annotation is fine). I'll hold off on this until we can talk it through in the Slack thread. |
2451e0a
to
12d8974
Compare
Manually rebased on 2.7.x, since that's the same branch I used for previous fixes (#2627). |
12d8974
to
1ce766b
Compare
The argument order has been incorrect since the deprecation message was changed in 3bdfe97.
This was missed when Indexes was originally deprecated in 7435e66.
The attribute is intentionally untested. The Indexes attribute cannot target a property (it omits Attribute::TARGET_PROPERTY). When Indexes targets a class, Index attributes cannot be nested within its definition. Testing the "indexes" option for class-level Document attributes is technically possible but not worth the effort.
1ce766b
to
c42ac54
Compare
Deprecation messages for annotations are now tested. CI failures are unrelated to this PR and due to #2624. |
} | ||
|
||
/** @param list<string>|null $errors */ | ||
private function captureDeprecationMessages(callable $callable, ?array &$errors): mixed |
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.
I think we can also use https://symfony.com/doc/current/components/phpunit_bridge.html but seems like a drastic change so let's keep it this way for now.
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.
Aye. We use that on the MongoDB driver but I noted it wasn't being utilized here.
Summary
The
Indexes
attribute/annotation was deprecated in doctrine/mongodb-odm@7435e66 for 2.2. There were deprecation messages added for usingIndexes
at the class level, andindexes
within the Document annotation; however, it looks like Indexes on the property level was missed.Also, one of the deprecation messages got screwed up in doctrine/mongodb-odm@3bdfe97. The message changed but the sprintf args weren't swapped to account for that.
I struggled to add tests for this because:
trigger_deprecation
calls@trigger_error()
, so output is silenced. I could theoretically useerror_get_last()
to check for the deprecation message, but there's no prior art for doing so. In fact, no deprecation messages seem to be tested.Indexes
attribute cannot target a property, so the property-level deprecation message could only trigger when using it as annotation.Indexes
as a class-level attribute withIndex
nested within. I consulted Support for nesting attributes with PHP 8.1 orm#9241 some some examples of nesting attributes, but all of my attempts resulted in exceptions (e.g.$value
property ofIndexes
couldn't be set).For manual testing of the annotation form, this is what I used: