Skip to content

Commit 6fa5df0

Browse files
committed
PHPLIB-702 Skip crud-v1 tests that use disabled serverless features
1 parent 2d4d0ce commit 6fa5df0

15 files changed

+54
-5
lines changed

tests/Collection/CrudSpecFunctionalTest.php

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
*/
3838
class CrudSpecFunctionalTest extends FunctionalTestCase
3939
{
40+
public const SERVERLESS_ALLOW = 'allow';
41+
public const SERVERLESS_FORBID = 'forbid';
42+
public const SERVERLESS_REQUIRE = 'require';
43+
4044
/** @var Collection */
4145
private $expectedCollection;
4246

@@ -51,12 +55,14 @@ public function setUp(): void
5155
/**
5256
* @dataProvider provideSpecificationTests
5357
*/
54-
public function testSpecification(array $initialData, array $test, $minServerVersion, $maxServerVersion): void
58+
public function testSpecification(array $initialData, array $test, $minServerVersion, $maxServerVersion, $serverless): void
5559
{
5660
if (isset($minServerVersion) || isset($maxServerVersion)) {
5761
$this->checkServerVersion($minServerVersion, $maxServerVersion);
5862
}
5963

64+
$this->checkServerlessRequirement($serverless);
65+
6066
$expectedData = $test['outcome']['collection']['data'] ?? null;
6167
$this->initializeData($initialData, $expectedData);
6268

@@ -84,12 +90,15 @@ public function provideSpecificationTests()
8490
foreach (glob(__DIR__ . '/spec-tests/*/*.json') as $filename) {
8591
$json = json_decode(file_get_contents($filename), true);
8692

87-
$minServerVersion = $json['minServerVersion'] ?? null;
88-
$maxServerVersion = $json['maxServerVersion'] ?? null;
89-
9093
foreach ($json['tests'] as $test) {
9194
$name = str_replace(' ', '_', $test['description']);
92-
$testArgs[$name] = [$json['data'], $test, $minServerVersion, $maxServerVersion];
95+
$testArgs[$name] = [
96+
$json['data'],
97+
$test,
98+
$json['minServerVersion'] ?? null,
99+
$json['maxServerVersion'] ?? null,
100+
$json['serverless'] ?? null,
101+
];
93102
}
94103
}
95104

@@ -114,6 +123,32 @@ private function assertEquivalentCollections(Collection $expectedCollection, Col
114123
}
115124
}
116125

126+
private function checkServerlessRequirement(?string $serverless): void
127+
{
128+
switch ($serverless) {
129+
case null:
130+
case self::SERVERLESS_ALLOW:
131+
return;
132+
133+
case self::SERVERLESS_FORBID:
134+
if ($this->isServerless()) {
135+
$this->markTestSkipped('Test does not apply on serverless');
136+
}
137+
138+
return;
139+
140+
case self::SERVERLESS_REQUIRE:
141+
if (! $this->isServerless()) {
142+
$this->markTestSkipped('Test requires serverless');
143+
}
144+
145+
return;
146+
147+
default:
148+
$this->fail(sprintf('Unknown serverless requirement "%s".', $serverless));
149+
}
150+
}
151+
117152
/**
118153
* Checks that the server version is within the allowed bounds (if any).
119154
*

tests/Collection/spec-tests/read/aggregate-collation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
}
77
],
88
"minServerVersion": "3.4",
9+
"serverless": "forbid",
910
"tests": [
1011
{
1112
"description": "Aggregate with collation",

tests/Collection/spec-tests/read/aggregate-out.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
}
1515
],
1616
"minServerVersion": "2.6",
17+
"serverless": "forbid",
1718
"tests": [
1819
{
1920
"description": "Aggregate with $out",

tests/Collection/spec-tests/read/count-collation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
}
77
],
88
"minServerVersion": "3.4",
9+
"serverless": "forbid",
910
"tests": [
1011
{
1112
"description": "Count documents with collation",

tests/Collection/spec-tests/read/distinct-collation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
}
1111
],
1212
"minServerVersion": "3.4",
13+
"serverless": "forbid",
1314
"tests": [
1415
{
1516
"description": "Distinct with a collation",

tests/Collection/spec-tests/read/find-collation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
}
77
],
88
"minServerVersion": "3.4",
9+
"serverless": "forbid",
910
"tests": [
1011
{
1112
"description": "Find with a collation",

tests/Collection/spec-tests/write/bulkWrite-collation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
}
2323
],
2424
"minServerVersion": "3.4",
25+
"serverless": "forbid",
2526
"tests": [
2627
{
2728
"description": "BulkWrite with delete operations and collation",

tests/Collection/spec-tests/write/deleteMany-collation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
}
1515
],
1616
"minServerVersion": "3.4",
17+
"serverless": "forbid",
1718
"tests": [
1819
{
1920
"description": "DeleteMany when many documents match with collation",

tests/Collection/spec-tests/write/deleteOne-collation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
}
1515
],
1616
"minServerVersion": "3.4",
17+
"serverless": "forbid",
1718
"tests": [
1819
{
1920
"description": "DeleteOne when many documents matches with collation",

tests/Collection/spec-tests/write/findOneAndDelete-collation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
}
1515
],
1616
"minServerVersion": "3.4",
17+
"serverless": "forbid",
1718
"tests": [
1819
{
1920
"description": "FindOneAndDelete when one document matches with collation",

tests/Collection/spec-tests/write/findOneAndReplace-collation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
}
1111
],
1212
"minServerVersion": "3.4",
13+
"serverless": "forbid",
1314
"tests": [
1415
{
1516
"description": "FindOneAndReplace when one document matches with collation returning the document after modification",

tests/Collection/spec-tests/write/findOneAndUpdate-collation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
}
1515
],
1616
"minServerVersion": "3.4",
17+
"serverless": "forbid",
1718
"tests": [
1819
{
1920
"description": "FindOneAndUpdate when many documents match with collation returning the document before modification",

tests/Collection/spec-tests/write/replaceOne-collation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
}
1111
],
1212
"minServerVersion": "3.4",
13+
"serverless": "forbid",
1314
"tests": [
1415
{
1516
"description": "ReplaceOne when one document matches with collation",

tests/Collection/spec-tests/write/updateMany-collation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
}
1515
],
1616
"minServerVersion": "3.4",
17+
"serverless": "forbid",
1718
"tests": [
1819
{
1920
"description": "UpdateMany when many documents match with collation",

tests/Collection/spec-tests/write/updateOne-collation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
}
1111
],
1212
"minServerVersion": "3.4",
13+
"serverless": "forbid",
1314
"tests": [
1415
{
1516
"description": "UpdateOne when one document matches with collation",

0 commit comments

Comments
 (0)