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

Fix tests on Schema index helpers #3236

Merged
merged 2 commits into from
Jan 3, 2025
Merged

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Jan 2, 2025

Find index by its actual name instead of the key fields.
Fix wrong assertions checking indexes doesn't exist with the wrong name.

@GromNaN GromNaN requested a review from a team as a code owner January 2, 2025 19:04
@GromNaN GromNaN requested a review from jmikola January 2, 2025 19:04
@GromNaN GromNaN marked this pull request as draft January 2, 2025 19:04
@GromNaN GromNaN force-pushed the schema-index-tests branch 2 times, most recently from 388e5fe to 31e6efe Compare January 2, 2025 19:13
@GromNaN GromNaN force-pushed the schema-index-tests branch from 31e6efe to 58b94c1 Compare January 2, 2025 19:17
@GromNaN GromNaN marked this pull request as ready for review January 2, 2025 19:17
Schema::table('newcollection', function ($collection) {
$collection->index(['field_a' => -1, 'field_b' => 1]);
});

$index = $this->getIndex('newcollection', 'field_a_-1_field_b_1');
$index = $this->getIndex('newcollection', $indexName);
$this->assertNotNull($index);
Copy link
Member Author

Choose a reason for hiding this comment

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

Here the assertion was always true, $index was false for missing index.

Copy link
Member

Choose a reason for hiding this comment

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

Having assertIndexExists() and assertIndexNotExists() would make the tests more readable if you wanted to go that route. I realize you can't get rid of getIndex() entirely, since some later tests expect to make assertions on the IndexInfo structure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the suggestion, that's more explicit with the new assert methods.

tests/SchemaTest.php Show resolved Hide resolved
@GromNaN GromNaN merged commit aae9170 into mongodb:5.x Jan 3, 2025
27 checks passed
@GromNaN GromNaN deleted the schema-index-tests branch January 3, 2025 17:07
@GromNaN GromNaN added the minor label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants