@@ -240,9 +240,9 @@ public function testDataKeyAndDoubleEncryption(string $providerName, $masterKey)
240240 $ clientEncrypted = static ::createTestClient (null , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
241241 $ clientEncryption = $ clientEncrypted ->createClientEncryption ($ encryptionOpts );
242242
243- $ commands = [];
244-
245243 $ dataKeyId = null ;
244+ $ insertCommand = null ;
245+
246246 $ keyAltName = $ providerName . '_altname ' ;
247247
248248 (new CommandObserver ())->observe (
@@ -254,18 +254,20 @@ function () use ($clientEncryption, &$dataKeyId, $keyAltName, $providerName, $ma
254254
255255 $ dataKeyId = $ clientEncryption ->createDataKey ($ providerName , $ keyData );
256256 },
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+ }
259261 }
260262 );
261263
262264 $ this ->assertInstanceOf (Binary::class, $ dataKeyId );
263265 $ this ->assertSame (Binary::TYPE_UUID , $ dataKeyId ->getType ());
264266
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 );
269271
270272 $ keys = $ client ->selectCollection ('keyvault ' , 'datakeys ' )->find (['_id ' => $ dataKeyId ]);
271273 $ keys = iterator_to_array ($ keys );
0 commit comments