Skip to content

Commit 2f6e092

Browse files
committed
Update test on dropping encrypted collection
1 parent d38238e commit 2f6e092

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"doctrine/persistence": "^3.2 || ^4",
3131
"friendsofphp/proxy-manager-lts": "^1.0",
3232
"jean85/pretty-package-versions": "^1.3.0 || ^2.0.1",
33-
"mongodb/mongodb": "^1.21 || ^2.0@dev",
33+
"mongodb/mongodb": "~1.21.2 || ^2.1.1@dev",
3434
"psr/cache": "^1.0 || ^2.0 || ^3.0",
3535
"symfony/console": "^5.4 || ^6.0 || ^7.0",
3636
"symfony/deprecation-contracts": "^2.2 || ^3.0",

tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryableEncryptionTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
use Documents\Encryption\PatientBilling;
1111
use Documents\Encryption\PatientRecord;
1212
use MongoDB\BSON\Binary;
13+
use MongoDB\BSON\Regex;
1314
use MongoDB\Client;
1415
use MongoDB\Model\BSONDocument;
1516

16-
use function count;
1717
use function getenv;
1818
use function iterator_to_array;
1919
use function random_bytes;
@@ -27,6 +27,13 @@ public function setUp(): void
2727
$this->skipTestIfQueryableEncryptionNotSupported();
2828
}
2929

30+
public function tearDown(): void
31+
{
32+
$this->dm?->getDocumentCollection(Patient::class)?->drop(['encryptedFields' => []]);
33+
34+
parent::tearDown();
35+
}
36+
3037
public function testCreateAndQueryEncryptedCollection(): void
3138
{
3239
$nonEncryptedClient = new Client(self::getUri());
@@ -64,8 +71,11 @@ public function testCreateAndQueryEncryptedCollection(): void
6471
self::assertSame('Jon Doe', $document->patientName);
6572
self::assertSame(12345678, $document->patientId);
6673
self::assertInstanceOf(Binary::class, $document->patientRecord->ssn);
74+
self::assertSame(Binary::TYPE_ENCRYPTED, $document->patientRecord->ssn->getType());
6775
self::assertInstanceOf(Binary::class, $document->patientRecord->billing);
76+
self::assertSame(Binary::TYPE_ENCRYPTED, $document->patientRecord->billing->getType());
6877
self::assertInstanceOf(Binary::class, $document->patientRecord->billingAmount);
78+
self::assertSame(Binary::TYPE_ENCRYPTED, $document->patientRecord->billingAmount->getType());
6979

7080
// Queryable with equality
7181
$result = $this->dm->getRepository(Patient::class)->findOneBy(['patientRecord.ssn' => '987-65-4320']);
@@ -84,11 +94,9 @@ public function testCreateAndQueryEncryptedCollection(): void
8494
self::assertSame('4111111111111111', $result->patientRecord->billing->number);
8595

8696
// Drop the encrypted collection
87-
$collectionCount = count($nonEncryptedDatabase->listCollectionNames());
8897
$this->dm->getSchemaManager()->dropDocumentCollection(Patient::class);
89-
$collectionNames = iterator_to_array($nonEncryptedDatabase->listCollectionNames());
90-
self::assertNotContains('patients', $collectionNames);
91-
self::assertSame($collectionCount - 3, count($collectionNames), 'The 2 metadata collections should also be dropped');
98+
$collectionNames = iterator_to_array($nonEncryptedDatabase->listCollectionNames(['filter' => ['name' => new Regex('patients')]]));
99+
self::assertSame([], $collectionNames, 'The 2 metadata collections should also be dropped');
92100
}
93101

94102
protected static function createTestDocumentManager(): DocumentManager

0 commit comments

Comments
 (0)