Skip to content

PHPLIB-1157: Limit omitted field assertions to top-level #1094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions tests/SpecTests/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use function json_encode;
use function MongoDB\BSON\fromJSON;
use function MongoDB\BSON\toPHP;
use function property_exists;
use function sprintf;
use function version_compare;

Expand Down Expand Up @@ -97,23 +96,19 @@ public static function assertDocumentsMatch($expectedDocument, $actualDocument,
}

/**
* Assert omitted fields in command documents.
* Assert omitted top-level fields in command documents.
*
* Note: this method may modify the $expected object.
*
* @see https://github.com/mongodb/specifications/blob/master/source/transactions/tests/README.rst#null-values
* @see https://github.com/mongodb/specifications/blob/09ee1ebc481f1502e3246971a9419e484d736207/source/command-monitoring/tests/README.rst#additional-values
*/
protected static function assertCommandOmittedFields(stdClass $expected, stdClass $actual): void
{
foreach ($expected as $key => $value) {
if ($value === null) {
static::assertObjectNotHasAttribute($key, $actual);
unset($expected->{$key});
continue;
}

if ($value instanceof stdClass && property_exists($actual, $key) && $actual->{$key} instanceof stdClass) {
static::assertCommandOmittedFields($value, $actual->{$key});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,38 @@
"result": {
"errorContains": "Driver support of Queryable Encryption is incompatible with server. Upgrade server to use Queryable Encryption."
}
},
{
"name": "assertCollectionNotExists",
"object": "testRunner",
"arguments": {
"database": "default",
"collection": "enxcol_.encryptedCollection.esc"
}
},
{
"name": "assertCollectionNotExists",
"object": "testRunner",
"arguments": {
"database": "default",
"collection": "enxcol_.encryptedCollection.ecc"
}
},
{
"name": "assertCollectionNotExists",
"object": "testRunner",
"arguments": {
"database": "default",
"collection": "enxcol_.encryptedCollection.ecoc"
}
},
{
"name": "assertCollectionNotExists",
"object": "testRunner",
"arguments": {
"database": "default",
"collection": "encryptedCollection"
}
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@
"command": {
"create": "encryptedCollection",
"encryptedFields": {
"escCollection": null,
"ecocCollection": null,
"eccCollection": null,
"fields": [
{
"path": "firstName",
Expand Down Expand Up @@ -343,9 +340,6 @@
"command": {
"create": "encryptedCollection",
"encryptedFields": {
"escCollection": null,
"ecocCollection": null,
"eccCollection": null,
"fields": [
{
"path": "firstName",
Expand Down Expand Up @@ -851,9 +845,6 @@
"command": {
"create": "encryptedCollection",
"encryptedFields": {
"escCollection": null,
"ecocCollection": null,
"eccCollection": null,
"fields": [
{
"path": "firstName",
Expand Down Expand Up @@ -1048,9 +1039,6 @@
"command": {
"create": "encryptedCollection",
"encryptedFields": {
"escCollection": null,
"ecocCollection": null,
"eccCollection": null,
"fields": [
{
"path": "firstName",
Expand Down Expand Up @@ -1367,9 +1355,6 @@
"command": {
"create": "encryptedCollection",
"encryptedFields": {
"escCollection": null,
"ecocCollection": null,
"eccCollection": null,
"fields": [
{
"path": "firstName",
Expand Down Expand Up @@ -1635,9 +1620,6 @@
"command": {
"create": "encryptedCollection",
"encryptedFields": {
"escCollection": null,
"ecocCollection": null,
"eccCollection": null,
"fields": [
{
"path": "firstName",
Expand Down