Skip to content

Commit 350a11a

Browse files
committed
Merge remote-tracking branch 'upstream/master' into PHPLIB-892
2 parents 178be17 + 5a14dee commit 350a11a

16 files changed

+53
-153
lines changed

tests/Collection/CrudSpecFunctionalTest.php

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use MongoDB\Operation\FindOneAndReplace;
1414
use MongoDB\UpdateResult;
1515
use MultipleIterator;
16-
use PHPUnit_Framework_SkippedTestError;
1716

1817
use function array_diff_key;
1918
use function array_key_exists;
@@ -25,7 +24,6 @@
2524
use function sprintf;
2625
use function str_replace;
2726
use function strtolower;
28-
use function version_compare;
2927

3028
/**
3129
* CRUD spec functional tests.
@@ -54,8 +52,12 @@ public function setUp(): void
5452
/** @dataProvider provideSpecificationTests */
5553
public function testSpecification(array $initialData, array $test, $minServerVersion, $maxServerVersion, $serverless): void
5654
{
57-
if (isset($minServerVersion) || isset($maxServerVersion)) {
58-
$this->checkServerVersion($minServerVersion, $maxServerVersion);
55+
if (isset($minServerVersion)) {
56+
$this->skipIfServerVersion('<', $minServerVersion);
57+
}
58+
59+
if (isset($maxServerVersion)) {
60+
$this->skipIfServerVersion('>=', $maxServerVersion);
5961
}
6062

6163
$this->checkServerlessRequirement($serverless);
@@ -143,24 +145,6 @@ private function checkServerlessRequirement(?string $serverless): void
143145
}
144146
}
145147

146-
/**
147-
* Checks that the server version is within the allowed bounds (if any).
148-
*
149-
* @throws PHPUnit_Framework_SkippedTestError
150-
*/
151-
private function checkServerVersion(?string $minServerVersion, ?string $maxServerVersion): void
152-
{
153-
$serverVersion = $this->getServerVersion();
154-
155-
if (isset($minServerVersion) && version_compare($serverVersion, $minServerVersion, '<')) {
156-
$this->markTestSkipped(sprintf('Server version "%s" < minServerVersion "%s"', $serverVersion, $minServerVersion));
157-
}
158-
159-
if (isset($maxServerVersion) && version_compare($serverVersion, $maxServerVersion, '>=')) {
160-
$this->markTestSkipped(sprintf('Server version "%s" >= maxServerVersion "%s"', $serverVersion, $maxServerVersion));
161-
}
162-
}
163-
164148
/**
165149
* Executes an "operation" block.
166150
*

tests/DocumentationExamplesTest.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use function ob_start;
2121
use function usleep;
2222
use function var_dump;
23-
use function version_compare;
2423

2524
/**
2625
* Documentation examples to be parsed for inclusion in the MongoDB manual.
@@ -1549,9 +1548,7 @@ public function testCausalConsistency(): void
15491548

15501549
public function testSnapshotQueries(): void
15511550
{
1552-
if (version_compare($this->getServerVersion(), '5.0.0', '<')) {
1553-
$this->markTestSkipped('Snapshot queries outside of transactions are not supported');
1554-
}
1551+
$this->skipIfServerVersion('<', '5.0.0', 'Snapshot queries outside of transactions are not supported');
15551552

15561553
if (! ($this->isReplicaSet() || $this->isShardedClusterUsingReplicasets())) {
15571554
$this->markTestSkipped('Snapshot read concern is only supported with replicasets');
@@ -1682,13 +1679,8 @@ public function testVersionedApi(): void
16821679

16831680
public function testVersionedApiMigration(): void
16841681
{
1685-
if (version_compare($this->getServerVersion(), '5.0.0', '<')) {
1686-
$this->markTestSkipped('Versioned API is not supported');
1687-
}
1688-
1689-
if (version_compare($this->getServerVersion(), '5.0.9', '>=')) {
1690-
$this->markTestSkipped('The count command was added to API version 1 (SERVER-63850)');
1691-
}
1682+
$this->skipIfServerVersion('<', '5.0.0', 'Versioned API is not supported');
1683+
$this->skipIfServerVersion('>=', '5.0.9', 'The count command was added to API version 1 (SERVER-63850)');
16921684

16931685
$this->dropCollection($this->getDatabaseName(), 'sales');
16941686
$uriString = static::getUri(true);
@@ -1817,9 +1809,7 @@ public function testQueryableEncryption(): void
18171809
$this->markTestSkipped('Queryable encryption requires replica sets');
18181810
}
18191811

1820-
if (version_compare($this->getServerVersion(), '7.0.0', '<')) {
1821-
$this->markTestSkipped('Explicit encryption tests require MongoDB 7.0 or later');
1822-
}
1812+
$this->skipIfServerVersion('<', '7.0.0', 'Explicit encryption tests require MongoDB 7.0 or later');
18231813

18241814
if (! static::isCryptSharedLibAvailable() && ! static::isMongocryptdAvailable()) {
18251815
$this->markTestSkipped('Neither crypt_shared nor mongocryptd are available');

tests/FunctionalTestCase.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,13 @@ protected function isShardedClusterUsingReplicasets()
473473
return preg_match('@^.*/.*:\d+@', $document['host']);
474474
}
475475

476+
protected function skipIfServerVersion(string $operator, string $version, ?string $message = null): void
477+
{
478+
if (version_compare($this->getServerVersion(), $version, $operator)) {
479+
$this->markTestSkipped($message ?? sprintf('Server version is %s %s', $operator, $version));
480+
}
481+
}
482+
476483
protected function skipIfChangeStreamIsNotSupported(): void
477484
{
478485
switch ($this->getPrimaryServer()->getType()) {

tests/Operation/BulkWriteFunctionalTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use stdClass;
1616

1717
use function is_array;
18-
use function version_compare;
1918

2019
class BulkWriteFunctionalTest extends FunctionalTestCase
2120
{
@@ -200,8 +199,8 @@ function (array $event) use ($expectedReplacement): void {
200199
*/
201200
public function testUpdateDocuments($update, $expectedUpdate): void
202201
{
203-
if (is_array($expectedUpdate) && version_compare($this->getServerVersion(), '4.2.0', '<')) {
204-
$this->markTestSkipped('Pipeline-style updates are not supported');
202+
if (is_array($expectedUpdate)) {
203+
$this->skipIfServerVersion('<', '4.2.0', 'Pipeline-style updates are not supported');
205204
}
206205

207206
(new CommandObserver())->observe(
@@ -425,9 +424,7 @@ function (array $event): void {
425424

426425
public function testBulkWriteWithPipelineUpdates(): void
427426
{
428-
if (version_compare($this->getServerVersion(), '4.2.0', '<')) {
429-
$this->markTestSkipped('Pipeline-style updates are not supported');
430-
}
427+
$this->skipIfServerVersion('<', '4.2.0', 'Pipeline-style updates are not supported');
431428

432429
$this->createFixtures(4);
433430

tests/Operation/CreateEncryptedCollectionFunctionalTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use function base64_decode;
1515
use function getenv;
16-
use function version_compare;
1716

1817
class CreateEncryptedCollectionFunctionalTest extends FunctionalTestCase
1918
{
@@ -36,9 +35,7 @@ public function setUp(): void
3635
$this->markTestSkipped('Queryable Encryption requires replica sets');
3736
}
3837

39-
if (version_compare($this->getServerVersion(), '6.0.0', '<')) {
40-
$this->markTestSkipped('Queryable Encryption requires MongoDB 6.0 or later');
41-
}
38+
$this->skipIfServerVersion('<', '6.0.0', 'Queryable Encryption requires MongoDB 6.0 or later');
4239

4340
$client = static::createTestClient();
4441

tests/Operation/CreateIndexesFunctionalTest.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use function call_user_func;
1717
use function is_callable;
1818
use function sprintf;
19-
use function version_compare;
2019

2120
class CreateIndexesFunctionalTest extends FunctionalTestCase
2221
{
@@ -189,9 +188,7 @@ function (array $event): void {
189188

190189
public function testCommitQuorumOption(): void
191190
{
192-
if (version_compare($this->getServerVersion(), '4.3.4', '<')) {
193-
$this->markTestSkipped('commitQuorum is not supported');
194-
}
191+
$this->skipIfServerVersion('<', '4.3.4', 'commitQuorum is not supported');
195192

196193
if ($this->getPrimaryServer()->getType() !== Server::TYPE_RS_PRIMARY) {
197194
$this->markTestSkipped('commitQuorum is only supported on replica sets');
@@ -216,9 +213,7 @@ function (array $event): void {
216213

217214
public function testCommitQuorumUnsupported(): void
218215
{
219-
if (version_compare($this->getServerVersion(), '4.3.4', '>=')) {
220-
$this->markTestSkipped('commitQuorum is supported');
221-
}
216+
$this->skipIfServerVersion('>=', '4.3.4', 'commitQuorum is supported');
222217

223218
$operation = new CreateIndexes(
224219
$this->getDatabaseName(),

tests/Operation/DeleteFunctionalTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
use MongoDB\Tests\CommandObserver;
1313
use stdClass;
1414

15-
use function version_compare;
16-
1715
class DeleteFunctionalTest extends FunctionalTestCase
1816
{
1917
/** @var Collection */
@@ -87,9 +85,7 @@ public function testDeleteMany(): void
8785

8886
public function testHintOptionAndUnacknowledgedWriteConcernUnsupportedClientSideError(): void
8987
{
90-
if (version_compare($this->getServerVersion(), '4.4.0', '>=')) {
91-
$this->markTestSkipped('hint is supported');
92-
}
88+
$this->skipIfServerVersion('>=', '4.4.0', 'hint is supported');
9389

9490
$operation = new Delete(
9591
$this->getDatabaseName(),

tests/Operation/ExplainFunctionalTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
use MongoDB\Operation\UpdateOne;
2222
use MongoDB\Tests\CommandObserver;
2323

24-
use function version_compare;
25-
2624
class ExplainFunctionalTest extends FunctionalTestCase
2725
{
2826
/** @dataProvider provideVerbosityInformation */
@@ -329,9 +327,7 @@ public function testUpdateOne($verbosity, $executionStatsExpected, $allPlansExec
329327

330328
public function testAggregate(): void
331329
{
332-
if (version_compare($this->getServerVersion(), '4.0.0', '<')) {
333-
$this->markTestSkipped('Explaining aggregate command requires server version >= 4.0');
334-
}
330+
$this->skipIfServerVersion('<', '4.0.0', 'Explaining aggregate command requires server version >= 4.0');
335331

336332
$this->createFixtures(3);
337333

@@ -348,9 +344,7 @@ public function testAggregate(): void
348344
/** @dataProvider provideVerbosityInformation */
349345
public function testAggregateOptimizedToQuery($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void
350346
{
351-
if (version_compare($this->getServerVersion(), '4.2.0', '<')) {
352-
$this->markTestSkipped('MongoDB < 4.2 does not optimize simple aggregation pipelines');
353-
}
347+
$this->skipIfServerVersion('<', '4.2.0', 'MongoDB < 4.2 does not optimize simple aggregation pipelines');
354348

355349
$this->createFixtures(3);
356350

tests/Operation/FindAndModifyFunctionalTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
use MongoDB\Tests\CommandObserver;
1313
use stdClass;
1414

15-
use function version_compare;
16-
1715
class FindAndModifyFunctionalTest extends FunctionalTestCase
1816
{
1917
/** @dataProvider provideQueryDocuments */
@@ -129,9 +127,7 @@ function (array $event): void {
129127

130128
public function testHintOptionUnsupportedClientSideError(): void
131129
{
132-
if (version_compare($this->getServerVersion(), '4.2.0', '>=')) {
133-
$this->markTestSkipped('server reports error for unsupported findAndModify options');
134-
}
130+
$this->skipIfServerVersion('>=', '4.2.0', 'server reports error for unsupported findAndModify options');
135131

136132
$operation = new FindAndModify(
137133
$this->getDatabaseName(),
@@ -147,9 +143,7 @@ public function testHintOptionUnsupportedClientSideError(): void
147143

148144
public function testHintOptionAndUnacknowledgedWriteConcernUnsupportedClientSideError(): void
149145
{
150-
if (version_compare($this->getServerVersion(), '4.4.0', '>=')) {
151-
$this->markTestSkipped('hint is supported');
152-
}
146+
$this->skipIfServerVersion('>=', '4.4.0', 'hint is supported');
153147

154148
$operation = new FindAndModify(
155149
$this->getDatabaseName(),

tests/Operation/MapReduceFunctionalTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ public function testResult(): void
107107

108108
public function testResultIncludesTimingWithVerboseOption(): void
109109
{
110-
if (version_compare($this->getServerVersion(), '4.3.0', '>=')) {
111-
$this->markTestSkipped('mapReduce statistics are no longer exposed');
112-
}
110+
$this->skipIfServerVersion('>=', '4.3.0', 'mapReduce statistics are no longer exposed');
113111

114112
$this->createFixtures(3);
115113

@@ -128,9 +126,7 @@ public function testResultIncludesTimingWithVerboseOption(): void
128126

129127
public function testResultDoesNotIncludeTimingWithoutVerboseOption(): void
130128
{
131-
if (version_compare($this->getServerVersion(), '4.3.0', '>=')) {
132-
$this->markTestSkipped('mapReduce statistics are no longer exposed');
133-
}
129+
$this->skipIfServerVersion('>=', '4.3.0', 'mapReduce statistics are no longer exposed');
134130

135131
$this->createFixtures(3);
136132

tests/Operation/UpdateFunctionalTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use stdClass;
1515

1616
use function is_array;
17-
use function version_compare;
1817

1918
class UpdateFunctionalTest extends FunctionalTestCase
2019
{
@@ -56,8 +55,8 @@ function (array $event) use ($expectedFilter): void {
5655
*/
5756
public function testUpdateDocuments($update, $expectedUpdate): void
5857
{
59-
if (is_array($expectedUpdate) && version_compare($this->getServerVersion(), '4.2.0', '<')) {
60-
$this->markTestSkipped('Pipeline-style updates are not supported');
58+
if (is_array($expectedUpdate)) {
59+
$this->skipIfServerVersion('<', '4.2.0', 'Pipeline-style updates are not supported');
6160
}
6261

6362
(new CommandObserver())->observe(
@@ -152,9 +151,7 @@ function (array $event): void {
152151

153152
public function testHintOptionAndUnacknowledgedWriteConcernUnsupportedClientSideError(): void
154153
{
155-
if (version_compare($this->getServerVersion(), '4.2.0', '>=')) {
156-
$this->markTestSkipped('hint is supported');
157-
}
154+
$this->skipIfServerVersion('>=', '4.2.0', 'hint is supported');
158155

159156
$operation = new Update(
160157
$this->getDatabaseName(),

0 commit comments

Comments
 (0)