From 5a14dee3b14f1c51f1b7f9483741b1d226f0124d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 21 Jun 2023 12:41:43 +0200 Subject: [PATCH] PHPLIB-1153: Add helper FunctionalTestCase::skipIfServerVersion (#1107) --- tests/Collection/CrudSpecFunctionalTest.php | 28 ++------ tests/DocumentationExamplesTest.php | 18 ++--- tests/FunctionalTestCase.php | 7 ++ tests/Operation/BulkWriteFunctionalTest.php | 9 +-- ...reateEncryptedCollectionFunctionalTest.php | 5 +- .../Operation/CreateIndexesFunctionalTest.php | 9 +-- tests/Operation/DeleteFunctionalTest.php | 6 +- tests/Operation/ExplainFunctionalTest.php | 10 +-- .../Operation/FindAndModifyFunctionalTest.php | 10 +-- tests/Operation/MapReduceFunctionalTest.php | 8 +-- tests/Operation/UpdateFunctionalTest.php | 9 +-- tests/Operation/WatchFunctionalTest.php | 67 +++++-------------- ...rose21_AutomaticDataEncryptionKeysTest.php | 5 +- .../Prose22_RangeExplicitEncryptionTest.php | 5 +- .../ClientSideEncryptionSpecTest.php | 5 +- tests/SpecTests/RetryableWritesSpecTest.php | 5 +- 16 files changed, 53 insertions(+), 153 deletions(-) diff --git a/tests/Collection/CrudSpecFunctionalTest.php b/tests/Collection/CrudSpecFunctionalTest.php index 620e35298..994ec915b 100644 --- a/tests/Collection/CrudSpecFunctionalTest.php +++ b/tests/Collection/CrudSpecFunctionalTest.php @@ -13,7 +13,6 @@ use MongoDB\Operation\FindOneAndReplace; use MongoDB\UpdateResult; use MultipleIterator; -use PHPUnit_Framework_SkippedTestError; use function array_diff_key; use function array_key_exists; @@ -25,7 +24,6 @@ use function sprintf; use function str_replace; use function strtolower; -use function version_compare; /** * CRUD spec functional tests. @@ -54,8 +52,12 @@ public function setUp(): void /** @dataProvider provideSpecificationTests */ public function testSpecification(array $initialData, array $test, $minServerVersion, $maxServerVersion, $serverless): void { - if (isset($minServerVersion) || isset($maxServerVersion)) { - $this->checkServerVersion($minServerVersion, $maxServerVersion); + if (isset($minServerVersion)) { + $this->skipIfServerVersion('<', $minServerVersion); + } + + if (isset($maxServerVersion)) { + $this->skipIfServerVersion('>=', $maxServerVersion); } $this->checkServerlessRequirement($serverless); @@ -143,24 +145,6 @@ private function checkServerlessRequirement(?string $serverless): void } } - /** - * Checks that the server version is within the allowed bounds (if any). - * - * @throws PHPUnit_Framework_SkippedTestError - */ - private function checkServerVersion(?string $minServerVersion, ?string $maxServerVersion): void - { - $serverVersion = $this->getServerVersion(); - - if (isset($minServerVersion) && version_compare($serverVersion, $minServerVersion, '<')) { - $this->markTestSkipped(sprintf('Server version "%s" < minServerVersion "%s"', $serverVersion, $minServerVersion)); - } - - if (isset($maxServerVersion) && version_compare($serverVersion, $maxServerVersion, '>=')) { - $this->markTestSkipped(sprintf('Server version "%s" >= maxServerVersion "%s"', $serverVersion, $maxServerVersion)); - } - } - /** * Executes an "operation" block. * diff --git a/tests/DocumentationExamplesTest.php b/tests/DocumentationExamplesTest.php index 748f5b81d..001057454 100644 --- a/tests/DocumentationExamplesTest.php +++ b/tests/DocumentationExamplesTest.php @@ -20,7 +20,6 @@ use function ob_start; use function usleep; use function var_dump; -use function version_compare; /** * Documentation examples to be parsed for inclusion in the MongoDB manual. @@ -1549,9 +1548,7 @@ public function testCausalConsistency(): void public function testSnapshotQueries(): void { - if (version_compare($this->getServerVersion(), '5.0.0', '<')) { - $this->markTestSkipped('Snapshot queries outside of transactions are not supported'); - } + $this->skipIfServerVersion('<', '5.0.0', 'Snapshot queries outside of transactions are not supported'); if (! ($this->isReplicaSet() || $this->isShardedClusterUsingReplicasets())) { $this->markTestSkipped('Snapshot read concern is only supported with replicasets'); @@ -1682,13 +1679,8 @@ public function testVersionedApi(): void public function testVersionedApiMigration(): void { - if (version_compare($this->getServerVersion(), '5.0.0', '<')) { - $this->markTestSkipped('Versioned API is not supported'); - } - - if (version_compare($this->getServerVersion(), '5.0.9', '>=')) { - $this->markTestSkipped('The count command was added to API version 1 (SERVER-63850)'); - } + $this->skipIfServerVersion('<', '5.0.0', 'Versioned API is not supported'); + $this->skipIfServerVersion('>=', '5.0.9', 'The count command was added to API version 1 (SERVER-63850)'); $this->dropCollection($this->getDatabaseName(), 'sales'); $uriString = static::getUri(true); @@ -1817,9 +1809,7 @@ public function testQueryableEncryption(): void $this->markTestSkipped('Queryable encryption requires replica sets'); } - if (version_compare($this->getServerVersion(), '7.0.0', '<')) { - $this->markTestSkipped('Explicit encryption tests require MongoDB 7.0 or later'); - } + $this->skipIfServerVersion('<', '7.0.0', 'Explicit encryption tests require MongoDB 7.0 or later'); if (! $this->isEnterprise()) { $this->markTestSkipped('Automatic encryption requires MongoDB Enterprise'); diff --git a/tests/FunctionalTestCase.php b/tests/FunctionalTestCase.php index 0e5e7de46..b4d4fb5ab 100644 --- a/tests/FunctionalTestCase.php +++ b/tests/FunctionalTestCase.php @@ -484,6 +484,13 @@ protected function isShardedClusterUsingReplicasets() return preg_match('@^.*/.*:\d+@', $document['host']); } + protected function skipIfServerVersion(string $operator, string $version, ?string $message = null): void + { + if (version_compare($this->getServerVersion(), $version, $operator)) { + $this->markTestSkipped($message ?? sprintf('Server version is %s %s', $operator, $version)); + } + } + protected function skipIfChangeStreamIsNotSupported(): void { switch ($this->getPrimaryServer()->getType()) { diff --git a/tests/Operation/BulkWriteFunctionalTest.php b/tests/Operation/BulkWriteFunctionalTest.php index 0dbb20e67..2acb747bf 100644 --- a/tests/Operation/BulkWriteFunctionalTest.php +++ b/tests/Operation/BulkWriteFunctionalTest.php @@ -15,7 +15,6 @@ use stdClass; use function is_array; -use function version_compare; class BulkWriteFunctionalTest extends FunctionalTestCase { @@ -200,8 +199,8 @@ function (array $event) use ($expectedReplacement): void { */ public function testUpdateDocuments($update, $expectedUpdate): void { - if (is_array($expectedUpdate) && version_compare($this->getServerVersion(), '4.2.0', '<')) { - $this->markTestSkipped('Pipeline-style updates are not supported'); + if (is_array($expectedUpdate)) { + $this->skipIfServerVersion('<', '4.2.0', 'Pipeline-style updates are not supported'); } (new CommandObserver())->observe( @@ -425,9 +424,7 @@ function (array $event): void { public function testBulkWriteWithPipelineUpdates(): void { - if (version_compare($this->getServerVersion(), '4.2.0', '<')) { - $this->markTestSkipped('Pipeline-style updates are not supported'); - } + $this->skipIfServerVersion('<', '4.2.0', 'Pipeline-style updates are not supported'); $this->createFixtures(4); diff --git a/tests/Operation/CreateEncryptedCollectionFunctionalTest.php b/tests/Operation/CreateEncryptedCollectionFunctionalTest.php index df690dd29..b6d920ce4 100644 --- a/tests/Operation/CreateEncryptedCollectionFunctionalTest.php +++ b/tests/Operation/CreateEncryptedCollectionFunctionalTest.php @@ -16,7 +16,6 @@ use function getenv; use function is_executable; use function is_readable; -use function version_compare; use const DIRECTORY_SEPARATOR; use const PATH_SEPARATOR; @@ -42,9 +41,7 @@ public function setUp(): void $this->markTestSkipped('Queryable Encryption requires replica sets'); } - if (version_compare($this->getServerVersion(), '6.0.0', '<')) { - $this->markTestSkipped('Queryable Encryption requires MongoDB 6.0 or later'); - } + $this->skipIfServerVersion('<', '6.0.0', 'Queryable Encryption requires MongoDB 6.0 or later'); $client = static::createTestClient(); diff --git a/tests/Operation/CreateIndexesFunctionalTest.php b/tests/Operation/CreateIndexesFunctionalTest.php index 13deb386c..748e33bc1 100644 --- a/tests/Operation/CreateIndexesFunctionalTest.php +++ b/tests/Operation/CreateIndexesFunctionalTest.php @@ -16,7 +16,6 @@ use function call_user_func; use function is_callable; use function sprintf; -use function version_compare; class CreateIndexesFunctionalTest extends FunctionalTestCase { @@ -189,9 +188,7 @@ function (array $event): void { public function testCommitQuorumOption(): void { - if (version_compare($this->getServerVersion(), '4.3.4', '<')) { - $this->markTestSkipped('commitQuorum is not supported'); - } + $this->skipIfServerVersion('<', '4.3.4', 'commitQuorum is not supported'); if ($this->getPrimaryServer()->getType() !== Server::TYPE_RS_PRIMARY) { $this->markTestSkipped('commitQuorum is only supported on replica sets'); @@ -216,9 +213,7 @@ function (array $event): void { public function testCommitQuorumUnsupported(): void { - if (version_compare($this->getServerVersion(), '4.3.4', '>=')) { - $this->markTestSkipped('commitQuorum is supported'); - } + $this->skipIfServerVersion('>=', '4.3.4', 'commitQuorum is supported'); $operation = new CreateIndexes( $this->getDatabaseName(), diff --git a/tests/Operation/DeleteFunctionalTest.php b/tests/Operation/DeleteFunctionalTest.php index 692441ac6..4ae84045e 100644 --- a/tests/Operation/DeleteFunctionalTest.php +++ b/tests/Operation/DeleteFunctionalTest.php @@ -12,8 +12,6 @@ use MongoDB\Tests\CommandObserver; use stdClass; -use function version_compare; - class DeleteFunctionalTest extends FunctionalTestCase { /** @var Collection */ @@ -87,9 +85,7 @@ public function testDeleteMany(): void public function testHintOptionAndUnacknowledgedWriteConcernUnsupportedClientSideError(): void { - if (version_compare($this->getServerVersion(), '4.4.0', '>=')) { - $this->markTestSkipped('hint is supported'); - } + $this->skipIfServerVersion('>=', '4.4.0', 'hint is supported'); $operation = new Delete( $this->getDatabaseName(), diff --git a/tests/Operation/ExplainFunctionalTest.php b/tests/Operation/ExplainFunctionalTest.php index 264289013..aa28ce8f7 100644 --- a/tests/Operation/ExplainFunctionalTest.php +++ b/tests/Operation/ExplainFunctionalTest.php @@ -21,8 +21,6 @@ use MongoDB\Operation\UpdateOne; use MongoDB\Tests\CommandObserver; -use function version_compare; - class ExplainFunctionalTest extends FunctionalTestCase { /** @dataProvider provideVerbosityInformation */ @@ -329,9 +327,7 @@ public function testUpdateOne($verbosity, $executionStatsExpected, $allPlansExec public function testAggregate(): void { - if (version_compare($this->getServerVersion(), '4.0.0', '<')) { - $this->markTestSkipped('Explaining aggregate command requires server version >= 4.0'); - } + $this->skipIfServerVersion('<', '4.0.0', 'Explaining aggregate command requires server version >= 4.0'); $this->createFixtures(3); @@ -348,9 +344,7 @@ public function testAggregate(): void /** @dataProvider provideVerbosityInformation */ public function testAggregateOptimizedToQuery($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void { - if (version_compare($this->getServerVersion(), '4.2.0', '<')) { - $this->markTestSkipped('MongoDB < 4.2 does not optimize simple aggregation pipelines'); - } + $this->skipIfServerVersion('<', '4.2.0', 'MongoDB < 4.2 does not optimize simple aggregation pipelines'); $this->createFixtures(3); diff --git a/tests/Operation/FindAndModifyFunctionalTest.php b/tests/Operation/FindAndModifyFunctionalTest.php index 22b2c9e56..ebdbd1092 100644 --- a/tests/Operation/FindAndModifyFunctionalTest.php +++ b/tests/Operation/FindAndModifyFunctionalTest.php @@ -12,8 +12,6 @@ use MongoDB\Tests\CommandObserver; use stdClass; -use function version_compare; - class FindAndModifyFunctionalTest extends FunctionalTestCase { /** @dataProvider provideQueryDocuments */ @@ -129,9 +127,7 @@ function (array $event): void { public function testHintOptionUnsupportedClientSideError(): void { - if (version_compare($this->getServerVersion(), '4.2.0', '>=')) { - $this->markTestSkipped('server reports error for unsupported findAndModify options'); - } + $this->skipIfServerVersion('>=', '4.2.0', 'server reports error for unsupported findAndModify options'); $operation = new FindAndModify( $this->getDatabaseName(), @@ -147,9 +143,7 @@ public function testHintOptionUnsupportedClientSideError(): void public function testHintOptionAndUnacknowledgedWriteConcernUnsupportedClientSideError(): void { - if (version_compare($this->getServerVersion(), '4.4.0', '>=')) { - $this->markTestSkipped('hint is supported'); - } + $this->skipIfServerVersion('>=', '4.4.0', 'hint is supported'); $operation = new FindAndModify( $this->getDatabaseName(), diff --git a/tests/Operation/MapReduceFunctionalTest.php b/tests/Operation/MapReduceFunctionalTest.php index bdb3ffc7a..55831dd2f 100644 --- a/tests/Operation/MapReduceFunctionalTest.php +++ b/tests/Operation/MapReduceFunctionalTest.php @@ -107,9 +107,7 @@ public function testResult(): void public function testResultIncludesTimingWithVerboseOption(): void { - if (version_compare($this->getServerVersion(), '4.3.0', '>=')) { - $this->markTestSkipped('mapReduce statistics are no longer exposed'); - } + $this->skipIfServerVersion('>=', '4.3.0', 'mapReduce statistics are no longer exposed'); $this->createFixtures(3); @@ -128,9 +126,7 @@ public function testResultIncludesTimingWithVerboseOption(): void public function testResultDoesNotIncludeTimingWithoutVerboseOption(): void { - if (version_compare($this->getServerVersion(), '4.3.0', '>=')) { - $this->markTestSkipped('mapReduce statistics are no longer exposed'); - } + $this->skipIfServerVersion('>=', '4.3.0', 'mapReduce statistics are no longer exposed'); $this->createFixtures(3); diff --git a/tests/Operation/UpdateFunctionalTest.php b/tests/Operation/UpdateFunctionalTest.php index 7af2fc674..d0a92679f 100644 --- a/tests/Operation/UpdateFunctionalTest.php +++ b/tests/Operation/UpdateFunctionalTest.php @@ -14,7 +14,6 @@ use stdClass; use function is_array; -use function version_compare; class UpdateFunctionalTest extends FunctionalTestCase { @@ -56,8 +55,8 @@ function (array $event) use ($expectedFilter): void { */ public function testUpdateDocuments($update, $expectedUpdate): void { - if (is_array($expectedUpdate) && version_compare($this->getServerVersion(), '4.2.0', '<')) { - $this->markTestSkipped('Pipeline-style updates are not supported'); + if (is_array($expectedUpdate)) { + $this->skipIfServerVersion('<', '4.2.0', 'Pipeline-style updates are not supported'); } (new CommandObserver())->observe( @@ -152,9 +151,7 @@ function (array $event): void { public function testHintOptionAndUnacknowledgedWriteConcernUnsupportedClientSideError(): void { - if (version_compare($this->getServerVersion(), '4.2.0', '>=')) { - $this->markTestSkipped('hint is supported'); - } + $this->skipIfServerVersion('>=', '4.2.0', 'hint is supported'); $operation = new Update( $this->getDatabaseName(), diff --git a/tests/Operation/WatchFunctionalTest.php b/tests/Operation/WatchFunctionalTest.php index 66c8d85bd..bc633c191 100644 --- a/tests/Operation/WatchFunctionalTest.php +++ b/tests/Operation/WatchFunctionalTest.php @@ -29,7 +29,6 @@ use function microtime; use function MongoDB\server_supports_feature; use function sprintf; -use function version_compare; /** * @group matrix-testing-exclude-server-4.2-driver-4.0-topology-sharded_cluster @@ -61,9 +60,7 @@ public function setUp(): void */ public function testGetResumeToken(): void { - if ($this->isPostBatchResumeTokenSupported()) { - $this->markTestSkipped('postBatchResumeToken is supported'); - } + $this->skipIfServerVersion('>=', '4.0.7', 'postBatchResumeToken is supported'); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions); $changeStream = $operation->execute($this->getPrimaryServer()); @@ -108,9 +105,7 @@ public function testGetResumeToken(): void */ public function testGetResumeTokenWithPostBatchResumeToken(): void { - if (! $this->isPostBatchResumeTokenSupported()) { - $this->markTestSkipped('postBatchResumeToken is not supported'); - } + $this->skipIfServerVersion('<', '4.0.7', 'postBatchResumeToken is not supported'); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions); @@ -206,9 +201,7 @@ function (array $event) use (&$commands): void { public function testResumeBeforeReceivingAnyResultsIncludesPostBatchResumeToken(): void { - if (! $this->isPostBatchResumeTokenSupported()) { - $this->markTestSkipped('postBatchResumeToken is not supported'); - } + $this->skipIfServerVersion('<', '4.0.7', 'postBatchResumeToken is not supported'); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions); @@ -282,9 +275,7 @@ public function testResumeBeforeReceivingAnyResultsIncludesStartAtOperationTime( $this->markTestSkipped('startAtOperationTime is not supported'); } - if ($this->isPostBatchResumeTokenSupported()) { - $this->markTestSkipped('postBatchResumeToken takes precedence over startAtOperationTime'); - } + $this->skipIfServerVersion('>=', '4.0.7', 'postBatchResumeToken takes precedence over startAtOperationTime'); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions); @@ -699,9 +690,7 @@ public function testInitialCursorIsNotClosed(): void */ public function testResumeTokenNotFoundClientSideError(): void { - if (version_compare($this->getServerVersion(), '4.1.8', '>=')) { - $this->markTestSkipped('Server rejects change streams that modify resume token (SERVER-37786)'); - } + $this->skipIfServerVersion('>=', '4.1.8', 'Server rejects change streams that modify resume token (SERVER-37786)'); $pipeline = [['$project' => ['_id' => 0]]]; @@ -727,9 +716,7 @@ public function testResumeTokenNotFoundClientSideError(): void */ public function testResumeTokenNotFoundServerSideError(): void { - if (version_compare($this->getServerVersion(), '4.1.8', '<')) { - $this->markTestSkipped('Server does not reject change streams that modify resume token'); - } + $this->skipIfServerVersion('<', '4.1.8', 'Server does not reject change streams that modify resume token'); $pipeline = [['$project' => ['_id' => 0]]]; @@ -750,9 +737,7 @@ public function testResumeTokenNotFoundServerSideError(): void */ public function testResumeTokenInvalidTypeClientSideError(): void { - if (version_compare($this->getServerVersion(), '4.1.8', '>=')) { - $this->markTestSkipped('Server rejects change streams that modify resume token (SERVER-37786)'); - } + $this->skipIfServerVersion('>=', '4.1.8', 'Server rejects change streams that modify resume token (SERVER-37786)'); $pipeline = [['$project' => ['_id' => ['$literal' => 'foo']]]]; @@ -778,9 +763,7 @@ public function testResumeTokenInvalidTypeClientSideError(): void */ public function testResumeTokenInvalidTypeServerSideError(): void { - if (version_compare($this->getServerVersion(), '4.1.8', '<')) { - $this->markTestSkipped('Server does not reject change streams that modify resume token'); - } + $this->skipIfServerVersion('<', '4.1.8', 'Server does not reject change streams that modify resume token'); $pipeline = [['$project' => ['_id' => ['$literal' => 'foo']]]]; @@ -964,9 +947,7 @@ public function testResumeAfterOption(): void public function testStartAfterOption(): void { - if (version_compare($this->getServerVersion(), '4.1.1', '<')) { - $this->markTestSkipped('startAfter is not supported'); - } + $this->skipIfServerVersion('<', '4.1.1', 'startAfter is not supported'); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions); $changeStream = $operation->execute($this->getPrimaryServer()); @@ -1175,8 +1156,8 @@ function (array $event) use (&$sessionAfterResume, &$commands): void { public function testSessionFreed(): void { - if ($this->isShardedCluster() && version_compare($this->getServerVersion(), '5.1.0', '>=')) { - $this->markTestSkipped('mongos still reports non-zero cursor ID for invalidated change stream (SERVER-60764)'); + if ($this->isShardedCluster()) { + $this->skipIfServerVersion('>=', '5.1.0', 'mongos still reports non-zero cursor ID for invalidated change stream (SERVER-60764)'); } $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions); @@ -1283,9 +1264,7 @@ function (array $aggregateCommand) { */ public function testErrorDuringAggregateCommandDoesNotCauseResume(): void { - if (version_compare($this->getServerVersion(), '4.0.0', '<')) { - $this->markTestSkipped('failCommand is not supported'); - } + $this->skipIfServerVersion('<', '4.0.0', 'failCommand is not supported'); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions); @@ -1362,9 +1341,7 @@ function () { */ public function testGetResumeTokenReturnsOriginalResumeTokenOnEmptyBatch(): void { - if ($this->isPostBatchResumeTokenSupported()) { - $this->markTestSkipped('postBatchResumeToken is supported'); - } + $this->skipIfServerVersion('>=', '4.0.7', 'postBatchResumeToken is supported'); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions); $changeStream = $operation->execute($this->getPrimaryServer()); @@ -1398,10 +1375,7 @@ public function testGetResumeTokenReturnsOriginalResumeTokenOnEmptyBatch(): void */ public function testResumeTokenBehaviour(): void { - if (version_compare($this->getServerVersion(), '4.1.1', '<')) { - $this->markTestSkipped('Testing resumeAfter and startAfter can only be tested on servers >= 4.1.1'); - } - + $this->skipIfServerVersion('<', '4.1.1', 'Testing resumeAfter and startAfter can only be tested on servers >= 4.1.1'); $this->skipIfIsShardedCluster('Resume token behaviour can\'t be reliably tested on sharded clusters.'); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions); @@ -1457,9 +1431,7 @@ public function testResumeTokenBehaviour(): void */ public function testResumingChangeStreamWithoutPreviousResultsIncludesStartAfterOption(): void { - if (version_compare($this->getServerVersion(), '4.1.1', '<')) { - $this->markTestSkipped('Testing resumeAfter and startAfter can only be tested on servers >= 4.1.1'); - } + $this->skipIfServerVersion('<', '4.1.1', 'Testing resumeAfter and startAfter can only be tested on servers >= 4.1.1'); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions); $changeStream = $operation->execute($this->getPrimaryServer()); @@ -1504,9 +1476,7 @@ function (array $event) use (&$aggregateCommand): void { */ public function testResumingChangeStreamWithPreviousResultsIncludesResumeAfterOption(): void { - if (version_compare($this->getServerVersion(), '4.1.1', '<')) { - $this->markTestSkipped('Testing resumeAfter and startAfter can only be tested on servers >= 4.1.1'); - } + $this->skipIfServerVersion('<', '4.1.1', 'Testing resumeAfter and startAfter can only be tested on servers >= 4.1.1'); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions); $changeStream = $operation->execute($this->getPrimaryServer()); @@ -1596,11 +1566,6 @@ private function insertDocument($document): void $this->assertEquals(1, $writeResult->getInsertedCount()); } - private function isPostBatchResumeTokenSupported() - { - return version_compare($this->getServerVersion(), '4.0.7', '>='); - } - private function isStartAtOperationTimeSupported() { return server_supports_feature($this->getPrimaryServer(), self::$wireVersionForStartAtOperationTime); diff --git a/tests/SpecTests/ClientSideEncryption/Prose21_AutomaticDataEncryptionKeysTest.php b/tests/SpecTests/ClientSideEncryption/Prose21_AutomaticDataEncryptionKeysTest.php index 91cad0e1d..ea99ca1c2 100644 --- a/tests/SpecTests/ClientSideEncryption/Prose21_AutomaticDataEncryptionKeysTest.php +++ b/tests/SpecTests/ClientSideEncryption/Prose21_AutomaticDataEncryptionKeysTest.php @@ -11,7 +11,6 @@ use MongoDB\Exception\InvalidArgumentException; use function base64_decode; -use function version_compare; /** * Prose test 21: Automatic Data Encryption Keys @@ -35,9 +34,7 @@ public function setUp(): void $this->markTestSkipped('Automatic data encryption key tests require replica sets'); } - if (version_compare($this->getServerVersion(), '7.0.0', '<')) { - $this->markTestSkipped('Automatic data encryption key tests require MongoDB 7.0 or later'); - } + $this->skipIfServerVersion('<', '7.0.0', 'Automatic data encryption key tests require MongoDB 7.0 or later'); $client = static::createTestClient(); $this->database = $client->selectDatabase($this->getDatabaseName()); diff --git a/tests/SpecTests/ClientSideEncryption/Prose22_RangeExplicitEncryptionTest.php b/tests/SpecTests/ClientSideEncryption/Prose22_RangeExplicitEncryptionTest.php index 1c0efb058..d1c437745 100644 --- a/tests/SpecTests/ClientSideEncryption/Prose22_RangeExplicitEncryptionTest.php +++ b/tests/SpecTests/ClientSideEncryption/Prose22_RangeExplicitEncryptionTest.php @@ -17,7 +17,6 @@ use function file_get_contents; use function get_debug_type; use function is_int; -use function version_compare; /** * Prose test 22: Range Explicit Encryption @@ -41,9 +40,7 @@ public function setUp(): void $this->markTestSkipped('Range explicit encryption tests require replica sets'); } - if (version_compare($this->getServerVersion(), '7.0.0', '<')) { - $this->markTestSkipped('Range explicit encryption tests require MongoDB 7.0 or later'); - } + $this->skipIfServerVersion('<', '7.0.0', 'Range explicit encryption tests require MongoDB 7.0 or later'); $client = static::createTestClient(); diff --git a/tests/SpecTests/ClientSideEncryptionSpecTest.php b/tests/SpecTests/ClientSideEncryptionSpecTest.php index 744156fe1..e75ef306d 100644 --- a/tests/SpecTests/ClientSideEncryptionSpecTest.php +++ b/tests/SpecTests/ClientSideEncryptionSpecTest.php @@ -46,7 +46,6 @@ use function strlen; use function substr; use function unserialize; -use function version_compare; use const DIRECTORY_SEPARATOR; use const PATH_SEPARATOR; @@ -1339,9 +1338,7 @@ public function testExplicitEncryption(Closure $test): void $this->markTestSkipped('Explicit encryption tests require replica sets'); } - if (version_compare($this->getServerVersion(), '7.0.0', '<')) { - $this->markTestSkipped('Explicit encryption tests require MongoDB 7.0 or later'); - } + $this->skipIfServerVersion('<', '7.0.0', 'Explicit encryption tests require MongoDB 7.0 or later'); // Test setup $encryptedFields = $this->decodeJson(file_get_contents(__DIR__ . '/client-side-encryption/etc/data/encryptedFields.json')); diff --git a/tests/SpecTests/RetryableWritesSpecTest.php b/tests/SpecTests/RetryableWritesSpecTest.php index 4479d9806..a0506cadc 100644 --- a/tests/SpecTests/RetryableWritesSpecTest.php +++ b/tests/SpecTests/RetryableWritesSpecTest.php @@ -12,7 +12,6 @@ use function basename; use function file_get_contents; use function glob; -use function version_compare; /** * Retryable writes spec tests. @@ -90,9 +89,7 @@ public function testNoWritesPerformedErrorReturnsOriginalError(): void $this->markTestSkipped('Test only applies to replica sets'); } - if (version_compare($this->getServerVersion(), '4.4.0', '<')) { - $this->markTestSkipped('NoWritesPerformed error label is only supported on MongoDB 4.4+'); - } + $this->skipIfServerVersion('<', '4.4.0', 'NoWritesPerformed error label is only supported on MongoDB 4.4+'); $client = self::createTestClient(null, ['retryWrites' => true]);