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
...@@ -71,19 +75,19 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -71,19 +75,19 @@ class DocumentationExamplesTest extends FunctionalTestCase
// Start Example 3 // Start Example 3
$insertManyResult = $db->inventory->insertMany([ $insertManyResult = $db->inventory->insertMany([
[ [
'item' => 'journal', 'item' => 'journal',
'qty' => 25, 'qty' => 25,
'tags' => ['blank', 'red'], 'tags' => ['blank', 'red'],
'size' => ['h' => 14, 'w' => 21, 'uom' => 'cm'], 'size' => ['h' => 14, 'w' => 21, 'uom' => 'cm'],
], ],
[ [
'item' => 'mat', 'item' => 'mat',
'qty' => 85, 'qty' => 85,
'tags' => ['gray'], 'tags' => ['gray'],
'size' => ['h' => 27.9, 'w' => 35.5, 'uom' => 'cm'], 'size' => ['h' => 27.9, 'w' => 35.5, 'uom' => 'cm'],
], ],
[ [
'item' => 'mousepad', 'item' => 'mousepad',
'qty' => 25, 'qty' => 25,
'tags' => ['gel', 'blue'], 'tags' => ['gel', 'blue'],
'size' => ['h' => 19, 'w' => 22.85, 'uom' => 'cm'], 'size' => ['h' => 19, 'w' => 22.85, 'uom' => 'cm'],
...@@ -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);
} }
...@@ -105,31 +109,31 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -105,31 +109,31 @@ class DocumentationExamplesTest extends FunctionalTestCase
// Start Example 6 // Start Example 6
$insertManyResult = $db->inventory->insertMany([ $insertManyResult = $db->inventory->insertMany([
[ [
'item' => 'journal', 'item' => 'journal',
'qty' => 25, 'qty' => 25,
'size' => ['h' => 14, 'w' => 21, 'uom' => 'cm'], 'size' => ['h' => 14, 'w' => 21, 'uom' => 'cm'],
'status' => 'A', 'status' => 'A',
], ],
[ [
'item' => 'notebook', 'item' => 'notebook',
'qty' => 50, 'qty' => 50,
'size' => ['h' => 8.5, 'w' => 11, 'uom' => 'in'], 'size' => ['h' => 8.5, 'w' => 11, 'uom' => 'in'],
'status' => 'A', 'status' => 'A',
], ],
[ [
'item' => 'paper', 'item' => 'paper',
'qty' => 100, 'qty' => 100,
'size' => ['h' => 8.5, 'w' => 11, 'uom' => 'in'], 'size' => ['h' => 8.5, 'w' => 11, 'uom' => 'in'],
'status' => 'D', 'status' => 'D',
], ],
[ [
'item' => 'planner', 'item' => 'planner',
'qty' => 75, 'qty' => 75,
'size' => ['h' => 22.85, 'w' => 30, 'uom' => 'cm'], 'size' => ['h' => 22.85, 'w' => 30, 'uom' => 'cm'],
'status' => 'D', 'status' => 'D',
], ],
[ [
'item' => 'postcard', 'item' => 'postcard',
'qty' => 45, 'qty' => 45,
'size' => ['h' => 10, 'w' => 15.25, 'uom' => 'cm'], 'size' => ['h' => 10, 'w' => 15.25, 'uom' => 'cm'],
'status' => 'A', 'status' => 'A',
...@@ -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);
...@@ -208,31 +212,31 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -208,31 +212,31 @@ class DocumentationExamplesTest extends FunctionalTestCase
// Start Example 14 // Start Example 14
$insertManyResult = $db->inventory->insertMany([ $insertManyResult = $db->inventory->insertMany([
[ [
'item' => 'journal', 'item' => 'journal',
'qty' => 25, 'qty' => 25,
'size' => ['h' => 14, 'w' => 21, 'uom' => 'cm'], 'size' => ['h' => 14, 'w' => 21, 'uom' => 'cm'],
'status' => 'A', 'status' => 'A',
], ],
[ [
'item' => 'notebook', 'item' => 'notebook',
'qty' => 50, 'qty' => 50,
'size' => ['h' => 8.5, 'w' => 11, 'uom' => 'in'], 'size' => ['h' => 8.5, 'w' => 11, 'uom' => 'in'],
'status' => 'A', 'status' => 'A',
], ],
[ [
'item' => 'paper', 'item' => 'paper',
'qty' => 100, 'qty' => 100,
'size' => ['h' => 8.5, 'w' => 11, 'uom' => 'in'], 'size' => ['h' => 8.5, 'w' => 11, 'uom' => 'in'],
'status' => 'D', 'status' => 'D',
], ],
[ [
'item' => 'planner', 'item' => 'planner',
'qty' => 75, 'qty' => 75,
'size' => ['h' => 22.85, 'w' => 30, 'uom' => 'cm'], 'size' => ['h' => 22.85, 'w' => 30, 'uom' => 'cm'],
'status' => 'D', 'status' => 'D',
], ],
[ [
'item' => 'postcard', 'item' => 'postcard',
'qty' => 45, 'qty' => 45,
'size' => ['h' => 10, 'w' => 15.25, 'uom' => 'cm'], 'size' => ['h' => 10, 'w' => 15.25, 'uom' => 'cm'],
'status' => 'A', 'status' => 'A',
...@@ -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);
...@@ -288,31 +292,31 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -288,31 +292,31 @@ class DocumentationExamplesTest extends FunctionalTestCase
// Start Example 20 // Start Example 20
$insertManyResult = $db->inventory->insertMany([ $insertManyResult = $db->inventory->insertMany([
[ [
'item' => 'journal', 'item' => 'journal',
'qty' => 25, 'qty' => 25,
'tags' => ['blank', 'red'], 'tags' => ['blank', 'red'],
'dim_cm' => [14, 21], 'dim_cm' => [14, 21],
], ],
[ [
'item' => 'notebook', 'item' => 'notebook',
'qty' => 50, 'qty' => 50,
'tags' => ['red', 'blank'], 'tags' => ['red', 'blank'],
'dim_cm' => [14, 21], 'dim_cm' => [14, 21],
], ],
[ [
'item' => 'paper', 'item' => 'paper',
'qty' => 100, 'qty' => 100,
'tags' => ['red', 'blank', 'plain'], 'tags' => ['red', 'blank', 'plain'],
'dim_cm' => [14, 21], 'dim_cm' => [14, 21],
], ],
[ [
'item' => 'planner', 'item' => 'planner',
'qty' => 75, 'qty' => 75,
'tags' => ['blank', 'red'], 'tags' => ['blank', 'red'],
'dim_cm' => [22.85, 30], 'dim_cm' => [22.85, 30],
], ],
[ [
'item' => 'postcard', 'item' => 'postcard',
'qty' => 45, 'qty' => 45,
'tags' => ['blue'], 'tags' => ['blue'],
'dim_cm' => [10, 15.25], 'dim_cm' => [10, 15.25],
...@@ -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);
...@@ -394,34 +398,34 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -394,34 +398,34 @@ class DocumentationExamplesTest extends FunctionalTestCase
// Start Example 29 // Start Example 29
$insertManyResult = $db->inventory->insertMany([ $insertManyResult = $db->inventory->insertMany([
[ [
'item' => 'journal', 'item' => 'journal',
'instock' => [ 'instock' => [
['warehouse' => 'A', 'qty' => 5], ['warehouse' => 'A', 'qty' => 5],
['warehouse' => 'C', 'qty' => 15], ['warehouse' => 'C', 'qty' => 15],
], ],
], ],
[ [
'item' => 'notebook', 'item' => 'notebook',
'instock' => [ 'instock' => [
['warehouse' => 'C', 'qty' => 5], ['warehouse' => 'C', 'qty' => 5],
], ],
], ],
[ [
'item' => 'paper', 'item' => 'paper',
'instock' => [ 'instock' => [
['warehouse' => 'A', 'qty' => 60], ['warehouse' => 'A', 'qty' => 60],
['warehouse' => 'B', 'qty' => 15], ['warehouse' => 'B', 'qty' => 15],
], ],
], ],
[ [
'item' => 'planner', 'item' => 'planner',
'instock' => [ 'instock' => [
['warehouse' => 'A', 'qty' => 40], ['warehouse' => 'A', 'qty' => 40],
['warehouse' => 'B', 'qty' => 5], ['warehouse' => 'B', 'qty' => 5],
], ],
], ],
[ [
'item' => 'postcard', 'item' => 'postcard',
'instock' => [ 'instock' => [
['warehouse' => 'B', 'qty' => 15], ['warehouse' => 'B', 'qty' => 15],
['warehouse' => 'C', 'qty' => 35], ['warehouse' => 'C', 'qty' => 35],
...@@ -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,31 +1082,35 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1072,31 +1082,35 @@ 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' => [ [
'_id' => ['day' => ['$dayOfWeek' => '$date']], '$group' => [
'items_sold' => ['$sum' => '$items.quantity'], '_id' => ['day' => ['$dayOfWeek' => '$date']],
'revenue' => [ 'items_sold' => ['$sum' => '$items.quantity'],
'$sum' => [ 'revenue' => [
'$multiply' => ['$items.quantity', '$items.price'] '$sum' => [
] '$multiply' => ['$items.quantity', '$items.price'],
],
],
], ],
]], ],
['$project' => [ [
'day' => '$_id.day', '$project' => [
'revenue' => 1, 'day' => '$_id.day',
'items_sold' => 1, 'revenue' => 1,
'discount' => [ 'items_sold' => 1,
'$cond' => [ 'discount' => [
'if' => ['$lte' => ['$revenue', 250]], '$cond' => [
'then' => 25, 'if' => ['$lte' => ['$revenue', 250]],
'else' => 0, 'then' => 25,
] '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,29 +1123,36 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1109,29 +1123,36 @@ class DocumentationExamplesTest extends FunctionalTestCase
// Start Aggregation Example 4 // Start Aggregation Example 4
$cursor = $db->air_alliances->aggregate([ $cursor = $db->air_alliances->aggregate([
['$lookup' => [ [
'from' => 'air_airlines', '$lookup' => [
'let' => ['constituents' => '$airlines'], 'from' => 'air_airlines',
'pipeline' => [['$match' => [ 'let' => ['constituents' => '$airlines'],
'$expr' => ['$in' => ['$name', '$constituents']] 'pipeline' => [[
]]], '$match' => [
'as' => 'airlines', '$expr' => ['$in' => ['$name', '$constituents']],
]], ],
['$project' => [ ],
'_id' => 0, ],
'name' => 1, 'as' => 'airlines',
'airlines' => [ ],
'$filter' => [ ],
'input' => '$airlines', [
'as' => 'airline', '$project' => [
'cond' => ['$eq' => ['$$airline.country', 'Canada']], '_id' => 0,
] 'name' => 1,
'airlines' => [
'$filter' => [
'input' => '$airlines',
'as' => 'airline',
'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();
} }
......
...@@ -85,7 +85,7 @@ final class Context ...@@ -85,7 +85,7 @@ final class Context
// TODO: Remove this once retryWrites=true by default (see: PHPC-1324) // TODO: Remove this once retryWrites=true by default (see: PHPC-1324)
$clientOptions['retryWrites'] = true; $clientOptions['retryWrites'] = true;
if (isset($test->outcome->collection->name)) { if (isset($test->outcome->collection->name)) {
$o->outcomeCollectionName = $test->outcome->collection->name; $o->outcomeCollectionName = $test->outcome->collection->name;
} }
...@@ -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,8 +179,7 @@ final class Operation ...@@ -179,8 +179,7 @@ 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