Skip to content
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

MNT Tweak some test to account for slightly different sorting logic in PostgreSQL #10693

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions tests/php/ORM/DataListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1958,33 +1958,28 @@ public function provideSortDirectionValidationTwoArgs(): array
/**
* Test passing scalar values to sort()
*
* Explicity tests that sort(null) will wipe any existing sort on a DataList
*
* @dataProvider provideSortScalarValues
*/
public function testSortScalarValues(mixed $emtpyValue, string $type): void
{
$this->assertSame(['Subteam 1'], Team::get()->limit(1)->column('Title'));
$list = Team::get()->sort('Title DESC');
$this->assertSame(['Team 3'], $list->limit(1)->column('Title'));
if ($type !== 'wipes-existing') {
$this->expectException(InvalidArgumentException::class);
}
$this->expectException(InvalidArgumentException::class);
if ($type === 'invalid-scalar') {
$this->expectExceptionMessage('sort() arguments must either be a string, an array, or null');
}
if ($type === 'empty-scalar') {
$this->expectExceptionMessage('Invalid sort parameter');
}
// $type === 'wipes-existing' is valid

$list = $list->sort($emtpyValue);
$this->assertSame(['Subteam 1'], $list->limit(1)->column('Title'));
}

public function provideSortScalarValues(): array
{
return [
[null, 'wipes-existing'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This scenario was testing that calling sort with null unsets the order by clause. I've replaced it with a sightly different test below.

['', 'empty-scalar'],
[[], 'empty-scalar'],
[false, 'invalid-scalar'],
Expand All @@ -1994,6 +1989,27 @@ public function provideSortScalarValues(): array
];
}

/**
* Explicity tests that sort(null) will wipe any existing sort on a DataList
*/
public function testSortNull(): void
{
$list = Team::get()->sort('Title DESC');
$query = $list->dataQuery()->getFinalisedQuery();
$this->assertSame(
['"DataObjectTest_Team"."Title"' => 'DESC'],
$query->getOrderBy(),
'Calling sort on a DataList sets an Orderby on the underlying query.'
);

$list = $list->sort(null);
$query = $list->dataQuery()->getFinalisedQuery();
$this->assertEmpty(
$query->getOrderBy(),
'Calling sort with null on a DataList unsets the orderby on the underlying query.'
);
}

public function testShuffle()
{
$list = Team::get()->shuffle();
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Security/MemberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1831,7 +1831,7 @@ public function testMapInCMSGroups(array $groupFixtures, array $groupCodes, arra
$result = Member::mapInCMSGroups($groups);
$this->assertInstanceOf(Map::class, $result);

$this->assertSame($expectedUsers, $result->keys());
$this->assertEqualsCanonicalizing($expectedUsers, $result->keys());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In PostgreSQL, the result was returning the keys in a slightly different order.

The order of the results is irrelevant here. `assertEqualsCanonicalizing' sorts the arrays before comparing them.

}

public function provideMapInCMSGroups()
Expand Down