Skip to content

[PHPLIB-1608] Implement prose tests for $lookup support #1752

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

Open
wants to merge 2 commits into
base: v2.x
Choose a base branch
from

Conversation

paulinevos
Copy link
Contributor

As laid out in the spec: mongodb/specifications@527e22d

Closes PHPLIB-1608

@paulinevos paulinevos requested a review from a team as a code owner August 14, 2025 14:46
@paulinevos paulinevos requested a review from jmikola August 14, 2025 14:46
@paulinevos paulinevos force-pushed the feature/1608_lookup-csfe-qe branch from 2b3a5a9 to ed00780 Compare August 14, 2025 14:54
@codecov-commenter
Copy link

codecov-commenter commented Aug 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.72%. Comparing base (4aed966) to head (955121d).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##               v2.x    #1752   +/-   ##
=========================================
  Coverage     87.72%   87.72%           
  Complexity     3190     3190           
=========================================
  Files           424      424           
  Lines          6348     6348           
=========================================
  Hits           5569     5569           
  Misses          779      779           
Flag Coverage Δ
6.0-replica_set ?
6.0-server 81.69% <ø> (ø)
6.0-sharded_cluster 85.27% <ø> (ø)
8.0-replica_set 87.64% <ø> (ø)
8.0-server 82.57% <ø> (ø)
8.0-sharded_cluster ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@paulinevos paulinevos force-pushed the feature/1608_lookup-csfe-qe branch from ed00780 to 270b4ad Compare August 14, 2025 15:02
@paulinevos paulinevos force-pushed the feature/1608_lookup-csfe-qe branch from 270b4ad to 955121d Compare August 14, 2025 15:12
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

The tests match the prose tests. Good work.

Comment on lines +70 to +77
$collections = [
self::COLL_CSFLE,
self::COLL_CSFLE2,
self::COLL_QE,
self::COLL_QE2,
self::COLL_NO_SCHEMA,
self::COLL_NO_SCHEMA2,
];
Copy link
Member

Choose a reason for hiding this comment

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

Do you need this array? If you add self::COLL_NO_SCHEMA => [], self::COLL_NO_SCHEMA2 => [] to $optionsMap you can look directly on it. That would be more directly comparable to the spec.


private function refreshCollections(): void
{
$db = $this->encryptedClient->selectDatabase(self::getDatabaseName());
Copy link
Member

Choose a reason for hiding this comment

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

selectDatabase and selectCollection are deprecated.
You can also initialize the unencrypted Database.

Suggested change
$db = $this->encryptedClient->selectDatabase(self::getDatabaseName());
$encryptedDatabase = $this->encryptedClient->getDatabase(self::getDatabaseName());
$unencryptedDatabase = $this->unencryptedClient->getDatabase(self::getDatabaseName());

Comment on lines +103 to +104
$collection = $this->unencryptedClient
->selectDatabase(self::getDatabaseName())
Copy link
Member

Choose a reason for hiding this comment

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

Maybe keep this Database object in a variable before the loop (see comment at the beginning of the test function).

Comment on lines +109 to +112
if ($options) {
$document = $collection->findOne(['_id' => $result->getInsertedId()]);
$this->assertInstanceOf(Binary::class, $document->{$collectionName});
}
Copy link
Member

Choose a reason for hiding this comment

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

Good factorisation of the test pattern 👍🏻

Comment on lines +53 to +58
$this->encryptedClient = self::createTestClient(null, [], [
'autoEncryption' => $autoEncryptionOpts,
/* libmongocrypt caches results from listCollections. Use a new
* client in each test to ensure its encryptedFields is applied. */
'disableClientPersistence' => true,
]);
Copy link
Member

Choose a reason for hiding this comment

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

Recreate encryptedClient with the same AutoEncryptionOpts as the setup. (Recreating prevents schema caching from impacting the test).

I understand that one instance of Client would be needed for setup and that a new instance would need to be created for each test.

Here you use the same instance in setup and test code, even if you create a new in the setup of each test.

Comment on lines +118 to +119
$this->skipIfServerVersion('<', '8.1.0', 'Lookup test case requires server version 8.1.0 or later');
$this->skipIfClientSideEncryptionIsNotSupported();
Copy link
Member

Choose a reason for hiding this comment

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

I see that only the test 9 has a distinct constraint; that's why you did not put this check in the setUp.

Comment on lines +121 to +122
$cursor = $this->encryptedClient->selectDatabase(self::getDatabaseName())
->getCollection($collection)
Copy link
Member

Choose a reason for hiding this comment

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

You can get the collection directly from the client.

Suggested change
$cursor = $this->encryptedClient->selectDatabase(self::getDatabaseName())
->getCollection($collection)
$cursor = $this->encryptedClient->getCollection(self::getDatabaseName(), $collection);

$this->skipIfServerVersion('<', '8.1.0', 'Lookup test case requires server version 8.1.0 or later');
$this->skipIfClientSideEncryptionIsNotSupported();

$this->expectExceptionMessageMatches('#not supported#');
Copy link
Member

Choose a reason for hiding this comment

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

I think expectExceptionMessage already matches substrings. expectExceptionMessageMatches is only if you have a regex.

Suggested change
$this->expectExceptionMessageMatches('#not supported#');
$this->expectExceptionMessage('not supported');

Comment on lines +349 to +350
$this->encryptedClient->selectDatabase(self::getDatabaseName())
->getCollection(self::COLL_CSFLE)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$this->encryptedClient->selectDatabase(self::getDatabaseName())
->getCollection(self::COLL_CSFLE)
$this->encryptedClient->getCollection(self::getDatabaseName(), self::COLL_CSFLE)

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.

3 participants