PHPLIB-330: Apply manual fixes

parent 339492ff
...@@ -17,7 +17,9 @@ ...@@ -17,7 +17,9 @@
namespace MongoDB\Exception; namespace MongoDB\Exception;
class BadMethodCallException extends \BadMethodCallException implements Exception use BadMethodCallException as BaseBadMethodCallException;
class BadMethodCallException extends BaseBadMethodCallException implements Exception
{ {
/** /**
* Thrown when a mutable method is invoked on an immutable object. * Thrown when a mutable method is invoked on an immutable object.
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
namespace MongoDB\Exception; namespace MongoDB\Exception;
interface Exception extends \MongoDB\Driver\Exception\Exception use MongoDB\Driver\Exception\Exception as DriverException;
interface Exception extends DriverException
{ {
} }
...@@ -17,7 +17,9 @@ ...@@ -17,7 +17,9 @@
namespace MongoDB\Exception; namespace MongoDB\Exception;
class InvalidArgumentException extends \MongoDB\Driver\Exception\InvalidArgumentException implements Exception use MongoDB\Driver\Exception\InvalidArgumentException as DriverInvalidArgumentException;
class InvalidArgumentException extends DriverInvalidArgumentException implements Exception
{ {
/** /**
* Thrown when an argument or option has an invalid type. * Thrown when an argument or option has an invalid type.
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
namespace MongoDB\Exception; namespace MongoDB\Exception;
class RuntimeException extends \MongoDB\Driver\Exception\RuntimeException implements Exception use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
class RuntimeException extends DriverRuntimeException implements Exception
{ {
} }
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
namespace MongoDB\Exception; namespace MongoDB\Exception;
class UnexpectedValueException extends \MongoDB\Driver\Exception\UnexpectedValueException implements Exception use MongoDB\Driver\Exception\UnexpectedValueException as DriverUnexpectedValueException;
class UnexpectedValueException extends DriverUnexpectedValueException implements Exception
{ {
} }
...@@ -242,6 +242,7 @@ class StreamWrapper ...@@ -242,6 +242,7 @@ class StreamWrapper
private function getStatTemplate() private function getStatTemplate()
{ {
return [ return [
// phpcs:disable Squiz.Arrays.ArrayDeclaration.IndexNoNewline
0 => 0, 'dev' => 0, 0 => 0, 'dev' => 0,
1 => 0, 'ino' => 0, 1 => 0, 'ino' => 0,
2 => 0, 'mode' => 0, 2 => 0, 'mode' => 0,
...@@ -255,6 +256,7 @@ class StreamWrapper ...@@ -255,6 +256,7 @@ class StreamWrapper
10 => 0, 'ctime' => 0, 10 => 0, 'ctime' => 0,
11 => -1, 'blksize' => -1, 11 => -1, 'blksize' => -1,
12 => -1, 'blocks' => -1, 12 => -1, 'blocks' => -1,
// phpcs:enable
]; ];
} }
......
...@@ -27,5 +27,5 @@ use MongoDB\Driver\Server; ...@@ -27,5 +27,5 @@ use MongoDB\Driver\Server;
*/ */
interface Explainable extends Executable interface Explainable extends Executable
{ {
function getCommandDocument(Server $server); public function getCommandDocument(Server $server);
} }
...@@ -156,7 +156,7 @@ class MapReduce implements Executable ...@@ -156,7 +156,7 @@ class MapReduce implements Executable
} }
if (isset($options['finalize']) && ! $options['finalize'] instanceof JavascriptInterface) { if (isset($options['finalize']) && ! $options['finalize'] instanceof JavascriptInterface) {
throw InvalidArgumentException::invalidType('"finalize" option', $options['finalize'], Javascript::class); throw InvalidArgumentException::invalidType('"finalize" option', $options['finalize'], JavascriptInterface::class);
} }
if (isset($options['jsMode']) && ! is_bool($options['jsMode'])) { if (isset($options['jsMode']) && ! is_bool($options['jsMode'])) {
......
...@@ -2,16 +2,20 @@ ...@@ -2,16 +2,20 @@
namespace MongoDB\Tests; namespace MongoDB\Tests;
use MongoDB\BSON\ObjectId;
use MongoDB\BSON\UTCDateTime; use MongoDB\BSON\UTCDateTime;
use MongoDB\Client; use MongoDB\Client;
use MongoDB\Database; use MongoDB\Database;
use MongoDB\Driver\Cursor; use MongoDB\Driver\Cursor;
use MongoDB\Driver\Exception\ConnectionTimeoutException;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\ConnectionTimeoutException;
use MongoDB\Operation\DropCollection;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait; use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
use function in_array;
use function ob_end_clean;
use function ob_start;
use function var_dump;
use function version_compare;
/** /**
* Documentation examples to be parsed for inclusion in the MongoDB manual. * Documentation examples to be parsed for inclusion in the MongoDB manual.
...@@ -54,7 +58,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -54,7 +58,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
// End Example 1 // End Example 1
$this->assertSame(1, $insertOneResult->getInsertedCount()); $this->assertSame(1, $insertOneResult->getInsertedCount());
$this->assertInstanceOf(\MongoDB\BSON\ObjectId::class, $insertOneResult->getInsertedId()); $this->assertInstanceOf(ObjectId::class, $insertOneResult->getInsertedId());
$this->assertInventoryCount(1); $this->assertInventoryCount(1);
// Start Example 2 // Start Example 2
...@@ -93,7 +97,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -93,7 +97,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
$this->assertSame(3, $insertManyResult->getInsertedCount()); $this->assertSame(3, $insertManyResult->getInsertedCount());
foreach ($insertManyResult->getInsertedIds() as $id) { foreach ($insertManyResult->getInsertedIds() as $id) {
$this->assertInstanceOf(\MongoDB\BSON\ObjectId::class, $id); $this->assertInstanceOf(ObjectId::class, $id);
} }
$this->assertInventoryCount(3); $this->assertInventoryCount(3);
} }
...@@ -139,7 +143,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -139,7 +143,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
$this->assertSame(5, $insertManyResult->getInsertedCount()); $this->assertSame(5, $insertManyResult->getInsertedCount());
foreach ($insertManyResult->getInsertedIds() as $id) { foreach ($insertManyResult->getInsertedIds() as $id) {
$this->assertInstanceOf(\MongoDB\BSON\ObjectId::class, $id); $this->assertInstanceOf(ObjectId::class, $id);
} }
$this->assertInventoryCount(5); $this->assertInventoryCount(5);
...@@ -242,7 +246,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -242,7 +246,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
$this->assertSame(5, $insertManyResult->getInsertedCount()); $this->assertSame(5, $insertManyResult->getInsertedCount());
foreach ($insertManyResult->getInsertedIds() as $id) { foreach ($insertManyResult->getInsertedIds() as $id) {
$this->assertInstanceOf(\MongoDB\BSON\ObjectId::class, $id); $this->assertInstanceOf(ObjectId::class, $id);
} }
$this->assertInventoryCount(5); $this->assertInventoryCount(5);
...@@ -322,7 +326,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -322,7 +326,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
$this->assertSame(5, $insertManyResult->getInsertedCount()); $this->assertSame(5, $insertManyResult->getInsertedCount());
foreach ($insertManyResult->getInsertedIds() as $id) { foreach ($insertManyResult->getInsertedIds() as $id) {
$this->assertInstanceOf(\MongoDB\BSON\ObjectId::class, $id); $this->assertInstanceOf(ObjectId::class, $id);
} }
$this->assertInventoryCount(5); $this->assertInventoryCount(5);
...@@ -432,7 +436,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -432,7 +436,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
$this->assertSame(5, $insertManyResult->getInsertedCount()); $this->assertSame(5, $insertManyResult->getInsertedCount());
foreach ($insertManyResult->getInsertedIds() as $id) { foreach ($insertManyResult->getInsertedIds() as $id) {
$this->assertInstanceOf(\MongoDB\BSON\ObjectId::class, $id); $this->assertInstanceOf(ObjectId::class, $id);
} }
$this->assertInventoryCount(5); $this->assertInventoryCount(5);
...@@ -573,7 +577,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -573,7 +577,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
$this->assertSame(5, $insertManyResult->getInsertedCount()); $this->assertSame(5, $insertManyResult->getInsertedCount());
foreach ($insertManyResult->getInsertedIds() as $id) { foreach ($insertManyResult->getInsertedIds() as $id) {
$this->assertInstanceOf(\MongoDB\BSON\ObjectId::class, $id); $this->assertInstanceOf(ObjectId::class, $id);
} }
$this->assertInventoryCount(5); $this->assertInventoryCount(5);
...@@ -789,7 +793,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -789,7 +793,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
$this->assertSame(10, $insertManyResult->getInsertedCount()); $this->assertSame(10, $insertManyResult->getInsertedCount());
foreach ($insertManyResult->getInsertedIds() as $id) { foreach ($insertManyResult->getInsertedIds() as $id) {
$this->assertInstanceOf(\MongoDB\BSON\ObjectId::class, $id); $this->assertInstanceOf(ObjectId::class, $id);
} }
$this->assertInventoryCount(10); $this->assertInventoryCount(10);
...@@ -899,7 +903,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -899,7 +903,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
$this->assertSame(5, $insertManyResult->getInsertedCount()); $this->assertSame(5, $insertManyResult->getInsertedCount());
foreach ($insertManyResult->getInsertedIds() as $id) { foreach ($insertManyResult->getInsertedIds() as $id) {
$this->assertInstanceOf(\MongoDB\BSON\ObjectId::class, $id); $this->assertInstanceOf(ObjectId::class, $id);
} }
$this->assertInventoryCount(5); $this->assertInventoryCount(5);
...@@ -949,6 +953,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -949,6 +953,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
$this->assertNull($firstChange); $this->assertNull($firstChange);
$this->assertNull($secondChange); $this->assertNull($secondChange);
// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
// Start Changestream Example 2 // Start Changestream Example 2
$changeStream = $db->inventory->watch([], ['fullDocument' => \MongoDB\Operation\Watch::FULL_DOCUMENT_UPDATE_LOOKUP]); $changeStream = $db->inventory->watch([], ['fullDocument' => \MongoDB\Operation\Watch::FULL_DOCUMENT_UPDATE_LOOKUP]);
$changeStream->rewind(); $changeStream->rewind();
...@@ -959,6 +964,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -959,6 +964,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
$secondChange = $changeStream->current(); $secondChange = $changeStream->current();
// End Changestream Example 2 // End Changestream Example 2
// phpcs:enable
$this->assertNull($firstChange); $this->assertNull($firstChange);
$this->assertNull($secondChange); $this->assertNull($secondChange);
...@@ -983,6 +989,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -983,6 +989,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
$this->assertMatchesDocument($expectedChange, $lastChange); $this->assertMatchesDocument($expectedChange, $lastChange);
// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
// Start Changestream Example 3 // Start Changestream Example 3
$resumeToken = $changeStream->getResumeToken(); $resumeToken = $changeStream->getResumeToken();
...@@ -995,6 +1002,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -995,6 +1002,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
$firstChange = $changeStream->current(); $firstChange = $changeStream->current();
// End Changestream Example 3 // End Changestream Example 3
// phpcs:enable
$expectedChange = [ $expectedChange = [
'_id' => $firstChange->_id, '_id' => $firstChange->_id,
...@@ -1036,7 +1044,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1036,7 +1044,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
]); ]);
// End Aggregation Example 1 // End Aggregation Example 1
$this->assertInstanceOf(\MongoDB\Driver\Cursor::class, $cursor); $this->assertInstanceOf(Cursor::class, $cursor);
} }
public function testAggregation_example_2() public function testAggregation_example_2()
...@@ -1048,21 +1056,23 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1048,21 +1056,23 @@ class DocumentationExamplesTest extends FunctionalTestCase
['$unwind' => '$items'], ['$unwind' => '$items'],
['$match' => ['items.fruit' => 'banana']], ['$match' => ['items.fruit' => 'banana']],
[ [
'$group' => ['_id' => ['day' => ['$dayOfWeek' => '$date']], '$group' => [
'count' => ['$sum' => '$items.quantity']], '_id' => ['day' => ['$dayOfWeek' => '$date']],
'count' => ['$sum' => '$items.quantity'],
],
], ],
[ [
'$project' => [ '$project' => [
'dayOfWeek' => '$_id.day', 'dayOfWeek' => '$_id.day',
'numberSold' => '$count', 'numberSold' => '$count',
'_id' => 0, '_id' => 0,
] ],
], ],
['$sort' => ['numberSold' => 1]], ['$sort' => ['numberSold' => 1]],
]); ]);
// End Aggregation Example 2 // End Aggregation Example 2
$this->assertInstanceOf(\MongoDB\Driver\Cursor::class, $cursor); $this->assertInstanceOf(Cursor::class, $cursor);
} }
public function testAggregation_example_3() public function testAggregation_example_3()
...@@ -1072,16 +1082,19 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1072,16 +1082,19 @@ class DocumentationExamplesTest extends FunctionalTestCase
// Start Aggregation Example 3 // Start Aggregation Example 3
$cursor = $db->sales->aggregate([ $cursor = $db->sales->aggregate([
['$unwind' => '$items'], ['$unwind' => '$items'],
['$group' => [ [
'$group' => [
'_id' => ['day' => ['$dayOfWeek' => '$date']], '_id' => ['day' => ['$dayOfWeek' => '$date']],
'items_sold' => ['$sum' => '$items.quantity'], 'items_sold' => ['$sum' => '$items.quantity'],
'revenue' => [ 'revenue' => [
'$sum' => [ '$sum' => [
'$multiply' => ['$items.quantity', '$items.price'] '$multiply' => ['$items.quantity', '$items.price'],
]
], ],
]], ],
['$project' => [ ],
],
[
'$project' => [
'day' => '$_id.day', 'day' => '$_id.day',
'revenue' => 1, 'revenue' => 1,
'items_sold' => 1, 'items_sold' => 1,
...@@ -1090,13 +1103,14 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1090,13 +1103,14 @@ class DocumentationExamplesTest extends FunctionalTestCase
'if' => ['$lte' => ['$revenue', 250]], 'if' => ['$lte' => ['$revenue', 250]],
'then' => 25, 'then' => 25,
'else' => 0, 'else' => 0,
]
], ],
]], ],
],
],
]); ]);
// End Aggregation Example 3 // End Aggregation Example 3
$this->assertInstanceOf(\MongoDB\Driver\Cursor::class, $cursor); $this->assertInstanceOf(Cursor::class, $cursor);
} }
public function testAggregation_example_4() public function testAggregation_example_4()
...@@ -1109,15 +1123,21 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1109,15 +1123,21 @@ class DocumentationExamplesTest extends FunctionalTestCase
// Start Aggregation Example 4 // Start Aggregation Example 4
$cursor = $db->air_alliances->aggregate([ $cursor = $db->air_alliances->aggregate([
['$lookup' => [ [
'$lookup' => [
'from' => 'air_airlines', 'from' => 'air_airlines',
'let' => ['constituents' => '$airlines'], 'let' => ['constituents' => '$airlines'],
'pipeline' => [['$match' => [ 'pipeline' => [[
'$expr' => ['$in' => ['$name', '$constituents']] '$match' => [
]]], '$expr' => ['$in' => ['$name', '$constituents']],
],
],
],
'as' => 'airlines', 'as' => 'airlines',
]], ],
['$project' => [ ],
[
'$project' => [
'_id' => 0, '_id' => 0,
'name' => 1, 'name' => 1,
'airlines' => [ 'airlines' => [
...@@ -1125,13 +1145,14 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1125,13 +1145,14 @@ class DocumentationExamplesTest extends FunctionalTestCase
'input' => '$airlines', 'input' => '$airlines',
'as' => 'airline', 'as' => 'airline',
'cond' => ['$eq' => ['$$airline.country', 'Canada']], 'cond' => ['$eq' => ['$$airline.country', 'Canada']],
]
], ],
]], ],
],
],
]); ]);
// End Aggregation Example 4 // End Aggregation Example 4
$this->assertInstanceOf(\MongoDB\Driver\Cursor::class, $cursor); $this->assertInstanceOf(Cursor::class, $cursor);
} }
public function testRunCommand_example_1() public function testRunCommand_example_1()
...@@ -1143,7 +1164,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1143,7 +1164,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
$result = $cursor->toArray()[0]; $result = $cursor->toArray()[0];
// End runCommand Example 1 // End runCommand Example 1
$this->assertInstanceOf(\MongoDB\Driver\Cursor::class, $cursor); $this->assertInstanceOf(Cursor::class, $cursor);
} }
public function testRunCommand_example_2() public function testRunCommand_example_2()
...@@ -1157,7 +1178,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1157,7 +1178,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
$result = $cursor->toArray()[0]; $result = $cursor->toArray()[0];
// End runCommand Example 2 // End runCommand Example 2
$this->assertInstanceOf(\MongoDB\Driver\Cursor::class, $cursor); $this->assertInstanceOf(Cursor::class, $cursor);
} }
public function testIndex_example_1() public function testIndex_example_1()
...@@ -1185,12 +1206,15 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1185,12 +1206,15 @@ class DocumentationExamplesTest extends FunctionalTestCase
$this->assertEquals('cuisine_1_name_1', $indexName); $this->assertEquals('cuisine_1_name_1', $indexName);
} }
// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
// phpcs:disable Squiz.Commenting.FunctionComment.WrongStyle
// phpcs:disable Squiz.WhiteSpace.FunctionSpacing.After
// Start Transactions Intro Example 1 // Start Transactions Intro Example 1
private function updateEmployeeInfo1(\MongoDB\Client $client, \MongoDB\Driver\Session $session) private function updateEmployeeInfo1(\MongoDB\Client $client, \MongoDB\Driver\Session $session)
{ {
$session->startTransaction([ $session->startTransaction([
'readConcern' => new \MongoDB\Driver\ReadConcern('snapshot'), 'readConcern' => new \MongoDB\Driver\ReadConcern('snapshot'),
'writeConcern' => new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY) 'writeConcern' => new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY),
]); ]);
try { try {
...@@ -1231,6 +1255,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1231,6 +1255,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
} }
} }
// End Transactions Intro Example 1 // End Transactions Intro Example 1
// phpcs:enable
public function testTransactions_intro_example_1() public function testTransactions_intro_example_1()
{ {
...@@ -1241,12 +1266,12 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1241,12 +1266,12 @@ class DocumentationExamplesTest extends FunctionalTestCase
$client = new Client(static::getUri()); $client = new Client(static::getUri());
/* The WC is required: https://docs.mongodb.com/manual/core/transactions/#transactions-and-locks */ /* The WC is required: https://docs.mongodb.com/manual/core/transactions/#transactions-and-locks */
$client->hr->dropCollection('employees', ['writeConcern' => new \MongoDB\Driver\WriteConcern('majority')]); $client->hr->dropCollection('employees', ['writeConcern' => new WriteConcern('majority')]);
$client->reporting->dropCollection('events', ['writeConcern' => new \MongoDB\Driver\WriteConcern('majority')]); $client->reporting->dropCollection('events', ['writeConcern' => new WriteConcern('majority')]);
/* Collections need to be created before a transaction starts */ /* Collections need to be created before a transaction starts */
$client->hr->createCollection('employees', ['writeConcern' => new \MongoDB\Driver\WriteConcern('majority')]); $client->hr->createCollection('employees', ['writeConcern' => new WriteConcern('majority')]);
$client->reporting->createCollection('events', ['writeConcern' => new \MongoDB\Driver\WriteConcern('majority')]); $client->reporting->createCollection('events', ['writeConcern' => new WriteConcern('majority')]);
$session = $client->startSession(); $session = $client->startSession();
...@@ -1258,6 +1283,9 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1258,6 +1283,9 @@ class DocumentationExamplesTest extends FunctionalTestCase
} }
} }
// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
// phpcs:disable Squiz.Commenting.FunctionComment.WrongStyle
// phpcs:disable Squiz.WhiteSpace.FunctionSpacing.After
// Start Transactions Retry Example 1 // Start Transactions Retry Example 1
private function runTransactionWithRetry1(callable $txnFunc, \MongoDB\Client $client, \MongoDB\Driver\Session $session) private function runTransactionWithRetry1(callable $txnFunc, \MongoDB\Client $client, \MongoDB\Driver\Session $session)
{ {
...@@ -1282,7 +1310,11 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1282,7 +1310,11 @@ class DocumentationExamplesTest extends FunctionalTestCase
} }
} }
// End Transactions Retry Example 1 // End Transactions Retry Example 1
// phpcs:enable
// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
// phpcs:disable Squiz.Commenting.FunctionComment.WrongStyle
// phpcs:disable Squiz.WhiteSpace.FunctionSpacing.After
// Start Transactions Retry Example 2 // Start Transactions Retry Example 2
private function commitWithRetry2(\MongoDB\Driver\Session $session) private function commitWithRetry2(\MongoDB\Driver\Session $session)
{ {
...@@ -1308,7 +1340,11 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1308,7 +1340,11 @@ class DocumentationExamplesTest extends FunctionalTestCase
} }
} }
// End Transactions Retry Example 2 // End Transactions Retry Example 2
// phpcs:enable
// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
// phpcs:disable Squiz.Commenting.FunctionComment.WrongStyle
// phpcs:disable Squiz.WhiteSpace.FunctionSpacing.After
// Start Transactions Retry Example 3 // Start Transactions Retry Example 3
private function runTransactionWithRetry3(callable $txnFunc, \MongoDB\Client $client, \MongoDB\Driver\Session $session) private function runTransactionWithRetry3(callable $txnFunc, \MongoDB\Client $client, \MongoDB\Driver\Session $session)
{ {
...@@ -1394,6 +1430,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1394,6 +1430,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
} }
} }
// End Transactions Retry Example 3 // End Transactions Retry Example 3
// phpcs:enable
public function testTransactions_retry_example_3() public function testTransactions_retry_example_3()
{ {
...@@ -1404,12 +1441,12 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1404,12 +1441,12 @@ class DocumentationExamplesTest extends FunctionalTestCase
$client = new Client(static::getUri()); $client = new Client(static::getUri());
/* The WC is required: https://docs.mongodb.com/manual/core/transactions/#transactions-and-locks */ /* The WC is required: https://docs.mongodb.com/manual/core/transactions/#transactions-and-locks */
$client->hr->dropCollection('employees', ['writeConcern' => new \MongoDB\Driver\WriteConcern('majority')]); $client->hr->dropCollection('employees', ['writeConcern' => new WriteConcern('majority')]);
$client->reporting->dropCollection('events', ['writeConcern' => new \MongoDB\Driver\WriteConcern('majority')]); $client->reporting->dropCollection('events', ['writeConcern' => new WriteConcern('majority')]);
/* Collections need to be created before a transaction starts */ /* Collections need to be created before a transaction starts */
$client->hr->createCollection('employees', ['writeConcern' => new \MongoDB\Driver\WriteConcern('majority')]); $client->hr->createCollection('employees', ['writeConcern' => new WriteConcern('majority')]);
$client->reporting->createCollection('events', ['writeConcern' => new \MongoDB\Driver\WriteConcern('majority')]); $client->reporting->createCollection('events', ['writeConcern' => new WriteConcern('majority')]);
ob_start(); ob_start();
try { try {
...@@ -1419,7 +1456,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1419,7 +1456,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
} }
} }
function testCausalConsistency() public function testCausalConsistency()
{ {
$this->skipIfCausalConsistencyIsNotSupported(); $this->skipIfCausalConsistencyIsNotSupported();
...@@ -1443,6 +1480,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1443,6 +1480,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
[ 'sku' => '111', 'name' => 'Peanuts', 'start' => new UTCDateTime() ] [ 'sku' => '111', 'name' => 'Peanuts', 'start' => new UTCDateTime() ]
); );
// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
// Start Causal Consistency Example 1 // Start Causal Consistency Example 1
$items = $client->selectDatabase( $items = $client->selectDatabase(
'test', 'test',
...@@ -1468,9 +1506,11 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1468,9 +1506,11 @@ class DocumentationExamplesTest extends FunctionalTestCase
[ 'session' => $s1 ] [ 'session' => $s1 ]
); );
// End Causal Consistency Example 1 // End Causal Consistency Example 1
// phpcs:enable
ob_start(); ob_start();
// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
// Start Causal Consistency Example 2 // Start Causal Consistency Example 2
$s2 = $client->startSession( $s2 = $client->startSession(
[ 'causalConsistency' => true ] [ 'causalConsistency' => true ]
...@@ -1483,7 +1523,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1483,7 +1523,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
[ [
'readPreference' => new \MongoDB\Driver\ReadPreference(\MongoDB\Driver\ReadPreference::RP_SECONDARY), 'readPreference' => new \MongoDB\Driver\ReadPreference(\MongoDB\Driver\ReadPreference::RP_SECONDARY),
'readConcern' => new \MongoDB\Driver\ReadConcern(\MongoDB\Driver\ReadConcern::MAJORITY), 'readConcern' => new \MongoDB\Driver\ReadConcern(\MongoDB\Driver\ReadConcern::MAJORITY),
'writeConcern' => new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY, 1000) 'writeConcern' => new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY, 1000),
] ]
)->items; )->items;
...@@ -1495,6 +1535,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1495,6 +1535,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
var_dump($item); var_dump($item);
} }
// End Causal Consistency Example 2 // End Causal Consistency Example 2
// phpcs:enable
ob_end_clean(); ob_end_clean();
} }
......
...@@ -175,7 +175,7 @@ final class Context ...@@ -175,7 +175,7 @@ final class Context
$options['readPreference'] = new ReadPreference($readPreference['mode']); $options['readPreference'] = new ReadPreference($readPreference['mode']);
} }
if (isset($options['writeConcern']) && !($options['writeConcern'] instanceof writeConcern)) { if (isset($options['writeConcern']) && ! ($options['writeConcern'] instanceof WriteConcern)) {
$writeConcern = (array) $options['writeConcern']; $writeConcern = (array) $options['writeConcern'];
$diff = array_diff_key($writeConcern, ['w' => 1, 'wtimeout' => 1, 'j' => 1]); $diff = array_diff_key($writeConcern, ['w' => 1, 'wtimeout' => 1, 'j' => 1]);
......
...@@ -139,7 +139,7 @@ final class ErrorExpectation ...@@ -139,7 +139,7 @@ final class ErrorExpectation
$this->assertCodeName($test, $actual); $this->assertCodeName($test, $actual);
} }
if (!empty($this->excludedLabels) or !empty($this->includedLabels)) { if (! empty($this->excludedLabels) || ! empty($this->includedLabels)) {
$test->assertInstanceOf(RuntimeException::class, $actual); $test->assertInstanceOf(RuntimeException::class, $actual);
foreach ($this->excludedLabels as $label) { foreach ($this->excludedLabels as $label) {
......
...@@ -179,7 +179,6 @@ final class Operation ...@@ -179,7 +179,6 @@ final class Operation
/** /**
* Executes the operation with a given context. * Executes the operation with a given context.
* *
* @param FunctionalTestCase $test Test instance
* @param Context $context Execution context * @param Context $context Execution context
* @return mixed * @return mixed
* @throws LogicException if the operation is unsupported * @throws LogicException if the operation is unsupported
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment