|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace MongoDB\Tests\SpecTests\Crud; |
| 4 | + |
| 5 | +use MongoDB\ClientBulkWrite; |
| 6 | +use MongoDB\Driver\Exception\InvalidArgumentException; |
| 7 | +use MongoDB\Tests\SpecTests\FunctionalTestCase; |
| 8 | + |
| 9 | +/** |
| 10 | + * Prose test 13: MongoClient.bulkWrite returns an error if auto-encryption is configured |
| 11 | + * |
| 12 | + * @see https://github.com/mongodb/specifications/tree/master/source/crud/tests#13-mongoclientbulkwrite-returns-an-error-if-auto-encryption-is-configured |
| 13 | + */ |
| 14 | +class Prose13_BulkWriteUnsupportedForAutoEncryptionTest extends FunctionalTestCase |
| 15 | +{ |
| 16 | + public function testErrorIfAutoEncryptionIsConfigured(): void |
| 17 | + { |
| 18 | + if ($this->isServerless()) { |
| 19 | + $this->markTestSkipped('bulkWrite command is not supported'); |
| 20 | + } |
| 21 | + |
| 22 | + $this->skipIfServerVersion('<', '8.0', 'bulkWrite command is not supported'); |
| 23 | + |
| 24 | + $this->skipIfClientSideEncryptionIsNotSupported(); |
| 25 | + |
| 26 | + $client = self::createTestClient(null, [], [ |
| 27 | + 'autoEncryption' => [ |
| 28 | + 'keyVaultNamespace' => $this->getNamespace(), |
| 29 | + 'kmsProviders' => ['aws' => ['accessKeyId' => 'foo', 'secretAccessKey' => 'bar']], |
| 30 | + ], |
| 31 | + ]); |
| 32 | + |
| 33 | + $collection = $client->selectCollection($this->getDatabaseName(), $this->getCollectionName()); |
| 34 | + $bulkWrite = ClientBulkWrite::createWithCollection($collection); |
| 35 | + $bulkWrite->insertOne(['a' => 'b']); |
| 36 | + |
| 37 | + try { |
| 38 | + $client->bulkWrite($bulkWrite); |
| 39 | + self::fail('InvalidArgumentException was not thrown'); |
| 40 | + } catch (InvalidArgumentException $e) { |
| 41 | + self::assertStringContainsString('bulkWrite does not currently support automatic encryption', $e->getMessage()); |
| 42 | + } |
| 43 | + } |
| 44 | +} |
0 commit comments