Skip to content

Commit cc60f0e

Browse files
committed
Remove usages of deprecated BSON functions
1 parent 1b4905e commit cc60f0e

File tree

6 files changed

+18
-34
lines changed

6 files changed

+18
-34
lines changed

lib/Doctrine/ODM/MongoDB/Mapping/Driver/AttributeDriver.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\Persistence\Mapping\ClassMetadata as PersistenceClassMetadata;
1616
use Doctrine\Persistence\Mapping\Driver\ColocatedMappingDriver;
1717
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
18+
use MongoDB\BSON\Document;
1819
use MongoDB\Driver\Exception\UnexpectedValueException;
1920
use ReflectionClass;
2021
use ReflectionMethod;
@@ -27,8 +28,6 @@
2728
use function constant;
2829
use function count;
2930
use function is_array;
30-
use function MongoDB\BSON\fromJSON;
31-
use function MongoDB\BSON\toPHP;
3231
use function trigger_deprecation;
3332

3433
/**
@@ -133,12 +132,12 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
133132
} elseif ($attribute instanceof ODM\Validation) {
134133
if (isset($attribute->validator)) {
135134
try {
136-
$validatorBson = fromJSON($attribute->validator);
135+
$validatorBson = Document::fromJSON($attribute->validator);
137136
} catch (UnexpectedValueException $e) {
138137
throw MappingException::schemaValidationError($e->getCode(), $e->getMessage(), $className, 'validator');
139138
}
140139

141-
$validator = toPHP($validatorBson, []);
140+
$validator = $validatorBson->toPHP();
142141
$metadata->setValidator($validator);
143142
}
144143

lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use DOMDocument;
1212
use InvalidArgumentException;
1313
use LibXMLError;
14+
use MongoDB\BSON\Document;
1415
use MongoDB\Driver\Exception\UnexpectedValueException;
1516
use SimpleXMLElement;
1617

@@ -31,8 +32,6 @@
3132
use function libxml_clear_errors;
3233
use function libxml_get_errors;
3334
use function libxml_use_internal_errors;
34-
use function MongoDB\BSON\fromJSON;
35-
use function MongoDB\BSON\toPHP;
3635
use function next;
3736
use function preg_match;
3837
use function simplexml_load_file;
@@ -215,12 +214,12 @@ public function loadMetadataForClass($className, \Doctrine\Persistence\Mapping\C
215214

216215
$validatorJson = (string) $xmlSchemaValidation;
217216
try {
218-
$validatorBson = fromJSON($validatorJson);
217+
$validatorBson = Document::fromJSON($validatorJson);
219218
} catch (UnexpectedValueException $e) {
220219
throw MappingException::schemaValidationError($e->getCode(), $e->getMessage(), $className, 'schema-validation');
221220
}
222221

223-
$validator = toPHP($validatorBson, []);
222+
$validator = $validatorBson->toPHP();
224223
$metadata->setValidator($validator);
225224
}
226225

tests/Doctrine/ODM/MongoDB/Tests/Functional/ValidationTest.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
99
use Doctrine\ODM\MongoDB\Tests\BaseTestCase;
1010
use Documents\SchemaValidated;
11-
12-
use function MongoDB\BSON\fromJSON;
13-
use function MongoDB\BSON\fromPHP;
14-
use function MongoDB\BSON\toCanonicalExtendedJSON;
15-
use function MongoDB\BSON\toPHP;
11+
use MongoDB\BSON\Document;
1612

1713
class ValidationTest extends BaseTestCase
1814
{
@@ -41,15 +37,13 @@ public function testCreateUpdateValidatedDocument(): void
4137
]
4238
}
4339
EOT;
44-
$expectedValidatorBson = fromJSON($expectedValidatorJson);
45-
$expectedValidator = toPHP($expectedValidatorBson, []);
40+
$expectedValidator = Document::fromJSON($expectedValidatorJson)->toPHP();
4641
$expectedOptions = [
4742
'validator' => $expectedValidator,
4843
'validationLevel' => ClassMetadata::SCHEMA_VALIDATION_LEVEL_MODERATE,
4944
'validationAction' => ClassMetadata::SCHEMA_VALIDATION_ACTION_WARN,
5045
];
51-
$expectedOptionsBson = fromPHP($expectedOptions);
52-
$expectedOptionsJson = toCanonicalExtendedJSON($expectedOptionsBson);
46+
$expectedOptionsJson = Document::fromPHP($expectedOptions)->toCanonicalExtendedJSON();
5347
$collections = $this->dm->getDocumentDatabase($cm->name)->listCollections();
5448
$assertNb = 0;
5549
foreach ($collections as $collection) {
@@ -58,8 +52,7 @@ public function testCreateUpdateValidatedDocument(): void
5852
}
5953

6054
$assertNb++;
61-
$collectionOptionsBson = fromPHP($collection->getOptions());
62-
$collectionOptionsJson = toCanonicalExtendedJSON($collectionOptionsBson);
55+
$collectionOptionsJson = Document::fromPHP($collection->getOptions())->toCanonicalExtendedJSON();
6356
self::assertJsonStringEqualsJsonString($expectedOptionsJson, $collectionOptionsJson);
6457
}
6558

tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,14 @@
3535
use Documents\UserTyped;
3636
use Generator;
3737
use InvalidArgumentException;
38+
use MongoDB\BSON\Document;
3839
use PHPUnit\Framework\Attributes\DataProvider;
3940
use ProxyManager\Proxy\GhostObjectInterface;
4041
use ReflectionClass;
4142
use ReflectionException;
4243
use stdClass;
4344

4445
use function array_merge;
45-
use function MongoDB\BSON\fromJSON;
46-
use function MongoDB\BSON\toPHP;
4746
use function serialize;
4847
use function unserialize;
4948

@@ -78,7 +77,7 @@ public function testClassMetadataInstanceSerialization(): void
7877
$cm->setVersioned(true);
7978
$cm->setVersionField('version');
8079
$validatorJson = '{ "$and": [ { "email": { "$regularExpression" : { "pattern": "@mongodb\\\\.com$", "options": "" } } } ] }';
81-
$cm->setValidator(toPHP(fromJSON($validatorJson)));
80+
$cm->setValidator(Document::fromJSON($validatorJson)->toPHP());
8281
$cm->setValidationAction(ClassMetadata::SCHEMA_VALIDATION_ACTION_WARN);
8382
$cm->setValidationLevel(ClassMetadata::SCHEMA_VALIDATION_LEVEL_OFF);
8483
self::assertIsArray($cm->getFieldMapping('phonenumbers'));
@@ -110,7 +109,7 @@ public function testClassMetadataInstanceSerialization(): void
110109
self::assertEquals('lock', $cm->lockField);
111110
self::assertEquals(true, $cm->isVersioned);
112111
self::assertEquals('version', $cm->versionField);
113-
self::assertEquals(toPHP(fromJSON($validatorJson)), $cm->getValidator());
112+
self::assertEquals(Document::fromJSON($validatorJson)->toPHP(), $cm->getValidator());
114113
self::assertEquals(ClassMetadata::SCHEMA_VALIDATION_ACTION_WARN, $cm->getValidationAction());
115114
self::assertEquals(ClassMetadata::SCHEMA_VALIDATION_LEVEL_OFF, $cm->getValidationLevel());
116115
}

tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/XmlDriverTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
88
use Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver;
99
use Doctrine\ODM\MongoDB\Mapping\MappingException;
10+
use MongoDB\BSON\Document;
1011
use TestDocuments\AlsoLoadDocument;
1112
use TestDocuments\CustomIdGenerator;
1213
use TestDocuments\InvalidPartialFilterDocument;
@@ -16,9 +17,6 @@
1617
use TestDocuments\UserNonStringOptions;
1718
use TestDocuments\WildcardIndexDocument;
1819

19-
use function MongoDB\BSON\fromJSON;
20-
use function MongoDB\BSON\toPHP;
21-
2220
class XmlDriverTest extends AbstractDriverTestCase
2321
{
2422
public function setUp(): void
@@ -137,8 +135,7 @@ public function testValidationMapping(): void
137135
]
138136
}
139137
EOT;
140-
$expectedValidatorBson = fromJSON($expectedValidatorJson);
141-
$expectedValidator = toPHP($expectedValidatorBson, []);
138+
$expectedValidator = Document::fromJSON($expectedValidatorJson)->toPHP();
142139
self::assertEquals($expectedValidator, $classMetadata->getValidator());
143140
}
144141

tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Documents\Tournament\Tournament;
2424
use Documents\UserName;
2525
use InvalidArgumentException;
26+
use MongoDB\BSON\Document;
2627
use MongoDB\Client;
2728
use MongoDB\Collection;
2829
use MongoDB\Database;
@@ -43,8 +44,6 @@
4344
use function array_map;
4445
use function assert;
4546
use function in_array;
46-
use function MongoDB\BSON\fromJSON;
47-
use function MongoDB\BSON\toPHP;
4847

4948
/**
5049
* @psalm-import-type IndexMapping from ClassMetadata
@@ -601,8 +600,7 @@ public function testUpdateDocumentValidator(array $expectedWriteOptions, ?int $m
601600
]
602601
}
603602
EOT;
604-
$expectedValidatorBson = fromJSON($expectedValidatorJson);
605-
$expectedValidator = toPHP($expectedValidatorBson, []);
603+
$expectedValidator = Document::fromJSON($expectedValidatorJson)->toPHP();
606604
$database
607605
->expects($this->once())
608606
->method('command')
@@ -707,8 +705,7 @@ public function testCreateDocumentCollectionWithValidator(array $expectedWriteOp
707705
]
708706
}
709707
EOT;
710-
$expectedValidatorBson = fromJSON($expectedValidatorJson);
711-
$expectedValidator = toPHP($expectedValidatorBson, []);
708+
$expectedValidator = Document::fromJSON($expectedValidatorJson)->toPHP();
712709
$options = [
713710
'capped' => false,
714711
'size' => null,

0 commit comments

Comments
 (0)