diff --git a/docs/tutorial/custom-types.txt b/docs/tutorial/custom-types.txt index f3736675a..243d7e524 100644 --- a/docs/tutorial/custom-types.txt +++ b/docs/tutorial/custom-types.txt @@ -151,8 +151,8 @@ back to ``LocalDateTime``. .. code-block:: php new LocalDateTime]); - $document = MongoDB\BSON\toPHP($bson); + $bson = MongoDB\BSON\Document::fromPHP(['date' => new LocalDateTime]); + $document = $bson->toPHP(); var_dump($document); var_dump($document->date->toDateTime()); diff --git a/docs/tutorial/example-data.txt b/docs/tutorial/example-data.txt index d0b748cc3..30f80ff53 100644 --- a/docs/tutorial/example-data.txt +++ b/docs/tutorial/example-data.txt @@ -22,8 +22,8 @@ example imports the ``zips.json`` file into a ``test.zips`` collection using the $bulk = new MongoDB\Driver\BulkWrite; foreach ($lines as $line) { - $bson = MongoDB\BSON\fromJSON($line); - $document = MongoDB\BSON\toPHP($bson); + $bson = MongoDB\BSON\Document::fromJSON($line); + $document = $bson->toPHP(); $bulk->insert($document); } diff --git a/examples/aggregate.php b/examples/aggregate.php index 58ce7eb9e..6f3676e3c 100644 --- a/examples/aggregate.php +++ b/examples/aggregate.php @@ -3,13 +3,12 @@ namespace MongoDB\Examples\Aggregate; +use MongoDB\BSON\Document; use MongoDB\Client; use function assert; use function getenv; use function is_object; -use function MongoDB\BSON\fromPHP; -use function MongoDB\BSON\toRelaxedExtendedJSON; use function printf; use function random_int; @@ -17,7 +16,7 @@ function toJSON(object $document): string { - return toRelaxedExtendedJSON(fromPHP($document)); + return Document::fromPHP($document)->toRelaxedExtendedJSON(); } $client = new Client(getenv('MONGODB_URI') ?: 'mongodb://127.0.0.1/'); diff --git a/examples/bulk.php b/examples/bulk.php index f1ec98ab0..3c2a56cfe 100644 --- a/examples/bulk.php +++ b/examples/bulk.php @@ -3,21 +3,20 @@ namespace MongoDB\Examples\Bulk; +use MongoDB\BSON\Document; use MongoDB\Client; use MongoDB\Driver\WriteConcern; use function assert; use function getenv; use function is_object; -use function MongoDB\BSON\fromPHP; -use function MongoDB\BSON\toRelaxedExtendedJSON; use function printf; require __DIR__ . '/../vendor/autoload.php'; function toJSON(object $document): string { - return toRelaxedExtendedJSON(fromPHP($document)); + return Document::fromPHP($document)->toRelaxedExtendedJSON(); } $client = new Client(getenv('MONGODB_URI') ?: 'mongodb://127.0.0.1/'); diff --git a/examples/changestream.php b/examples/changestream.php index ed46a6e95..e653b0220 100644 --- a/examples/changestream.php +++ b/examples/changestream.php @@ -3,13 +3,12 @@ namespace MongoDB\Examples\ChangeStream; +use MongoDB\BSON\Document; use MongoDB\Client; use function assert; use function getenv; use function is_object; -use function MongoDB\BSON\fromPHP; -use function MongoDB\BSON\toRelaxedExtendedJSON; use function printf; use function time; @@ -17,7 +16,7 @@ function toJSON(object $document): string { - return toRelaxedExtendedJSON(fromPHP($document)); + return Document::fromPHP($document)->toRelaxedExtendedJSON(); } // Change streams require a replica set or sharded cluster diff --git a/examples/command_logger.php b/examples/command_logger.php index 790c09a67..7fd932dac 100644 --- a/examples/command_logger.php +++ b/examples/command_logger.php @@ -3,6 +3,7 @@ namespace MongoDB\Examples\CommandLogger; +use MongoDB\BSON\Document; use MongoDB\Client; use MongoDB\Driver\Monitoring\CommandFailedEvent; use MongoDB\Driver\Monitoring\CommandStartedEvent; @@ -13,15 +14,13 @@ use function get_class; use function getenv; use function is_object; -use function MongoDB\BSON\fromPHP; -use function MongoDB\BSON\toRelaxedExtendedJSON; use function printf; require __DIR__ . '/../vendor/autoload.php'; function toJSON(object $document): string { - return toRelaxedExtendedJSON(fromPHP($document)); + return Document::fromPHP($document)->toRelaxedExtendedJSON(); } class CommandLogger implements CommandSubscriber diff --git a/examples/sdam_logger.php b/examples/sdam_logger.php index 00762c63d..974e11dfb 100644 --- a/examples/sdam_logger.php +++ b/examples/sdam_logger.php @@ -3,6 +3,7 @@ namespace MongoDB\Examples; +use MongoDB\BSON\Document; use MongoDB\Client; use MongoDB\Driver\Monitoring\SDAMSubscriber; use MongoDB\Driver\Monitoring\ServerChangedEvent; @@ -17,8 +18,6 @@ use function get_class; use function getenv; -use function MongoDB\BSON\fromPHP; -use function MongoDB\BSON\toRelaxedExtendedJSON; use function printf; require __DIR__ . '/../vendor/autoload.php'; @@ -26,7 +25,7 @@ /** @param array|object $document */ function toJSON($document): string { - return toRelaxedExtendedJSON(fromPHP($document)); + return Document::fromPHP($document)->toRelaxedExtendedJSON(); } class SDAMLogger implements SDAMSubscriber diff --git a/examples/with_transaction.php b/examples/with_transaction.php index b9e4ab2dc..0b583ac6d 100644 --- a/examples/with_transaction.php +++ b/examples/with_transaction.php @@ -3,14 +3,13 @@ namespace MongoDB\Examples\WithTransaction; +use MongoDB\BSON\Document; use MongoDB\Client; use MongoDB\Driver\Session; use function assert; use function getenv; use function is_object; -use function MongoDB\BSON\fromPHP; -use function MongoDB\BSON\toRelaxedExtendedJSON; use function MongoDB\with_transaction; use function printf; @@ -18,7 +17,7 @@ function toJSON(object $document): string { - return toRelaxedExtendedJSON(fromPHP($document)); + return Document::fromPHP($document)->toRelaxedExtendedJSON(); } // Transactions require a replica set (MongoDB >= 4.0) or sharded cluster (MongoDB >= 4.2) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 0eac0407a..449892a64 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -135,19 +135,6 @@ stdClass - - - $documentLength - $documentLength - options['typeMap']]]> - - - position]]> - - - $documentLength - - cursor->nextBatch]]> diff --git a/src/GridFS/Bucket.php b/src/GridFS/Bucket.php index 5430f6f2c..8a7ef25b5 100644 --- a/src/GridFS/Bucket.php +++ b/src/GridFS/Bucket.php @@ -52,8 +52,6 @@ use function is_string; use function method_exists; use function MongoDB\apply_type_map_to_document; -use function MongoDB\BSON\fromPHP; -use function MongoDB\BSON\toJSON; use function property_exists; use function sprintf; use function str_contains; @@ -705,7 +703,7 @@ public function uploadFromStream(string $filename, $source, array $options = []) private function createPathForFile(object $file): string { if (is_array($file->_id) || (is_object($file->_id) && ! method_exists($file->_id, '__toString'))) { - $id = toJSON(fromPHP(['_id' => $file->_id])); + $id = Document::fromPHP(['_id' => $file->_id])->toRelaxedExtendedJSON(); } else { $id = (string) $file->_id; } diff --git a/src/GridFS/Exception/FileNotFoundException.php b/src/GridFS/Exception/FileNotFoundException.php index dbf8b08e1..9243db6f4 100644 --- a/src/GridFS/Exception/FileNotFoundException.php +++ b/src/GridFS/Exception/FileNotFoundException.php @@ -17,10 +17,9 @@ namespace MongoDB\GridFS\Exception; +use MongoDB\BSON\Document; use MongoDB\Exception\RuntimeException; -use function MongoDB\BSON\fromPHP; -use function MongoDB\BSON\toJSON; use function sprintf; class FileNotFoundException extends RuntimeException @@ -58,7 +57,7 @@ public static function byFilenameAndRevision(string $filename, int $revision, st */ public static function byId($id, string $namespace) { - $json = toJSON(fromPHP(['_id' => $id])); + $json = Document::fromPHP(['_id' => $id])->toRelaxedExtendedJSON(); return new self(sprintf('File "%s" not found in "%s"', $json, $namespace)); } diff --git a/src/GridFS/Exception/StreamException.php b/src/GridFS/Exception/StreamException.php index e60d8c23a..8dab6d668 100644 --- a/src/GridFS/Exception/StreamException.php +++ b/src/GridFS/Exception/StreamException.php @@ -2,10 +2,9 @@ namespace MongoDB\GridFS\Exception; +use MongoDB\BSON\Document; use MongoDB\Exception\RuntimeException; -use function MongoDB\BSON\fromPHP; -use function MongoDB\BSON\toJSON; use function sprintf; use function stream_get_meta_data; @@ -30,7 +29,7 @@ public static function downloadFromFilenameFailed(string $filename, $source, $de */ public static function downloadFromIdFailed($id, $source, $destination): self { - $idString = toJSON(fromPHP(['_id' => $id])); + $idString = Document::fromPHP(['_id' => $id])->toRelaxedExtendedJSON(); $sourceMetadata = stream_get_meta_data($source); $destinationMetadata = stream_get_meta_data($destination); diff --git a/src/Model/BSONIterator.php b/src/Model/BSONIterator.php index 3bf380a1d..43dae2ed2 100644 --- a/src/Model/BSONIterator.php +++ b/src/Model/BSONIterator.php @@ -18,12 +18,14 @@ namespace MongoDB\Model; use Iterator; +use MongoDB\BSON\Document; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\UnexpectedValueException; use ReturnTypeWillChange; +use function assert; use function is_array; -use function MongoDB\BSON\toPHP; +use function is_int; use function sprintf; use function strlen; use function substr; @@ -49,6 +51,7 @@ class BSONIterator implements Iterator private int $position = 0; + /** @var array{typeMap: array, ...} */ private array $options; /** @@ -142,12 +145,13 @@ private function advance(): void } [, $documentLength] = unpack('V', substr($this->buffer, $this->position, self::BSON_SIZE)); + assert(is_int($documentLength)); if ($this->bufferLength - $this->position < $documentLength) { throw new UnexpectedValueException(sprintf('Expected %d bytes; %d remaining', $documentLength, $this->bufferLength - $this->position)); } - $this->current = toPHP(substr($this->buffer, $this->position, $documentLength), $this->options['typeMap']); + $this->current = Document::fromBSON(substr($this->buffer, $this->position, $documentLength))->toPHP($this->options['typeMap']); $this->position += $documentLength; } } diff --git a/src/functions.php b/src/functions.php index bb7dfb23c..b3b5167e7 100644 --- a/src/functions.php +++ b/src/functions.php @@ -43,8 +43,6 @@ use function is_array; use function is_object; use function is_string; -use function MongoDB\BSON\fromPHP; -use function MongoDB\BSON\toPHP; use function str_ends_with; use function substr; @@ -115,7 +113,7 @@ function apply_type_map_to_document($document, array $typeMap) throw InvalidArgumentException::expectedDocumentType('$document', $document); } - return toPHP(fromPHP($document), $typeMap); + return Document::fromPHP($document)->toPHP($typeMap); } /** diff --git a/tests/Model/BSONIteratorTest.php b/tests/Model/BSONIteratorTest.php index efda8481d..ff1a8bd1c 100644 --- a/tests/Model/BSONIteratorTest.php +++ b/tests/Model/BSONIteratorTest.php @@ -2,6 +2,8 @@ namespace MongoDB\Tests\Model; +use Generator; +use MongoDB\BSON\Document; use MongoDB\Exception\UnexpectedValueException; use MongoDB\Model\BSONIterator; use MongoDB\Tests\TestCase; @@ -9,14 +11,21 @@ use function array_map; use function implode; use function iterator_to_array; -use function MongoDB\BSON\fromPHP; use function substr; class BSONIteratorTest extends TestCase { /** @dataProvider provideTypeMapOptionsAndExpectedDocuments */ - public function testValidValues(?array $typeMap, $binaryString, array $expectedDocuments): void + public function testValidValues(?array $typeMap, array $expectedDocuments): void { + $binaryString = implode(array_map( + fn ($input) => (string) Document::fromPHP($input), + [ + ['_id' => 1, 'x' => ['foo' => 'bar']], + ['_id' => 3, 'x' => ['foo' => 'bar']], + ], + )); + $bsonIt = new BSONIterator($binaryString, ['typeMap' => $typeMap]); $results = iterator_to_array($bsonIt); @@ -24,71 +33,44 @@ public function testValidValues(?array $typeMap, $binaryString, array $expectedD $this->assertEquals($expectedDocuments, $results); } - public function provideTypeMapOptionsAndExpectedDocuments() + public function provideTypeMapOptionsAndExpectedDocuments(): Generator { - return [ - [ - null, - implode(array_map( - 'MongoDB\BSON\fromPHP', - [ - ['_id' => 1, 'x' => ['foo' => 'bar']], - ['_id' => 3, 'x' => ['foo' => 'bar']], - ], - )), - [ - (object) ['_id' => 1, 'x' => (object) ['foo' => 'bar']], - (object) ['_id' => 3, 'x' => (object) ['foo' => 'bar']], - ], + yield 'No type map' => [ + 'typeMap' => null, + 'expectedDocuments' => [ + (object) ['_id' => 1, 'x' => (object) ['foo' => 'bar']], + (object) ['_id' => 3, 'x' => (object) ['foo' => 'bar']], ], - [ - ['root' => 'array', 'document' => 'array'], - implode(array_map( - 'MongoDB\BSON\fromPHP', - [ - ['_id' => 1, 'x' => ['foo' => 'bar']], - ['_id' => 3, 'x' => ['foo' => 'bar']], - ], - )), - [ - ['_id' => 1, 'x' => ['foo' => 'bar']], - ['_id' => 3, 'x' => ['foo' => 'bar']], - ], + ]; + + yield 'Array type map' => [ + 'typeMap' => ['root' => 'array', 'document' => 'array'], + 'expectedDocuments' => [ + ['_id' => 1, 'x' => ['foo' => 'bar']], + ['_id' => 3, 'x' => ['foo' => 'bar']], ], - [ - ['root' => 'object', 'document' => 'array'], - implode(array_map( - 'MongoDB\BSON\fromPHP', - [ - ['_id' => 1, 'x' => ['foo' => 'bar']], - ['_id' => 3, 'x' => ['foo' => 'bar']], - ], - )), - [ - (object) ['_id' => 1, 'x' => ['foo' => 'bar']], - (object) ['_id' => 3, 'x' => ['foo' => 'bar']], - ], + ]; + + yield 'Root as object' => [ + 'typeMap' => ['root' => 'object', 'document' => 'array'], + 'expectedDocuments' => [ + (object) ['_id' => 1, 'x' => ['foo' => 'bar']], + (object) ['_id' => 3, 'x' => ['foo' => 'bar']], ], - [ - ['root' => 'array', 'document' => 'stdClass'], - implode(array_map( - 'MongoDB\BSON\fromPHP', - [ - ['_id' => 1, 'x' => ['foo' => 'bar']], - ['_id' => 3, 'x' => ['foo' => 'bar']], - ], - )), - [ - ['_id' => 1, 'x' => (object) ['foo' => 'bar']], - ['_id' => 3, 'x' => (object) ['foo' => 'bar']], - ], + ]; + + yield 'Document as object' => [ + 'typeMap' => ['root' => 'array', 'document' => 'stdClass'], + 'expectedDocuments' => [ + ['_id' => 1, 'x' => (object) ['foo' => 'bar']], + ['_id' => 3, 'x' => (object) ['foo' => 'bar']], ], ]; } public function testCannotReadLengthFromFirstDocument(): void { - $binaryString = substr(fromPHP([]), 0, 3); + $binaryString = substr((string) Document::fromPHP([]), 0, 3); $bsonIt = new BSONIterator($binaryString); @@ -99,7 +81,7 @@ public function testCannotReadLengthFromFirstDocument(): void public function testCannotReadLengthFromSubsequentDocument(): void { - $binaryString = fromPHP([]) . substr(fromPHP([]), 0, 3); + $binaryString = (string) Document::fromPHP([]) . substr((string) Document::fromPHP([]), 0, 3); $bsonIt = new BSONIterator($binaryString); $bsonIt->rewind(); @@ -111,7 +93,7 @@ public function testCannotReadLengthFromSubsequentDocument(): void public function testCannotReadFirstDocument(): void { - $binaryString = substr(fromPHP([]), 0, 4); + $binaryString = substr((string) Document::fromPHP([]), 0, 4); $bsonIt = new BSONIterator($binaryString); @@ -122,7 +104,7 @@ public function testCannotReadFirstDocument(): void public function testCannotReadSecondDocument(): void { - $binaryString = fromPHP([]) . substr(fromPHP([]), 0, 4); + $binaryString = (string) Document::fromPHP([]) . substr((string) Document::fromPHP([]), 0, 4); $bsonIt = new BSONIterator($binaryString); $bsonIt->rewind(); diff --git a/tests/SpecTests/DocumentsMatchConstraintTest.php b/tests/SpecTests/DocumentsMatchConstraintTest.php index 8a238f272..f4959882d 100644 --- a/tests/SpecTests/DocumentsMatchConstraintTest.php +++ b/tests/SpecTests/DocumentsMatchConstraintTest.php @@ -4,6 +4,7 @@ use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; use MongoDB\BSON\Int64; use MongoDB\BSON\Javascript; use MongoDB\BSON\MaxKey; @@ -17,9 +18,6 @@ use MongoDB\Tests\TestCase; use PHPUnit\Framework\ExpectationFailedException; -use function MongoDB\BSON\fromJSON; -use function MongoDB\BSON\toPHP; - use const PHP_INT_SIZE; class DocumentsMatchConstraintTest extends TestCase @@ -82,9 +80,9 @@ public function testBSONTypeAssertions($type, $value): void public function provideBSONTypes() { - $undefined = toPHP(fromJSON('{ "x": {"$undefined": true} }'))->x; - $symbol = toPHP(fromJSON('{ "x": {"$symbol": "test"} }'))->x; - $dbPointer = toPHP(fromJSON('{ "x": {"$dbPointer": {"$ref": "db.coll", "$id" : { "$oid" : "5a2e78accd485d55b405ac12" } }} }'))->x; + $undefined = Document::fromJSON('{ "x": {"$undefined": true} }')->toPHP()->x; + $symbol = Document::fromJSON('{ "x": {"$symbol": "test"} }')->toPHP()->x; + $dbPointer = Document::fromJSON('{ "x": {"$dbPointer": {"$ref": "db.coll", "$id" : { "$oid" : "5a2e78accd485d55b405ac12" } }} }')->toPHP()->x; $int64 = new Int64(1); $long = PHP_INT_SIZE == 4 ? new Int64('4294967296') : 4_294_967_296; diff --git a/tests/SpecTests/FunctionalTestCase.php b/tests/SpecTests/FunctionalTestCase.php index 9a5ab4d6d..16fc999db 100644 --- a/tests/SpecTests/FunctionalTestCase.php +++ b/tests/SpecTests/FunctionalTestCase.php @@ -4,6 +4,7 @@ use ArrayIterator; use LogicException; +use MongoDB\BSON\Document; use MongoDB\Collection; use MongoDB\Driver\Server; use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase; @@ -14,8 +15,6 @@ use function in_array; use function json_encode; -use function MongoDB\BSON\fromJSON; -use function MongoDB\BSON\toPHP; use function sprintf; use function version_compare; @@ -179,7 +178,7 @@ protected function checkServerRequirements(array $runOn): void */ protected function decodeJson(string $json) { - return toPHP(fromJSON($json)); + return Document::fromJSON($json)->toPHP(); } /** diff --git a/tests/TestCase.php b/tests/TestCase.php index f349b47b5..8e2b0af7b 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,6 +3,7 @@ namespace MongoDB\Tests; use InvalidArgumentException; +use MongoDB\BSON\Document; use MongoDB\BSON\PackedArray; use MongoDB\Codec\Codec; use MongoDB\Driver\ReadConcern; @@ -27,8 +28,6 @@ use function is_object; use function is_string; use function iterator_to_array; -use function MongoDB\BSON\fromPHP; -use function MongoDB\BSON\toJSON; use function preg_match; use function preg_replace; use function restore_error_handler; @@ -115,8 +114,8 @@ public function assertMatchesDocument($expectedDocument, $actualDocument): void } $this->assertEquals( - toJSON(fromPHP($normalizedExpectedDocument)), - toJSON(fromPHP($normalizedActualDocument)), + Document::fromPHP($normalizedExpectedDocument)->toRelaxedExtendedJSON(), + Document::fromPHP($normalizedActualDocument)->toRelaxedExtendedJSON(), ); } @@ -132,8 +131,8 @@ public function assertMatchesDocument($expectedDocument, $actualDocument): void public function assertSameDocument($expectedDocument, $actualDocument): void { $this->assertEquals( - toJSON(fromPHP($this->normalizeBSON($expectedDocument))), - toJSON(fromPHP($this->normalizeBSON($actualDocument))), + Document::fromPHP($this->normalizeBSON($expectedDocument))->toRelaxedExtendedJSON(), + Document::fromPHP($this->normalizeBSON($actualDocument))->toRelaxedExtendedJSON(), ); } @@ -147,7 +146,7 @@ public function assertSameDocuments(array $expectedDocuments, $actualDocuments): throw new InvalidArgumentException('$actualDocuments is not an array or Traversable'); } - $normalizeRootDocuments = fn ($document) => toJSON(fromPHP($this->normalizeBSON($document))); + $normalizeRootDocuments = fn ($document) => Document::fromPHP($this->normalizeBSON($document))->toRelaxedExtendedJSON(); $this->assertEquals( array_map($normalizeRootDocuments, $expectedDocuments), diff --git a/tests/UnifiedSpecTests/Constraint/IsBsonTypeTest.php b/tests/UnifiedSpecTests/Constraint/IsBsonTypeTest.php index cdc371cb2..7300ecd1a 100644 --- a/tests/UnifiedSpecTests/Constraint/IsBsonTypeTest.php +++ b/tests/UnifiedSpecTests/Constraint/IsBsonTypeTest.php @@ -4,6 +4,7 @@ use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; use MongoDB\BSON\Int64; use MongoDB\BSON\Javascript; use MongoDB\BSON\MaxKey; @@ -21,8 +22,6 @@ use stdClass; use function fopen; -use function MongoDB\BSON\fromJSON; -use function MongoDB\BSON\toPHP; use const PHP_INT_SIZE; @@ -36,9 +35,9 @@ public function testConstraint($type, $value): void public function provideTypes() { - $undefined = toPHP(fromJSON('{ "x": {"$undefined": true} }'))->x; - $symbol = toPHP(fromJSON('{ "x": {"$symbol": "test"} }'))->x; - $dbPointer = toPHP(fromJSON('{ "x": {"$dbPointer": {"$ref": "db.coll", "$id" : { "$oid" : "5a2e78accd485d55b405ac12" } }} }'))->x; + $undefined = Document::fromJSON('{ "x": {"$undefined": true} }')->toPHP()->x; + $symbol = Document::fromJSON('{ "x": {"$symbol": "test"} }')->toPHP()->x; + $dbPointer = Document::fromJSON('{ "x": {"$dbPointer": {"$ref": "db.coll", "$id" : { "$oid" : "5a2e78accd485d55b405ac12" } }} }')->toPHP()->x; $int64 = new Int64(1); $long = PHP_INT_SIZE == 4 ? new Int64('4294967296') : 4_294_967_296; diff --git a/tests/UnifiedSpecTests/UnifiedTestCase.php b/tests/UnifiedSpecTests/UnifiedTestCase.php index 8a6e69aba..3df7e842e 100644 --- a/tests/UnifiedSpecTests/UnifiedTestCase.php +++ b/tests/UnifiedSpecTests/UnifiedTestCase.php @@ -4,12 +4,11 @@ use Generator; use IteratorAggregate; +use MongoDB\BSON\Document; use stdClass; use Traversable; use function file_get_contents; -use function MongoDB\BSON\fromJSON; -use function MongoDB\BSON\toPHP; use function PHPUnit\Framework\assertIsArray; use function PHPUnit\Framework\assertIsObject; use function PHPUnit\Framework\assertIsString; @@ -69,7 +68,7 @@ public static function fromFile(string $filename): Generator { /* Decode the file through the driver's extended JSON parser to ensure * proper handling of special types. */ - $json = toPHP(fromJSON(file_get_contents($filename))); + $json = Document::fromJSON(file_get_contents($filename))->toPHP(); yield from static::fromJSON($json); }