Skip to content

Commit d9602fd

Browse files
committed
PHPLIB-510: Implement FLE spec tests
1 parent f503a83 commit d9602fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+22335
-6
lines changed

tests/FunctionalTestCase.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@
2626
use function is_object;
2727
use function is_string;
2828
use function key;
29+
use function ob_get_clean;
30+
use function ob_start;
2931
use function parse_url;
32+
use function phpinfo;
3033
use function preg_match;
34+
use function preg_quote;
35+
use function sprintf;
3136
use function version_compare;
37+
use const INFO_MODULES;
3238

3339
abstract class FunctionalTestCase extends TestCase
3440
{
@@ -375,6 +381,17 @@ protected function skipIfCausalConsistencyIsNotSupported()
375381
}
376382
}
377383

384+
protected function skipIfClientSideEncryptionIsNotSupported()
385+
{
386+
if (version_compare($this->getFeatureCompatibilityVersion(), '4.2', '<')) {
387+
$this->markTestSkipped('Client Side Encryption only supported on FCV 4.2 or higher');
388+
}
389+
390+
if ($this->getModuleInfo('libmongocrypt') === 'disabled') {
391+
$this->markTestSkipped('Client Side Encryption is not enabled in the MongoDB extension');
392+
}
393+
}
394+
378395
protected function skipIfTransactionsAreNotSupported()
379396
{
380397
if ($this->getPrimaryServer()->getType() === Server::TYPE_STANDALONE) {
@@ -420,6 +437,26 @@ private function disableFailPoints()
420437
}
421438
}
422439

440+
/**
441+
* @param string $row
442+
*
443+
* @return string|null
444+
*/
445+
private function getModuleInfo($row)
446+
{
447+
ob_start();
448+
phpinfo(INFO_MODULES);
449+
$info = ob_get_clean();
450+
451+
$pattern = sprintf('/^%s([\w ]+)$/m', preg_quote($row . ' => '));
452+
453+
if (preg_match($pattern, $info, $matches) !== 1) {
454+
return null;
455+
}
456+
457+
return $matches[1];
458+
}
459+
423460
/**
424461
* Checks if the failCommand command is supported on this server version
425462
*

tests/SpecTests/ChangeStreamsSpecTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ private function createChangeStream(stdClass $test)
180180

181181
switch ($test->target) {
182182
case 'client':
183-
return $context->client->watch($pipeline, $options);
183+
return $context->getClient()->watch($pipeline, $options);
184184
case 'database':
185185
return $context->getDatabase()->watch($pipeline, $options);
186186
case 'collection':
@@ -228,7 +228,7 @@ private function dropDatabasesAndCreateCollection($databaseName, $collectionName
228228
{
229229
$context = $this->getContext();
230230

231-
$database = $context->client->selectDatabase($databaseName);
231+
$database = $context->getClient()->selectDatabase($databaseName);
232232
$database->drop($context->defaultWriteOptions);
233233
$database->createCollection($collectionName, $context->defaultWriteOptions);
234234
}

0 commit comments

Comments
 (0)