Files
mongo-php-driver/tests/clientEncryption/clientEncryption-ctor_error-002.phpt
Jeremy Mikola 03fcb6b9ef PHPC-2099: crypt_shared testing (#1333)
* Use non-breaking space in OS axis labels

* Revise titles and Manager construction in autoEncryption tests

* Define CSFLE_KEY_VAULT_NS and CSFLE_LOCAL_KEY constants

The value for CSFLE_KEY_VAULT_NS is based on the example from PHPLIB-826. This was not required but helps makes all tests consistent and will make it easier if we need to add functionality to a helper to drop the key vault collection before a test.

Using CSFLE_LOCAL_KEY allows removal of a duplicated string literal in various CSFLE tests. Although the new constant wasn't required for all tests (empty strings worked fine to satisfy option validation), using a constant helps ensure consistency across the test suite.

Also use create_test_manager() in more places when basic.inc is included. The remaining instances of direct Manager construction should only be in tests where basic.inc isn't used.
2022-06-22 13:37:56 -04:00

54 lines
1.8 KiB
PHP

--TEST--
MongoDB\Driver\ClientEncryption::__construct() with invalid option types
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_not_libmongocrypt(); ?>
--FILE--
<?php
require_once __DIR__ . '/../utils/basic.inc';
/* phongo_clientencryption_opts_from_zval always requires a keyVaultClient
* option when constructing ClientEncryption directly, so this will be used to
* test other options. */
$baseOptions = ['keyVaultClient' => create_test_manager()];
$tests = [
[],
['keyVaultClient' => 'not_an_array_or_object'],
[
'keyVaultNamespace' => 'not_a_namespace',
// keyVaultNamespace requires a valid kmsProviders option
'kmsProviders' => ['local' => ['key' => new MongoDB\BSON\Binary(CSFLE_LOCAL_KEY, 0)]],
] + $baseOptions,
['kmsProviders' => 'not_an_array_or_object'] + $baseOptions,
['tlsOptions' => 'not_an_array_or_object'] + $baseOptions,
];
foreach ($tests as $test) {
echo throws(function () use ($test) {
new MongoDB\Driver\ClientEncryption($test);
}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n\n";
}
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
The "keyVaultClient" option is required when constructing a ClientEncryption object directly
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Expected "keyVaultClient" option to be MongoDB\Driver\Manager, string given
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Expected "keyVaultNamespace" option to contain a full collection namespace
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Expected "kmsProviders" option to be an array or object, string given
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Expected "tlsOptions" option to be an array or object, string given
===DONE===