Repository navigation
Allow SortDirection enum in ObjectRepository::findBy() #524
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
Closed
Closed
Changes from all commits
Commits
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
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 |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Doctrine\Tests\Persistence; | ||
|
|
||
| use Doctrine\Persistence\ObjectRepository; | ||
| use PHPUnit\Framework\TestCase; | ||
| use SortDirection; | ||
|
|
||
| final class ObjectRepositorySortDirectionTest extends TestCase | ||
| { | ||
| public function testFindByAcceptsSortDirectionEnumValue(): void | ||
| { | ||
| $repository = self::createMock(ObjectRepository::class); | ||
|
|
||
| $repository | ||
| ->expects(self::once()) | ||
| ->method('findBy') | ||
| ->with([], ['created_at' => SortDirection::Descending]) | ||
| ->willReturn([]); | ||
|
|
||
| $repository->findBy([], ['created_at' => SortDirection::Descending]); | ||
| } | ||
| } |
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.
Widening parameter type is a BC break for implementers (as implementers are not allowed to use a more restrictive type based on the Liskov Substitution Principle). So to me, this change must happen only in the 5.0.x branch.
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.
You're absolutely right. And even if it doesn't break the PHP code because the type isn't enforced by PHP, we're providing information about a supported type that isn't respected by all older versions of ORM/ODM. Adding a composer conflict rule with older ORM versions would be really dirty.
The solution, therefore, is to accept
string|SortDirectionin 5.0 and (possibly) remove support forstringin 6.0.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.
Indeed. An interface package that would be forced to add conflicts for older versions of implementation packages would be a clear signal that the interface package does not follow semver (assuming implementation packages don't use unbounded constraints of course but rely on semver constraints)
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.
Can this maybe be achieved with
@method?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.
@greg0ire no. We don't want to add a new method. We want to change the signature of an existing method.
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.
Ok, too bad there isn't an annotation to suggest this.