Skip to content

feat: add toBeAscending, toBeDescending, and toBeSorted expectations#1739

Open
sonalidudhia wants to merge 2 commits into
pestphp:5.xfrom
sonalidudhia:draft-pr-request
Open

feat: add toBeAscending, toBeDescending, and toBeSorted expectations#1739
sonalidudhia wants to merge 2 commits into
pestphp:5.xfrom
sonalidudhia:draft-pr-request

Conversation

@sonalidudhia

@sonalidudhia sonalidudhia commented Jun 26, 2026

Copy link
Copy Markdown

Adds three new array sorting expectations.

Useful for testing query results, pagination, leaderboards, and sorted collections.

expect([1, 2, 3])->toBeAscending();
expect([3, 2, 1])->toBeDescending();
expect([1, 2, 2, 3])->toBeAscending(); // equal adjacent OK

expect($users)->toBeSorted(by: 'age');
expect($users)->toBeSorted(by: 'age', direction: 'desc');
expect($posts)->toBeSorted(by: 'created_at'); // works with DateTime

// Object properties
$users = [
    (object)['name' => 'Anna'],
    (object)['name' => 'Ben'],
];
expect($users)->toBeSorted(by: 'name');

// Negation
expect([3, 1, 2])->not->toBeAscending();

sonalidudhia and others added 2 commits June 26, 2026 18:05
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonalidudhia sonalidudhia marked this pull request as ready for review June 26, 2026 12:54
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.

1 participant