@@ -240,9 +240,9 @@ public function testDataKeyAndDoubleEncryption(string $providerName, $masterKey)
240
240
$ clientEncrypted = static ::createTestClient (null , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
241
241
$ clientEncryption = $ clientEncrypted ->createClientEncryption ($ encryptionOpts );
242
242
243
- $ commands = [];
244
-
245
243
$ dataKeyId = null ;
244
+ $ insertCommand = null ;
245
+
246
246
$ keyAltName = $ providerName . '_altname ' ;
247
247
248
248
(new CommandObserver ())->observe (
@@ -254,18 +254,20 @@ function () use ($clientEncryption, &$dataKeyId, $keyAltName, $providerName, $ma
254
254
255
255
$ dataKeyId = $ clientEncryption ->createDataKey ($ providerName , $ keyData );
256
256
},
257
- function ($ command ) use (&$ commands ): void {
258
- $ commands [] = $ command ;
257
+ function ($ command ) use (&$ insertCommand ): void {
258
+ if ($ command ['started ' ]->getCommandName () === 'insert ' ) {
259
+ $ insertCommand = $ command ['started ' ]->getCommand ();
260
+ }
259
261
}
260
262
);
261
263
262
264
$ this ->assertInstanceOf (Binary::class, $ dataKeyId );
263
265
$ this ->assertSame (Binary::TYPE_UUID , $ dataKeyId ->getType ());
264
266
265
- $ this ->assertCount ( 2 , $ commands );
266
- $ insert = $ commands [ 1 ][ ' started ' ] ;
267
- $ this ->assertSame ( ' insert ' , $ insert -> getCommandName () );
268
- $ this ->assertSame (WriteConcern::MAJORITY , $ insert -> getCommand () ->writeConcern ->w );
267
+ $ this ->assertNotNull ( $ insertCommand );
268
+ $ this -> assertObjectHasAttribute ( ' writeConcern ' , $ insertCommand ) ;
269
+ $ this ->assertObjectHasAttribute ( ' w ' , $ insertCommand -> writeConcern );
270
+ $ this ->assertSame (WriteConcern::MAJORITY , $ insertCommand ->writeConcern ->w );
269
271
270
272
$ keys = $ client ->selectCollection ('keyvault ' , 'datakeys ' )->find (['_id ' => $ dataKeyId ]);
271
273
$ keys = iterator_to_array ($ keys );
0 commit comments