Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
--TEST--
MongoDB\Driver\BulkWriteCommand::__construct() multiple options combined
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_not_live(); ?>
<?php skip_if_server_version('<', '8.0'); ?>
<?php skip_if_not_clean(); ?>
--FILE--
<?php

require_once __DIR__ . "/../utils/basic.inc";

class CommandLogger implements MongoDB\Driver\Monitoring\CommandSubscriber
{
public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event): void
{
if ($event->getCommandName() !== 'bulkWrite') {
return;
}

$command = $event->getCommand();

printf("ordered: %s\n", var_export($command->ordered, true));
printf("comment: %s\n", json_encode($command->comment));
}

public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event): void
{
}

public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event): void
{
}
}

$manager = create_test_manager();

$bulk = new MongoDB\Driver\BulkWriteCommand([
'ordered' => false,
'comment' => 'test comment',
'verboseResults' => true,
]);
$bulk->insertOne(NS, ['_id' => 1]);
$bulk->insertOne(NS, ['_id' => 2]);

$manager->addSubscriber(new CommandLogger);
$result = $manager->executeBulkWriteCommand($bulk);

var_dump($result->getInsertedCount());
var_dump($result->getInsertResults() !== null);

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
ordered: false
comment: "test comment"
int(2)
bool(true)
===DONE===
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ try {
printf("%s(%d): %s\n", get_class($e), $e->getCode(), $e->getMessage());
var_dump($e->getPartialResult());
var_dump($e->getWriteErrors());
var_dump($e->getWriteConcernErrors());
}

?>
Expand Down Expand Up @@ -64,4 +65,6 @@ array(1) {
}
}
}
array(0) {
}
===DONE===
18 changes: 18 additions & 0 deletions tests/command/command-ctor_error-002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
MongoDB\Driver\Command construction (invalid maxAwaitTimeMS range)
--FILE--
<?php

require_once __DIR__ . '/../utils/basic.inc';

echo throws(function() {
new MongoDB\Driver\Command(['ping' => 1], ['maxAwaitTimeMS' => -1]);
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Expected "maxAwaitTimeMS" option to be >= 0, -1 given
===DONE===
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
MongoDB\Driver\Exception\ConnectionTimeoutException::hasErrorLabel()
--FILE--
<?php

$exception = new MongoDB\Driver\Exception\ConnectionTimeoutException();
$labels = ['test', 'foo'];

$reflection = new ReflectionClass($exception);
$errorLabelsProperty = $reflection->getProperty('errorLabels');
$errorLabelsProperty->setValue($exception, $labels);

var_dump($exception->hasErrorLabel('foo'));
var_dump($exception->hasErrorLabel('bar'));

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
bool(true)
bool(false)
===DONE===
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
MongoDB\Driver\Exception\ExecutionTimeoutException::hasErrorLabel()
--FILE--
<?php

$exception = new MongoDB\Driver\Exception\ExecutionTimeoutException();
$labels = ['test', 'foo'];

$reflection = new ReflectionClass($exception);
$errorLabelsProperty = $reflection->getProperty('errorLabels');
$errorLabelsProperty->setValue($exception, $labels);

var_dump($exception->hasErrorLabel('foo'));
var_dump($exception->hasErrorLabel('bar'));

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
bool(true)
bool(false)
===DONE===
18 changes: 18 additions & 0 deletions tests/query/query-ctor-maxAwaitTimeMS-001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
MongoDB\Driver\Query construction with maxAwaitTimeMS option
--FILE--
<?php

$q = new MongoDB\Driver\Query([], ['maxAwaitTimeMS' => 0]);
echo "maxAwaitTimeMS=0: OK\n";

$q = new MongoDB\Driver\Query([], ['maxAwaitTimeMS' => 1000]);
echo "maxAwaitTimeMS=1000: OK\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
maxAwaitTimeMS=0: OK
maxAwaitTimeMS=1000: OK
===DONE===
16 changes: 16 additions & 0 deletions tests/query/query-ctor-maxAwaitTimeMS-002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
MongoDB\Driver\Query construction with maxAwaitTimeMS option (64-bit)
--SKIPIF--
<?php if (8 !== PHP_INT_SIZE) { die('skip Only for 64-bit platform'); } ?>
--FILE--
<?php

$q = new MongoDB\Driver\Query([], ['maxAwaitTimeMS' => 4294967295]);
echo "maxAwaitTimeMS=4294967295: OK\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
maxAwaitTimeMS=4294967295: OK
===DONE===
23 changes: 23 additions & 0 deletions tests/session/session-getServer-001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
MongoDB\Driver\Session::getServer()
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_not_libmongoc_crypto(); ?>
<?php skip_if_not_live(); ?>
--FILE--
<?php
require_once __DIR__ . "/../utils/basic.inc";

$manager = create_test_manager();
$session = $manager->startSession();

/* Session::getServer() currently returns null, as sessions are not pinned
* to a server. */
var_dump($session->getServer());

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
NULL
===DONE===
25 changes: 25 additions & 0 deletions tests/session/session-getTransactionOptions-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ $options = [
['readConcern' => new \MongoDB\Driver\ReadConcern('majority')],
['readPreference' => new \MongoDB\Driver\ReadPreference('primaryPreferred')],
['writeConcern' => new \MongoDB\Driver\WriteConcern('majority')],
[
'maxCommitTimeMS' => 5000,
'readConcern' => new \MongoDB\Driver\ReadConcern(\MongoDB\Driver\ReadConcern::MAJORITY),
'readPreference' => new \MongoDB\Driver\ReadPreference(\MongoDB\Driver\ReadPreference::PRIMARY),
'writeConcern' => new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY),
],
];

foreach ($options as $test) {
Expand Down Expand Up @@ -82,4 +88,23 @@ array(2) {
string(8) "majority"
}
}
array(4) {
["maxCommitTimeMS"]=>
int(5000)
["readConcern"]=>
object(MongoDB\Driver\ReadConcern)#%d (1) {
["level"]=>
string(8) "majority"
}
["readPreference"]=>
object(MongoDB\Driver\ReadPreference)#%d (1) {
["mode"]=>
string(7) "primary"
}
["writeConcern"]=>
object(MongoDB\Driver\WriteConcern)#%d (1) {
["w"]=>
string(8) "majority"
}
}
===DONE===
Loading