Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Nov 3, 2023

Use the driver feature to normalize the aggregation pipeline in PHP.
Diffs are easier to read when using JSON comparison.

Part of PHPLIB-1291

Related to #8

Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two questions you can address on your own but LGTM.

self::objectify($expected);
// Normalize with BSON round-trip
// BSON Documents doesn't support top-level arrays.
$actual = Document::fromPHP(['root' => $actual])->toRelaxedExtendedJSON();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to use toCanonicalExtendedJSON()?

Copy link
Member Author

@GromNaN GromNaN Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must admit that I'm very confused between the 2 methods. toCanonicalExtendedJSON() is the correct one to use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, you should stick to canonical mode. Relaxed mode is fine for concise output (e.g. debugging), but canonical is necessary to ensure accurate type comparisons.


// BSON Documents doesn't support top-level arrays.
$expected = toPHP(fromJSON('{"root":' . $expectedJson . '}'))->root;
$expected = '{"pipeline":' . $expectedJson . '}';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this is outside of the PR diff, but when is a BackedEnum used to store the expected JSON string?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe @GromNaN has some new fancy ENUM ideas? 😆 🙈

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was introduced in #6 to generate test pipelines from config Yaml.

@GromNaN GromNaN force-pushed the bson-normalize-test branch from 2b8a6ae to e44f7d0 Compare November 3, 2023 14:18
Stage::match(
// sku: \MongoDB\Builder\Query::regex('789$', ''),
sku: new Regex('789$', ''),
sku: Query::regex('789$', ''),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like comparing JSON allows to fix this issue: #6 (comment)

@GromNaN GromNaN merged commit d8898ce into mongodb:0.1 Nov 3, 2023
@GromNaN GromNaN deleted the bson-normalize-test branch November 3, 2023 16:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants