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

PHPLIB-1358 Add tests on Type Expression Operators #49

Merged
merged 1 commit into from
Jan 24, 2024

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Jan 23, 2024

Fix PHPLIB-1358

https://www.mongodb.com/docs/manual/reference/operator/aggregation/#type-expression-operators

  • $convert
  • $isNumber fixed, as it get a single value
  • $toBool
  • $toDate already done
  • $toDecimal
  • $toDouble
  • $toInt
  • $toLong
  • $toObjectId
  • $toString already done
  • $type

@GromNaN GromNaN requested a review from jmikola January 23, 2024 17:40
/**
* Test $toDouble expression
*/
class ToDoubleOperatorTest extends PipelineTestCase
Copy link
Member

Choose a reason for hiding this comment

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

This is outside the scope of the PR, but why does the parameter type for ToDoubleOperator::__construct() include non-empty-string instead of just string? In toDouble.yaml, the $expression argument has a type expression.

I traced this to a "strings cannot be empty" comment in OperatorGenerator::getAcceptedTypes(), but it's unclear to me why that is. That's also the case for StrLenBytesOperator, which I'd expect would be able to take a string of any length.

Copy link
Member Author

Choose a reason for hiding this comment

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

Out of zeal, I've put this type for all the strings, but that's probably overkill.

Copy link
Member

Choose a reason for hiding this comment

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

I feel like there would be at least some cases where an empty string is a legitimate argument for some operators. If you agree, consider opening a separate issue to investigate that at a later point.

Copy link
Member Author

Choose a reason for hiding this comment

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

Tracked in PHPLIB-1373

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.

LGTM with suggestion to revisit the non-empty-string typing at a later point.

@GromNaN GromNaN merged commit ff4fc79 into mongodb:0.1 Jan 24, 2024
@GromNaN GromNaN deleted the PHPLIB-1358 branch January 24, 2024 09:19
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.

2 participants