Skip to content

Adding the new SortDirection - #50

Merged
W0rma merged 3 commits into
Codeception:mainfrom
ThomasLandauer:patch-3
Nov 2, 2026
Merged

W0rma merged 3 commits into
Codeception:mainfrom
ThomasLandauer:patch-3

Conversation

@ThomasLandauer

Copy link
Copy Markdown
Member

No description provided.

Comment on lines 146 to 149
* $I->grabEntitiesFromRepository('User', [
* 'status' => 'active',
* Criteria::create()->orderBy(['name' => 'asc']),
* Criteria::create()->orderBy(['name' => SortDirection::Ascending]),
* ]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your suggestion would only work with doctrine/collections version 3.1 or higher.

Should this be reflected in the docs?

Suggested change
* $I->grabEntitiesFromRepository('User', [
* 'status' => 'active',
* Criteria::create()->orderBy(['name' => 'asc']),
* Criteria::create()->orderBy(['name' => SortDirection::Ascending]),
* ]);
* // doctrine/collections < 3.0
* $I->grabEntitiesFromRepository('User', [
* 'status' => 'active',
* Criteria::create()->orderBy(['name' => 'asc']),
* ]);
*
* // doctrine/collections 3.0
* $I->grabEntitiesFromRepository('User', [
* 'status' => 'active',
* Criteria::create()->orderBy(['name' => \Doctrine\Common\Collections\Order::Ascending]),
* ]);
*
* // doctrine/collections > 3.0
* $I->grabEntitiesFromRepository('User', [
* 'status' => 'active',
* Criteria::create()->orderBy(['name' => \SortDirection::Ascending]),
* ]);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Order::Ascending was never really promoted, so I'd rather not mention that at all. And \SortDirection::Ascending only works in PHP 8.6 (which isn't released yet), otherwise you'll need Symfony's polyfill.
=> So this is all a little confusing - and from my experience I'd guess that whatever we write now will stay there for the next 10 years... ;-)
But you're right that removing 'asc' completely probably wasn't the best idea. So I added it as "comment" now.
My main goal was to promote PHP's new cool SortDirection enum. I think that people who can't use that yet, will easily figure out that asc is meant for them :-)

Comment thread src/Codeception/Module/Doctrine.php Resolved
Co-authored-by: Dieter Beck <beck.worma@gmail.com>
@W0rma
W0rma merged commit 8d5fb10 into Codeception:main Nov 2, 2026
8 checks passed
@ThomasLandauer
ThomasLandauer deleted the patch-3 branch November 2, 2026 13:28
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.

2 participants