Skip to content

Commit f70072c

Browse files
committed
Use promoted properties for encrypted document tests
1 parent 38ff112 commit f70072c

File tree

5 files changed

+42
-39
lines changed

5 files changed

+42
-39
lines changed

tests/Doctrine/ODM/MongoDB/Tests/EncryptionTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class EncryptionTest extends BaseTestCase
1111
{
12-
public function testMetadataIsEncrypted(): void
12+
public function testEncryptionFieldMap(): void
1313
{
1414
$factory = new EncryptionFieldMap($this->dm->getMetadataFactory());
1515
$encryptedFieldsMap = $factory->getEncryptionFieldMap(Patient::class);

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

+13-14
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,18 @@ public function testCreateAndQueryEncryptedCollection(): void
3434
self::assertContains('datakeys', $collectionNames);
3535

3636
// Insert a document
37-
$patient = new Patient();
38-
$patient->patientName = 'Jon Doe';
39-
$patient->patientId = 12345678;
40-
41-
$patientRecord = new PatientRecord();
42-
$patientRecord->ssn = '987-65-4320';
43-
$patientRecord->billingAmount = 1200;
44-
45-
$billing = new PatientBilling();
46-
$billing->type = 'Visa';
47-
$billing->number = '4111111111111111';
48-
49-
$patientRecord->billing = $billing;
50-
$patient->patientRecord = $patientRecord;
37+
$patient = new Patient(
38+
patientName: 'Jon Doe',
39+
patientId: 12345678,
40+
patientRecord: new PatientRecord(
41+
ssn: '987-65-4320',
42+
billing: new PatientBilling(
43+
type: 'Visa',
44+
number: '4111111111111111',
45+
),
46+
billingAmount: 1200,
47+
),
48+
);
5149

5250
$this->dm->persist($patient);
5351
$this->dm->flush();
@@ -58,6 +56,7 @@ public function testCreateAndQueryEncryptedCollection(): void
5856
self::assertNotNull($result);
5957
self::assertSame('Jon Doe', $result->patientName);
6058
self::assertSame('987-65-4320', $result->patientRecord->ssn);
59+
self::assertSame('4111111111111111', $result->patientRecord->billing->number);
6160

6261
// Queryable with range
6362
$result = $this->dm->getRepository(Patient::class)->findOneBy(['patientRecord.billingAmount' => ['$gt' => 1000, '$lt' => 2000]]);

tests/Documents/Encryption/Patient.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ class Patient
1212
#[ODM\Id]
1313
public ?string $id;
1414

15-
#[ODM\Field]
16-
public string $patientName;
17-
18-
#[ODM\Field]
19-
public int $patientId;
20-
21-
#[ODM\EmbedOne(targetDocument: PatientRecord::class)]
22-
public PatientRecord $patientRecord;
15+
public function __construct(
16+
#[ODM\Field]
17+
public string $patientName,
18+
#[ODM\Field]
19+
public int $patientId,
20+
#[ODM\EmbedOne(targetDocument: PatientRecord::class)]
21+
public PatientRecord $patientRecord,
22+
) {
23+
}
2324
}

tests/Documents/Encryption/PatientBilling.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
#[EmbeddedDocument]
1111
class PatientBilling
1212
{
13-
#[ODM\Field]
14-
public string $type;
15-
16-
#[ODM\Field]
17-
public string $number;
13+
public function __construct(
14+
#[ODM\Field]
15+
public string $type,
16+
#[ODM\Field]
17+
public string $number,
18+
) {
19+
}
1820
}

tests/Documents/Encryption/PatientRecord.php

+12-11
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ class PatientRecord
1313
#[ODM\Id]
1414
public ?string $id;
1515

16-
#[ODM\Field]
17-
#[ODM\Encrypt(queryType: ODM\Encrypt::QUERY_TYPE_EQUALITY)]
18-
public string $ssn;
19-
20-
#[ODM\EmbedOne(targetDocument: PatientBilling::class)]
21-
#[ODM\Encrypt]
22-
public PatientBilling $billing;
23-
24-
#[ODM\Field]
25-
#[ODM\Encrypt(queryType: ODM\Encrypt::QUERY_TYPE_RANGE, sparsity: 1, trimFactor: 4, min: 100, max: 2000)]
26-
public int $billingAmount;
16+
public function __construct(
17+
#[ODM\Field]
18+
#[ODM\Encrypt(queryType: ODM\Encrypt::QUERY_TYPE_EQUALITY)]
19+
public string $ssn,
20+
#[ODM\EmbedOne(targetDocument: PatientBilling::class)]
21+
#[ODM\Encrypt]
22+
public PatientBilling $billing,
23+
#[ODM\Field]
24+
#[ODM\Encrypt(queryType: ODM\Encrypt::QUERY_TYPE_RANGE, sparsity: 1, trimFactor: 4, min: 100, max: 2000)]
25+
public int $billingAmount,
26+
) {
27+
}
2728
}

0 commit comments

Comments
 (0)