@@ -302,286 +302,6 @@ public function testWithTransaction(): void
302
302
$ this ->assertExampleOutput (__DIR__ . '/../examples/with_transaction.php ' , $ expectedOutput );
303
303
}
304
304
305
- /** @dataProvider provideEncryptionExamples */
306
- public function testEncryptionExamples (string $ file , string $ expectedOutput ): void
307
- {
308
- $ this ->skipIfClientSideEncryptionIsNotSupported ();
309
-
310
- /* Ensure that the key vault, collection under test, and any metadata
311
- * collections are cleaned up before and after the example is run. */
312
- $ this ->dropCollection ('test ' , 'coll ' , ['encryptedFields ' => []]);
313
- $ this ->dropCollection ('encryption ' , '__keyVault ' );
314
-
315
- /* Ensure the key vault has a partial, unique index for keyAltNames. The
316
- * key management examples already do this, so this is mainly for the
317
- * benefit of other scripts. */
318
- $ this ->setUpKeyVaultIndex ();
319
-
320
- $ this ->assertExampleOutput ($ file , $ expectedOutput );
321
- }
322
-
323
- public static function provideEncryptionExamples (): Generator
324
- {
325
- $ expectedOutput = <<<'OUTPUT'
326
- MongoDB\BSON\Binary Object
327
- (
328
- [data] => %a
329
- [type] => 4
330
- )
331
- MongoDB\BSON\Binary Object
332
- (
333
- [data] => %a
334
- [type] => 6
335
- )
336
- OUTPUT;
337
-
338
- yield 'create_data_key ' => [
339
- 'file ' => __DIR__ . '/../docs/examples/encryption/create_data_key.php ' ,
340
- 'expectedOutput ' => $ expectedOutput ,
341
- ];
342
-
343
- $ expectedOutput = <<<'OUTPUT'
344
- Error creating key: E11000 duplicate key error %s: encryption.__keyVault%sdup key: { keyAltNames: "myDataKey" }
345
- MongoDB\BSON\Binary Object
346
- (
347
- [data] => %a
348
- [type] => 6
349
- )
350
- OUTPUT;
351
-
352
- yield 'key_alt_name ' => [
353
- 'file ' => __DIR__ . '/../docs/examples/encryption/key_alt_name.php ' ,
354
- 'expectedOutput ' => $ expectedOutput ,
355
- ];
356
-
357
- $ expectedOutput = <<<'OUTPUT'
358
- MongoDB\Model\BSONDocument Object
359
- (
360
- [storage:ArrayObject:private] => Array
361
- (
362
- [_id] => 1
363
- [encryptedField] => mySecret
364
- )
365
-
366
- )
367
- MongoDB\Model\BSONDocument Object
368
- (
369
- [storage:ArrayObject:private] => Array
370
- (
371
- [_id] => 1
372
- [encryptedField] => MongoDB\BSON\Binary Object
373
- (
374
- [data] => %a
375
- [type] => 6
376
- )
377
-
378
- )
379
-
380
- )
381
- Error inserting document: Document failed validation
382
- OUTPUT;
383
-
384
- yield 'csfle-automatic_encryption-local_schema ' => [
385
- 'file ' => __DIR__ . '/../docs/examples/encryption/csfle-automatic_encryption-local_schema.php ' ,
386
- 'expectedOutput ' => $ expectedOutput ,
387
- ];
388
-
389
- $ expectedOutput = <<<'OUTPUT'
390
- MongoDB\Model\BSONDocument Object
391
- (
392
- [storage:ArrayObject:private] => Array
393
- (
394
- [_id] => 1
395
- [encryptedField] => mySecret
396
- )
397
-
398
- )
399
- MongoDB\Model\BSONDocument Object
400
- (
401
- [storage:ArrayObject:private] => Array
402
- (
403
- [_id] => 1
404
- [encryptedField] => MongoDB\BSON\Binary Object
405
- (
406
- [data] => %a
407
- [type] => 6
408
- )
409
-
410
- )
411
-
412
- )
413
- Error inserting document: Document failed validation
414
- OUTPUT;
415
-
416
- yield 'csfle-automatic_encryption-server_side_schema ' => [
417
- 'file ' => __DIR__ . '/../docs/examples/encryption/csfle-automatic_encryption-server_side_schema.php ' ,
418
- 'expectedOutput ' => $ expectedOutput ,
419
- ];
420
-
421
- $ expectedOutput = <<<'OUTPUT'
422
- MongoDB\Model\BSONDocument Object
423
- (
424
- [storage:ArrayObject:private] => Array
425
- (
426
- [_id] => 1
427
- [encryptedField] => MongoDB\BSON\Binary Object
428
- (
429
- [data] => %a
430
- [type] => 6
431
- )
432
-
433
- )
434
-
435
- )
436
- Decrypted: mySecret
437
- OUTPUT;
438
-
439
- yield 'csfle-explicit_encryption ' => [
440
- 'file ' => __DIR__ . '/../docs/examples/encryption/csfle-explicit_encryption.php ' ,
441
- 'expectedOutput ' => $ expectedOutput ,
442
- ];
443
-
444
- $ expectedOutput = <<<'OUTPUT'
445
- MongoDB\Model\BSONDocument Object
446
- (
447
- [storage:ArrayObject:private] => Array
448
- (
449
- [_id] => 1
450
- [encryptedField] => mySecret
451
- )
452
-
453
- )
454
- OUTPUT;
455
-
456
- yield 'csfle-explicit_encryption_automatic_decryption ' => [
457
- 'file ' => __DIR__ . '/../docs/examples/encryption/csfle-explicit_encryption_automatic_decryption.php ' ,
458
- 'expectedOutput ' => $ expectedOutput ,
459
- ];
460
- }
461
-
462
- /** @dataProvider provideQueryableEncryptionExamples */
463
- public function testQueryableEncryptionExamples (string $ file , string $ expectedOutput ): void
464
- {
465
- $ this ->skipIfClientSideEncryptionIsNotSupported ();
466
-
467
- $ this ->skipIfServerVersion ('< ' , '7.0.0 ' , 'Queryable encryption tests require MongoDB 7.0 or later ' );
468
-
469
- if ($ this ->isStandalone ()) {
470
- $ this ->markTestSkipped ('Queryable encryption requires replica sets ' );
471
- }
472
-
473
- /* Ensure that the key vault, collection under test, and any metadata
474
- * collections are cleaned up before and after the example is run. */
475
- $ this ->dropCollection ('test ' , 'coll ' , ['encryptedFields ' => []]);
476
- $ this ->dropCollection ('encryption ' , '__keyVault ' );
477
-
478
- // Ensure the key vault has a partial, unique index for keyAltNames
479
- $ this ->setUpKeyVaultIndex ();
480
-
481
- $ this ->assertExampleOutput ($ file , $ expectedOutput );
482
- }
483
-
484
- public static function provideQueryableEncryptionExamples (): Generator
485
- {
486
- $ expectedOutput = <<<'OUTPUT'
487
- MongoDB\Model\BSONDocument Object
488
- (
489
- [storage:ArrayObject:private] => Array
490
- (
491
- [_id] => 1
492
- [encryptedIndexed] => indexedValue
493
- [encryptedUnindexed] => unindexedValue
494
- [__safeContent__] => MongoDB\Model\BSONArray Object
495
- (
496
- [storage:ArrayObject:private] => Array
497
- (
498
- [0] => MongoDB\BSON\Binary Object
499
- (
500
- [data] => %a
501
- [type] => 0
502
- )
503
-
504
- )
505
-
506
- )
507
-
508
- )
509
-
510
- )
511
- MongoDB\Model\BSONDocument Object
512
- (
513
- [storage:ArrayObject:private] => Array
514
- (
515
- [_id] => 1
516
- [encryptedIndexed] => MongoDB\BSON\Binary Object
517
- (
518
- [data] => %a
519
- [type] => 6
520
- )
521
-
522
- [encryptedUnindexed] => MongoDB\BSON\Binary Object
523
- (
524
- [data] => %a
525
- [type] => 6
526
- )
527
-
528
- [__safeContent__] => MongoDB\Model\BSONArray Object
529
- (
530
- [storage:ArrayObject:private] => Array
531
- (
532
- [0] => MongoDB\BSON\Binary Object
533
- (
534
- [data] => %a
535
- [type] => 0
536
- )
537
-
538
- )
539
-
540
- )
541
-
542
- )
543
-
544
- )
545
- OUTPUT;
546
-
547
- yield 'queryable_encryption-automatic ' => [
548
- 'file ' => __DIR__ . '/../docs/examples/encryption/queryable_encryption-automatic.php ' ,
549
- 'expectedOutput ' => $ expectedOutput ,
550
- ];
551
-
552
- $ expectedOutput = <<<'OUTPUT'
553
- MongoDB\Model\BSONDocument Object
554
- (
555
- [storage:ArrayObject:private] => Array
556
- (
557
- [_id] => 1
558
- [encryptedIndexed] => indexedValue
559
- [encryptedUnindexed] => unindexedValue
560
- [__safeContent__] => MongoDB\Model\BSONArray Object
561
- (
562
- [storage:ArrayObject:private] => Array
563
- (
564
- [0] => MongoDB\BSON\Binary Object
565
- (
566
- [data] => %a
567
- [type] => 0
568
- )
569
-
570
- )
571
-
572
- )
573
-
574
- )
575
-
576
- )
577
- OUTPUT;
578
-
579
- yield 'queryable_encryption-explicit ' => [
580
- 'file ' => __DIR__ . '/../docs/examples/encryption/queryable_encryption-explicit.php ' ,
581
- 'expectedOutput ' => $ expectedOutput ,
582
- ];
583
- }
584
-
585
305
private function assertExampleOutput (string $ file , string $ expectedOutput ): void
586
306
{
587
307
require $ file ;
0 commit comments