@@ -16,12 +16,20 @@ public function setUp(): void
16
16
}
17
17
18
18
if ($ this ->isApiVersionRequired ()) {
19
- $ this ->markTestSkipped ('Examples are not tested with when the server requires specifying an API version. ' );
19
+ $ this ->markTestSkipped ('Examples are not tested when the server requires specifying an API version. ' );
20
20
}
21
21
22
22
self ::createTestClient ()->dropDatabase ('test ' );
23
23
}
24
24
25
+ /** @dataProvider provideBasicExamples */
26
+ public function testBasicExamples (string $ file , string $ expectedOutput ): void
27
+ {
28
+ require $ file ;
29
+
30
+ self ::assertStringMatchesFormat ($ expectedOutput , $ this ->getActualOutputForAssertion ());
31
+ }
32
+
25
33
public function dataExamples (): Generator
26
34
{
27
35
$ expectedOutput = <<<'OUTPUT'
@@ -177,14 +185,6 @@ public function testChangeStream(): void
177
185
$ this ->testExample (__DIR__ . '/../examples/changestream.php ' , $ expectedOutput );
178
186
}
179
187
180
- /** @dataProvider dataExamples */
181
- public function testExample (string $ file , string $ expectedOutput ): void
182
- {
183
- require $ file ;
184
-
185
- self ::assertStringMatchesFormat ($ expectedOutput , $ this ->getActualOutputForAssertion ());
186
- }
187
-
188
188
public function testWithTransaction (): void
189
189
{
190
190
$ this ->skipIfTransactionsAreNotSupported ();
@@ -197,4 +197,231 @@ public function testWithTransaction(): void
197
197
198
198
$ this ->testExample (__DIR__ . '/../examples/with_transaction.php ' , $ expectedOutput );
199
199
}
200
+
201
+ /** @dataProvider provideEncryptionExamples */
202
+ public function testEncryptionExamples (string $ file , string $ expectedOutput ): void
203
+ {
204
+ $ this ->skipIfClientSideEncryptionIsNotSupported ();
205
+
206
+ require $ file ;
207
+
208
+ self ::assertStringMatchesFormat ($ expectedOutput , $ this ->getActualOutputForAssertion ());
209
+ }
210
+
211
+ public function provideEncryptionExamples (): Generator
212
+ {
213
+ $ expectedOutput = <<<'OUTPUT'
214
+ MongoDB\BSON\Binary Object
215
+ (
216
+ [data] => %a
217
+ [type] => 4
218
+ )
219
+ MongoDB\BSON\Binary Object
220
+ (
221
+ [data] => %a
222
+ [type] => 6
223
+ )
224
+ OUTPUT;
225
+
226
+ yield 'create_data_key ' => [
227
+ 'file ' => __DIR__ . '/../docs/examples/create_data_key.php ' ,
228
+ 'expectedOutput ' => $ expectedOutput ,
229
+ ];
230
+
231
+ $ expectedOutput = <<<'OUTPUT'
232
+ MongoDB\BSON\Binary Object
233
+ (
234
+ [data] => %a
235
+ [type] => 6
236
+ )
237
+ OUTPUT;
238
+
239
+ yield 'key_alt_name ' => [
240
+ 'file ' => __DIR__ . '/../docs/examples/key_alt_name.php ' ,
241
+ 'expectedOutput ' => $ expectedOutput ,
242
+ ];
243
+
244
+ $ expectedOutput = <<<'OUTPUT'
245
+ MongoDB\Model\BSONDocument Object
246
+ (
247
+ [storage:ArrayObject:private] => Array
248
+ (
249
+ [_id] => 1
250
+ [encryptedField] => mySecret
251
+ )
252
+
253
+ )
254
+ MongoDB\Model\BSONDocument Object
255
+ (
256
+ [storage:ArrayObject:private] => Array
257
+ (
258
+ [_id] => 1
259
+ [encryptedField] => MongoDB\BSON\Binary Object
260
+ (
261
+ [data] => %a
262
+ [type] => 6
263
+ )
264
+
265
+ )
266
+
267
+ )
268
+ OUTPUT;
269
+
270
+ yield 'csfle-automatic_encryption-local_schema ' => [
271
+ 'file ' => __DIR__ . '/../docs/examples/csfle-automatic_encryption-local_schema.php ' ,
272
+ 'expectedOutput ' => $ expectedOutput ,
273
+ ];
274
+
275
+ $ expectedOutput = <<<'OUTPUT'
276
+ MongoDB\Model\BSONDocument Object
277
+ (
278
+ [storage:ArrayObject:private] => Array
279
+ (
280
+ [_id] => 1
281
+ [encryptedField] => mySecret
282
+ )
283
+
284
+ )
285
+ MongoDB\Model\BSONDocument Object
286
+ (
287
+ [storage:ArrayObject:private] => Array
288
+ (
289
+ [_id] => 1
290
+ [encryptedField] => MongoDB\BSON\Binary Object
291
+ (
292
+ [data] => %a
293
+ [type] => 6
294
+ )
295
+
296
+ )
297
+
298
+ )
299
+ OUTPUT;
300
+
301
+ yield 'csfle-automatic_encryption-server_side_schema ' => [
302
+ 'file ' => __DIR__ . '/../docs/examples/csfle-automatic_encryption-server_side_schema.php ' ,
303
+ 'expectedOutput ' => $ expectedOutput ,
304
+ ];
305
+
306
+ $ expectedOutput = <<<'OUTPUT'
307
+ MongoDB\BSON\Binary Object
308
+ (
309
+ [data] => %a
310
+ [type] => 6
311
+ )
312
+ mySecret
313
+ OUTPUT;
314
+
315
+ yield 'csfle-explicit_encryption ' => [
316
+ 'file ' => __DIR__ . '/../docs/examples/csfle-explicit_encryption.php ' ,
317
+ 'expectedOutput ' => $ expectedOutput ,
318
+ ];
319
+
320
+ $ expectedOutput = <<<'OUTPUT'
321
+ mySecret
322
+ OUTPUT;
323
+
324
+ yield 'csfle-explicit_encryption_automatic_decryption ' => [
325
+ 'file ' => __DIR__ . '/../docs/examples/csfle-explicit_encryption_automatic_decryption.php ' ,
326
+ 'expectedOutput ' => $ expectedOutput ,
327
+ ];
328
+
329
+ $ expectedOutput = <<<'OUTPUT'
330
+ MongoDB\Model\BSONDocument Object
331
+ (
332
+ [storage:ArrayObject:private] => Array
333
+ (
334
+ [_id] => 1
335
+ [encryptedIndexed] => indexedValue
336
+ [encryptedUnindexed] => unindexedValue
337
+ [__safeContent__] => MongoDB\Model\BSONArray Object
338
+ (
339
+ [storage:ArrayObject:private] => Array
340
+ (
341
+ [0] => MongoDB\BSON\Binary Object
342
+ (
343
+ [data] => %a
344
+ [type] => 0
345
+ )
346
+
347
+ )
348
+
349
+ )
350
+
351
+ )
352
+
353
+ )
354
+ MongoDB\Model\BSONDocument Object
355
+ (
356
+ [storage:ArrayObject:private] => Array
357
+ (
358
+ [_id] => 1
359
+ [encryptedIndexed] => MongoDB\BSON\Binary Object
360
+ (
361
+ [data] => %a
362
+ [type] => 6
363
+ )
364
+
365
+ [encryptedUnindexed] => MongoDB\BSON\Binary Object
366
+ (
367
+ [data] => %a
368
+ [type] => 6
369
+ )
370
+
371
+ [__safeContent__] => MongoDB\Model\BSONArray Object
372
+ (
373
+ [storage:ArrayObject:private] => Array
374
+ (
375
+ [0] => MongoDB\BSON\Binary Object
376
+ (
377
+ [data] => %a
378
+ [type] => 0
379
+ )
380
+
381
+ )
382
+
383
+ )
384
+
385
+ )
386
+
387
+ )
388
+ OUTPUT;
389
+
390
+ yield 'queryable_encryption-automatic ' => [
391
+ 'file ' => __DIR__ . '/../docs/examples/queryable_encryption-automatic.php ' ,
392
+ 'expectedOutput ' => $ expectedOutput ,
393
+ ];
394
+
395
+ $ expectedOutput = <<<'OUTPUT'
396
+ MongoDB\Model\BSONDocument Object
397
+ (
398
+ [storage:ArrayObject:private] => Array
399
+ (
400
+ [_id] => 1
401
+ [encryptedIndexed] => indexedValue
402
+ [encryptedUnindexed] => unindexedValue
403
+ [__safeContent__] => MongoDB\Model\BSONArray Object
404
+ (
405
+ [storage:ArrayObject:private] => Array
406
+ (
407
+ [0] => MongoDB\BSON\Binary Object
408
+ (
409
+ [data] => %a
410
+ [type] => 0
411
+ )
412
+
413
+ )
414
+
415
+ )
416
+
417
+ )
418
+
419
+ )
420
+ OUTPUT;
421
+
422
+ yield 'queryable_encryption-explicit ' => [
423
+ 'file ' => __DIR__ . '/../docs/examples/queryable_encryption-explicit.php ' ,
424
+ 'expectedOutput ' => $ expectedOutput ,
425
+ ];
426
+ }
200
427
}
0 commit comments