-
Notifications
You must be signed in to change notification settings - Fork 264
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
PHPLIB-1227 Use void return types for operations without meaningful result document #1468
Conversation
@@ -314,17 +310,13 @@ public function createCollection(string $collectionName, array $options = []): a | |||
* getPrevious() and getEncryptedFields() methods, respectively. | |||
* | |||
* @see CreateCollection::__construct() for supported options | |||
* @return array A tuple containing the command result document from creating the collection and the modified "encryptedFields" option | |||
* @return array The modified "encryptedFields" option |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of a tuple, we return the 2nd element (the encryptedFields
), but the return type is not modified.
tests/FunctionalTestCase.php
Outdated
@@ -189,6 +196,45 @@ protected function assertCollectionExists(string $collectionName, ?string $datab | |||
} | |||
} | |||
|
|||
/** @param callable():void $closure */ | |||
protected static function commandResult(callable $closure): object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Read command result from the events. That allows to keep the assertCommandSucceeded
. But it might not be necessary if the operations throw an exception when the command fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I concur. There should be no reason to maintain assertCommandSucceeded()
, although removing it entirely might leave some tests without assertions (easy fix if so).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed all that assertions. assertCommandSucceeded
is still used when running raw commands.
* * typeMap (array): Type map for BSON deserialization. This will only be | ||
* used for the returned command result document. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The typeMap option can be removed since we don't return the command results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking of your comment below on createDataKeys()
, I noted you didn't suggest deprecating the typeMap
option in 1.x. I also don't think that's necessary and feel we can just rely on upgrade notes for 2.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with not needing a deprecation notice for removing typeMap, as we won't throw an error when the option is present, it just won't do anything.
I would point out however that a typeMap
option here is a pretty good indication that the caller intends to use the result, so it could be a way to notify users of the changing return type. Since it doesn't catch all cases, I'm not sure it's warranted though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebased on #1473
244030e
to
6f2085c
Compare
* @throws DriverRuntimeException for errors creating a data key | ||
*/ | ||
public function createDataKeys(ClientEncryption $clientEncryption, string $kmsProvider, ?array $masterKey, ?array &$encryptedFields = null): void | ||
public function createDataKeys(ClientEncryption $clientEncryption, string $kmsProvider, ?array $masterKey): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function return null, we don't need to have a by-reference parameter to output the data keys. Using the returned value is more common.
This change can be backported to 1.x, with a deprecation message if $encryptedFields
parameter is passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change can be backported to 1.x
FWIW, I'm OK skipping that and just communicating this in the upgrade notes. I think it's very unlikely that anyone was actually using this API.
Defer to you, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we consider the operation (and thus the API) internal in 1.x, I agree with not adding a deprecation layer in 1.x.
e15bc11
to
c6772de
Compare
* @throws DriverRuntimeException for errors creating a data key | ||
*/ | ||
public function createDataKeys(ClientEncryption $clientEncryption, string $kmsProvider, ?array $masterKey, ?array &$encryptedFields = null): void | ||
public function createDataKeys(ClientEncryption $clientEncryption, string $kmsProvider, ?array $masterKey): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change can be backported to 1.x
FWIW, I'm OK skipping that and just communicating this in the upgrade notes. I think it's very unlikely that anyone was actually using this API.
Defer to you, though.
* * typeMap (array): Type map for BSON deserialization. This will only be | ||
* used for the returned command result document. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking of your comment below on createDataKeys()
, I noted you didn't suggest deprecating the typeMap
option in 1.x. I also don't think that's necessary and feel we can just rely on upgrade notes for 2.0.
tests/FunctionalTestCase.php
Outdated
@@ -189,6 +196,45 @@ protected function assertCollectionExists(string $collectionName, ?string $datab | |||
} | |||
} | |||
|
|||
/** @param callable():void $closure */ | |||
protected static function commandResult(callable $closure): object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I concur. There should be no reason to maintain assertCommandSucceeded()
, although removing it entirely might leave some tests without assertions (easy fix if so).
96d6c8a
to
a901218
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments, and I agree with the list of operations that no longer return a result. I'll defer to @jmikola for the detailed review.
* * typeMap (array): Type map for BSON deserialization. This will only be | ||
* used for the returned command result document. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with not needing a deprecation notice for removing typeMap, as we won't throw an error when the option is present, it just won't do anything.
I would point out however that a typeMap
option here is a pretty good indication that the caller intends to use the result, so it could be a way to notify users of the changing return type. Since it doesn't catch all cases, I'm not sure it's warranted though.
* @throws DriverRuntimeException for errors creating a data key | ||
*/ | ||
public function createDataKeys(ClientEncryption $clientEncryption, string $kmsProvider, ?array $masterKey, ?array &$encryptedFields = null): void | ||
public function createDataKeys(ClientEncryption $clientEncryption, string $kmsProvider, ?array $masterKey): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we consider the operation (and thus the API) internal in 1.x, I agree with not adding a deprecation layer in 1.x.
378073a
to
eea3fbe
Compare
eea3fbe
to
260c266
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two suggestions (your call). LGTM with whatever you decide.
@@ -29,9 +33,23 @@ public function testCollMod(): void | |||
['index' => ['keyPattern' => ['lastAccess' => 1], 'expireAfterSeconds' => 1000]], | |||
['typeMap' => ['root' => 'array', 'document' => 'array']], | |||
); | |||
$result = $modifyCollection->execute($this->getPrimaryServer()); | |||
$modifyCollection->execute($this->getPrimaryServer()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that the return value of collMod
is entirely irrelevant, as the server docs include a note about being able to infer whether a value actually changed server-side by inspecting the command result:
If the operation is successful but the hidden value has not changed (specifically, hiding an already hidden index or unhiding an already unhidden index), the command omits the
hidden_old
andhidden_new
fields from the output.
I didn't consider that until seeing this test change.
If you agree, I'd suggest just reverting the changes to ModifyCollection. Otherwise, feel free to leave as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reverted the change on this operation. This was missing from #1473, so nothing to revert on v1.x
72bf1b8
to
9b89a1b
Compare
* v2.x: PHPLIB-1546 and PHPLIB-1159: Remove CreateCollection flags and autoIndexId options (#1478) PHPLIB-1227 Use void return types for operations without meaningful result document (#1468) Remove deprecated functionality (#1439) PHPLIB-1518 `WriteResult::get*Count()` always return an int on acknowledged result (#1454) PHPLIB-954: Add return types to all methods (#1391) PHPLIB-797: Remove unused methods in UnsupportedException (#1436) Revert "Add final annotations to non-internal Operation classes (#1410)" PHPLIB-953 Make internal classes and Operation classes final (#1392) PHPLIB-1218 Remove deprecated fields from GridFS files (#1398)
* v2.x: PHPLIB-1546 and PHPLIB-1159: Remove CreateCollection flags and autoIndexId options (#1478) PHPLIB-1227 Use void return types for operations without meaningful result document (#1468) Remove deprecated functionality (#1439) PHPLIB-1518 `WriteResult::get*Count()` always return an int on acknowledged result (#1454) PHPLIB-954: Add return types to all methods (#1391) PHPLIB-797: Remove unused methods in UnsupportedException (#1436) Revert "Add final annotations to non-internal Operation classes (#1410)" PHPLIB-953 Make internal classes and Operation classes final (#1392) PHPLIB-1218 Remove deprecated fields from GridFS files (#1398)
* v2.x: Regenerate evergreen configuration (#1503) PHPLIB-1546 and PHPLIB-1159: Remove CreateCollection flags and autoIndexId options (#1478) PHPLIB-1227 Use void return types for operations without meaningful result document (#1468) Remove deprecated functionality (#1439) PHPLIB-1518 `WriteResult::get*Count()` always return an int on acknowledged result (#1454) PHPLIB-954: Add return types to all methods (#1391) PHPLIB-797: Remove unused methods in UnsupportedException (#1436) Revert "Add final annotations to non-internal Operation classes (#1410)" PHPLIB-953 Make internal classes and Operation classes final (#1392) PHPLIB-1218 Remove deprecated fields from GridFS files (#1398)
Fix PHPLIB-1227
This introduces major breaking changes that we did not deprecate.