Skip to content

PHPLIB-401: ResumeTokenException extends RuntimeException #646

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 4 commits into from
Jul 29, 2019
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
2 changes: 1 addition & 1 deletion src/Exception/ResumeTokenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace MongoDB\Exception;

class ResumeTokenException extends \Exception
class ResumeTokenException extends RuntimeException
{
/**
* Thrown when a resume token has an invalid type.
Expand Down
23 changes: 11 additions & 12 deletions src/Operation/Aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class Aggregate implements Executable
* * batchSize (integer): The number of documents to return per batch.
*
* * bypassDocumentValidation (boolean): If true, allows the write to
* circumvent document level validation. This only applies when the $out
* stage is specified.
* circumvent document level validation. This only applies when an $out
* or $merge stage is specified.
*
* For servers < 3.2, this option is ignored as document level validation
* is not available.
Expand All @@ -87,15 +87,14 @@ class Aggregate implements Executable
* * maxTimeMS (integer): The maximum amount of time to allow the query to
* run.
*
* * readConcern (MongoDB\Driver\ReadConcern): Read concern. Note that a
* "majority" read concern is not compatible with the $out stage.
* * readConcern (MongoDB\Driver\ReadConcern): Read concern.
*
* This is not supported for server versions < 3.2 and will result in an
* exception at execution time if used.
*
* * readPreference (MongoDB\Driver\ReadPreference): Read preference.
*
* This option is ignored if the $out stage is specified.
* This option is ignored if an $out or $merge stage is specified.
*
* * session (MongoDB\Driver\Session): Client session.
*
Expand All @@ -111,7 +110,7 @@ class Aggregate implements Executable
* mongod/mongos upgrades.
*
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern. This only
* applies when the $out stage is specified.
* applies when an $out or $merge stage is specified.
*
* This is not supported for server versions < 3.4 and will result in an
* exception at execution time if used.
Expand Down Expand Up @@ -298,10 +297,10 @@ public function execute(Server $server)
* Create the aggregate command.
*
* @param Server $server
* @param boolean $hasOutStage
* @param boolean $hasWriteStage
* @return Command
*/
private function createCommand(Server $server, $hasOutStage)
private function createCommand(Server $server, $hasWriteStage)
{
$cmd = [
'aggregate' => isset($this->collectionName) ? $this->collectionName : 1,
Expand Down Expand Up @@ -337,10 +336,10 @@ private function createCommand(Server $server, $hasOutStage)
}

if ($this->options['useCursor']) {
/* Ignore batchSize if pipeline includes an $out stage, as no
* documents will be returned and sending a batchSize of zero could
* prevent the pipeline from executing at all. */
$cmd['cursor'] = isset($this->options["batchSize"]) && ! $hasOutStage
/* Ignore batchSize if pipeline includes an $out or $merge stage, as
* no documents will be returned and sending a batchSize of zero
* could prevent the pipeline from executing at all. */
$cmd['cursor'] = isset($this->options["batchSize"]) && !$hasWriteStage
? ['batchSize' => $this->options["batchSize"]]
: new stdClass;
}
Expand Down
14 changes: 5 additions & 9 deletions tests/SpecTests/CommandExpectations.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static function fromTransactions(array $expectedEvents)
*/
public function commandFailed(CommandFailedEvent $event)
{
if ($this->ignoreCommandFailed) {
if ($this->ignoreCommandFailed || ($this->ignoreExtraEvents && count($this->actualEvents) === count($this->expectedEvents))) {
return;
}

Expand All @@ -105,7 +105,7 @@ public function commandFailed(CommandFailedEvent $event)
*/
public function commandStarted(CommandStartedEvent $event)
{
if ($this->ignoreCommandStarted) {
if ($this->ignoreCommandStarted || ($this->ignoreExtraEvents && count($this->actualEvents) === count($this->expectedEvents))) {
return;
}

Expand All @@ -119,7 +119,7 @@ public function commandStarted(CommandStartedEvent $event)
*/
public function commandSucceeded(CommandSucceededEvent $event)
{
if ($this->ignoreCommandSucceeded) {
if ($this->ignoreCommandSucceeded || ($this->ignoreExtraEvents && count($this->actualEvents) === count($this->expectedEvents))) {
return;
}

Expand Down Expand Up @@ -150,15 +150,11 @@ public function stopMonitoring()
*/
public function assert(FunctionalTestCase $test, Context $context)
{
$actualEvents = $this->ignoreExtraEvents
? array_slice($this->actualEvents, 0, count($this->expectedEvents))
: $this->actualEvents;

$test->assertCount(count($this->expectedEvents), $actualEvents);
$test->assertCount(count($this->expectedEvents), $this->actualEvents);

$mi = new MultipleIterator(MultipleIterator::MIT_NEED_ANY);
$mi->attachIterator(new ArrayIterator($this->expectedEvents));
$mi->attachIterator(new ArrayIterator($actualEvents));
$mi->attachIterator(new ArrayIterator($this->actualEvents));

foreach ($mi as $events) {
list($expectedEventAndClass, $actualEvent) = $events;
Expand Down