Skip to content

Commit ac78f65

Browse files
committed
Add assertion on non-decrypted data
1 parent b2a492e commit ac78f65

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public function setUp(): void
2626

2727
public function testCreateAndQueryEncryptedCollection(): void
2828
{
29-
$client = new Client(self::getUri());
30-
$database = $client->getDatabase(DOCTRINE_MONGODB_DATABASE);
29+
$nonEncryptedClient = new Client(self::getUri());
30+
$nonEncryptedDatabase = $nonEncryptedClient->getDatabase(DOCTRINE_MONGODB_DATABASE);
3131

3232
// Create the encrypted collection
3333
$this->dm->getSchemaManager()->createDocumentCollection(Patient::class);
3434

3535
// Test created collectionss
36-
$collectionNames = iterator_to_array($database->listCollectionNames());
36+
$collectionNames = iterator_to_array($nonEncryptedDatabase->listCollectionNames());
3737
self::assertContains('patients', $collectionNames);
3838
self::assertContains('datakeys', $collectionNames);
3939

@@ -55,13 +55,24 @@ public function testCreateAndQueryEncryptedCollection(): void
5555
$this->dm->flush();
5656
$this->dm->clear();
5757

58+
// Data is encrypted
59+
$document = $nonEncryptedDatabase->getCollection('patients')->findOne(['patientName' => 'Jon Doe']);
60+
self::assertNotNull($document);
61+
self::assertSame('Jon Doe', $document->patientName);
62+
self::assertSame(12345678, $document->patientId);
63+
self::assertInstanceOf(Binary::class, $document->patientRecord->ssn);
64+
self::assertInstanceOf(Binary::class, $document->patientRecord->billing);
65+
self::assertInstanceOf(Binary::class, $document->patientRecord->billingAmount);
66+
5867
// Queryable with equality
5968
$result = $this->dm->getRepository(Patient::class)->findOneBy(['patientRecord.ssn' => '987-65-4320']);
6069
self::assertNotNull($result);
6170
self::assertSame('Jon Doe', $result->patientName);
6271
self::assertSame('987-65-4320', $result->patientRecord->ssn);
6372
self::assertSame('4111111111111111', $result->patientRecord->billing->number);
6473

74+
$this->dm->clear();
75+
6576
// Queryable with range
6677
$result = $this->dm->getRepository(Patient::class)->findOneBy(['patientRecord.billingAmount' => ['$gt' => 1000, '$lt' => 2000]]);
6778
self::assertNotNull($result);

0 commit comments

Comments
 (0)