Skip to content

Commit 7532582

Browse files
committed
Add build variant to test with requireApiVersion=true
1 parent 6aa33d3 commit 7532582

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

.evergreen/config.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ functions:
176176
params:
177177
script: |
178178
${PREPARE_SHELL}
179-
MONGODB_VERSION=${VERSION} ORCHESTRATION_FILE=${ORCHESTRATION_FILE} TOPOLOGY=${TOPOLOGY} AUTH=${AUTH} SSL=${SSL} STORAGE_ENGINE=${STORAGE_ENGINE} sh ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
179+
MONGODB_VERSION=${VERSION} ORCHESTRATION_FILE=${ORCHESTRATION_FILE} TOPOLOGY=${TOPOLOGY} AUTH=${AUTH} SSL=${SSL} STORAGE_ENGINE=${STORAGE_ENGINE} REQUIRE_API_VERSION=${REQUIRE_API_VERSION} sh ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
180180
# run-orchestration generates expansion file with the MONGODB_URI for the cluster
181181
- command: expansions.update
182182
params:
@@ -215,7 +215,7 @@ functions:
215215
export GCP_EMAIL="${client_side_encryption_gcp_email}"
216216
export GCP_PRIVATEKEY="${client_side_encryption_gcp_privatekey}"
217217
export PATH="${PHP_PATH}/bin:$PATH"
218-
PHP_VERSION=${PHP_VERSION} AUTH=${AUTH} SSL=${SSL} MONGODB_URI="${MONGODB_URI}" sh ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
218+
API_VERSION=${API_VERSION} PHP_VERSION=${PHP_VERSION} AUTH=${AUTH} SSL=${SSL} MONGODB_URI="${MONGODB_URI}" sh ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
219219
220220
"run atlas data lake test":
221221
- command: shell.exec
@@ -357,6 +357,17 @@ tasks:
357357
- func: "bootstrap mongohoused"
358358
- func: "run atlas data lake test"
359359

360+
- name: "test-requireApiVersion"
361+
tags: ["versioned_api"]
362+
commands:
363+
- func: "bootstrap mongo-orchestration"
364+
vars:
365+
TOPOLOGY: "server"
366+
AUTH: "auth"
367+
REQUIRE_API_VERSION: "yes"
368+
- func: "run tests"
369+
vars:
370+
API_VERSION: "1"
360371

361372
# }}}
362373

@@ -610,3 +621,10 @@ buildvariants:
610621
run_on: rhel70
611622
tasks:
612623
- name: "test-atlas-data-lake"
624+
625+
- matrix_name: "test-requireApiVersion"
626+
matrix_spec: { "php-edge-versions": "latest-stable", "versions": "latest", "driver-versions": "latest" }
627+
display_name: "Versioned API - ${versions}"
628+
run_on: rhel70
629+
tasks:
630+
- name: "test-requireApiVersion"

.evergreen/run-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ AUTH=${AUTH:-noauth}
1212
SSL=${SSL:-nossl}
1313
MONGODB_URI=${MONGODB_URI:-}
1414
TESTS=${TESTS:-}
15+
export API_VERSION=${API_VERSION:-}
1516
IS_MATRIX_TESTING=${IS_MATRIX_TESTING:-}
1617

1718
# For matrix testing, we have to determine the correct driver version

tests/TestCase.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use MongoDB\Driver\Manager;
88
use MongoDB\Driver\ReadConcern;
99
use MongoDB\Driver\ReadPreference;
10+
use MongoDB\Driver\ServerApi;
1011
use MongoDB\Driver\WriteConcern;
1112
use MongoDB\Model\BSONArray;
1213
use MongoDB\Model\BSONDocument;
@@ -45,12 +46,12 @@ public static function getUri()
4546

4647
public static function createTestClient(string $uri = null, array $options = [], array $driverOptions = []) : Client
4748
{
48-
return new Client($uri ?? static::getUri(), $options, $driverOptions);
49+
return new Client($uri ?? static::getUri(), $options, static::appendServerApiOption($driverOptions));
4950
}
5051

5152
public static function createTestManager(string $uri = null, array $options = [], array $driverOptions = []) : Manager
5253
{
53-
return new Manager($uri ?? static::getUri(), $options, $driverOptions);
54+
return new Manager($uri ?? static::getUri(), $options, static::appendServerApiOption($driverOptions));
5455
}
5556

5657
/**
@@ -314,6 +315,15 @@ protected function wrapValuesForDataProvider(array $values)
314315
}, $values);
315316
}
316317

318+
private static function appendServerApiOption(array $driverOptions) : array
319+
{
320+
if (getenv('API_VERSION') && ! isset($driverOptions['serverApi'])) {
321+
$driverOptions['serverApi'] = new ServerApi(getenv('API_VERSION'));
322+
}
323+
324+
return $driverOptions;
325+
}
326+
317327
/**
318328
* Normalizes a BSON document or array for use with assertEquals().
319329
*

0 commit comments

Comments
 (0)