Skip to content

Commit bec87ea

Browse files
authored
Merge pull request #2602 from doctrine/2.6.x-merge-up-into-2.7.x_xIl3t7Dt
Merge release 2.6.2 into 2.7.x
2 parents 3171964 + a51bfc0 commit bec87ea

File tree

7 files changed

+44
-20
lines changed

7 files changed

+44
-20
lines changed

lib/Doctrine/ODM/MongoDB/DocumentManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ public function getDocumentBucket(string $className): Bucket
389389
if (! isset($this->documentBuckets[$className])) {
390390
$db = $this->getDocumentDatabase($className);
391391

392-
$options = ['bucketName' => $bucketName];
392+
$options = ['bucketName' => $bucketName, 'typeMap' => self::CLIENT_TYPEMAP];
393393
if ($metadata->readPreference !== null) {
394394
$options['readPreference'] = new ReadPreference($metadata->readPreference, $metadata->readPreferenceTags);
395395
}

lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@
5151
use function strtoupper;
5252
use function trigger_deprecation;
5353

54-
use const PHP_VERSION_ID;
55-
5654
/**
5755
* A <tt>ClassMetadata</tt> instance holds all the object-document mapping metadata
5856
* of a document and it's references.
@@ -2616,17 +2614,16 @@ private function validateAndCompleteTypedFieldMapping(array $mapping): array
26162614
return $mapping;
26172615
}
26182616

2619-
if (PHP_VERSION_ID >= 80100 && ! $type->isBuiltin() && enum_exists($type->getName())) {
2620-
$mapping['enumType'] = $type->getName();
2621-
2617+
if (! $type->isBuiltin() && enum_exists($type->getName())) {
26222618
$reflection = new ReflectionEnum($type->getName());
2623-
$type = $reflection->getBackingType();
26242619

2625-
if ($type === null) {
2626-
throw MappingException::nonBackedEnumMapped($this->name, $mapping['fieldName'], $mapping['enumType']);
2620+
if (! $reflection->isBacked()) {
2621+
throw MappingException::nonBackedEnumMapped($this->name, $mapping['fieldName'], $reflection->getName());
26272622
}
26282623

2624+
$type = $reflection->getBackingType();
26292625
assert($type instanceof ReflectionNamedType);
2626+
$mapping['enumType'] = $reflection->getName();
26302627
}
26312628

26322629
switch ($type->getName()) {

phpstan-baseline.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,16 @@ parameters:
445445
count: 1
446446
path: lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php
447447

448+
-
449+
message: "#^Method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\:\\:validateAndCompleteTypedFieldMapping\\(\\) should return array\\{type\\?\\: string, fieldName\\?\\: string, name\\?\\: string, strategy\\?\\: string, association\\?\\: int, id\\?\\: bool, isOwningSide\\?\\: bool, collectionClass\\?\\: class\\-string, \\.\\.\\.\\} but returns array\\{type\\?\\: string, fieldName\\?\\: string, name\\?\\: string, strategy\\?\\: string, association\\?\\: int, id\\?\\: bool, isOwningSide\\?\\: bool, collectionClass\\?\\: class\\-string, \\.\\.\\.\\}\\.$#"
450+
count: 1
451+
path: lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
452+
453+
-
454+
message: "#^Parameter \\#2 \\$enumType of class Doctrine\\\\Persistence\\\\Reflection\\\\EnumReflectionProperty constructor expects class\\-string\\<BackedEnum\\>, class\\-string\\<UnitEnum\\> given\\.$#"
455+
count: 1
456+
path: lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
457+
448458
-
449459
message: "#^Parameter \\#2 \\$mapping of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\Driver\\\\XmlDriver\\:\\:addFieldMapping\\(\\) expects array\\{type\\?\\: string, fieldName\\?\\: string, name\\?\\: string, strategy\\?\\: string, association\\?\\: int, id\\?\\: bool, isOwningSide\\?\\: bool, collectionClass\\?\\: class\\-string, \\.\\.\\.\\}, array\\<string, non\\-empty\\-array\\<int, string\\>\\|bool\\|string\\> given\\.$#"
450460
count: 1

psalm-baseline.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
2+
<files psalm-version="5.17.0@c620f6e80d0abfca532b00bda366062aaedf6e5d">
33
<file src="lib/Doctrine/ODM/MongoDB/Aggregation/Aggregation.php">
44
<MissingTemplateParam>
55
<code>IteratorAggregate</code>
@@ -82,6 +82,7 @@
8282
<file src="lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php">
8383
<InvalidArgument>
8484
<code>$mapping</code>
85+
<code>$options</code>
8586
</InvalidArgument>
8687
</file>
8788
<file src="lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php">

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,22 @@ protected static function createMetadataDriverImpl(): MappingDriver
108108
protected static function createTestDocumentManager(): DocumentManager
109109
{
110110
$config = static::getConfiguration();
111-
$client = new Client(getenv('DOCTRINE_MONGODB_SERVER') ?: DOCTRINE_MONGODB_SERVER, [], ['typeMap' => ['root' => 'array', 'document' => 'array']]);
111+
$client = new Client(getenv('DOCTRINE_MONGODB_SERVER') ?: DOCTRINE_MONGODB_SERVER);
112112

113113
return DocumentManager::create($client, $config);
114114
}
115115

116116
protected function getServerVersion(): string
117117
{
118-
$result = $this->dm->getClient()->selectDatabase(DOCTRINE_MONGODB_DATABASE)->command(['buildInfo' => 1])->toArray()[0];
118+
$result = $this->dm->getClient()->selectDatabase(DOCTRINE_MONGODB_DATABASE)->command(['buildInfo' => 1], ['typeMap' => DocumentManager::CLIENT_TYPEMAP])->toArray()[0];
119119

120120
return $result['version'];
121121
}
122122

123123
/** @psalm-param class-string $className */
124124
protected function skipTestIfNotSharded(string $className): void
125125
{
126-
$result = $this->dm->getDocumentDatabase($className)->command(['listCommands' => true])->toArray()[0];
126+
$result = $this->dm->getDocumentDatabase($className)->command(['listCommands' => true], ['typeMap' => DocumentManager::CLIENT_TYPEMAP])->toArray()[0];
127127

128128
if (array_key_exists('shardCollection', $result['commands'])) {
129129
return;
@@ -135,7 +135,7 @@ protected function skipTestIfNotSharded(string $className): void
135135
/** @psalm-param class-string $className */
136136
protected function skipTestIfSharded(string $className): void
137137
{
138-
$result = $this->dm->getDocumentDatabase($className)->command(['listCommands' => true])->toArray()[0];
138+
$result = $this->dm->getDocumentDatabase($className)->command(['listCommands' => true], ['typeMap' => DocumentManager::CLIENT_TYPEMAP])->toArray()[0];
139139

140140
if (! array_key_exists('shardCollection', $result['commands'])) {
141141
return;

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\ODM\MongoDB\Tests\Functional;
66

7+
use Doctrine\ODM\MongoDB\DocumentManager;
78
use Doctrine\ODM\MongoDB\MongoDBException;
89
use Doctrine\ODM\MongoDB\Tests\BaseTestCase;
910
use Documents\Sharded\ShardedByUser;
@@ -31,7 +32,7 @@ public function testEnsureShardingForNewCollection(): void
3132

3233
$collection = $this->dm->getDocumentCollection($class);
3334
$indexes = iterator_to_array($collection->listIndexes());
34-
$stats = $this->dm->getDocumentDatabase($class)->command(['collstats' => $collection->getCollectionName()])->toArray()[0];
35+
$stats = $this->dm->getDocumentDatabase($class)->command(['collstats' => $collection->getCollectionName()], ['typeMap' => DocumentManager::CLIENT_TYPEMAP])->toArray()[0];
3536

3637
self::assertCount(2, $indexes);
3738
self::assertSame(['k' => 1], $indexes[1]['key']);
@@ -45,7 +46,7 @@ public function testEnsureShardingForNewCollectionWithoutCreatingIndexes(): void
4546

4647
$collection = $this->dm->getDocumentCollection($class);
4748
$indexes = iterator_to_array($collection->listIndexes());
48-
$stats = $this->dm->getDocumentDatabase($class)->command(['collstats' => $collection->getCollectionName()])->toArray()[0];
49+
$stats = $this->dm->getDocumentDatabase($class)->command(['collstats' => $collection->getCollectionName()], ['typeMap' => DocumentManager::CLIENT_TYPEMAP])->toArray()[0];
4950

5051
self::assertCount(2, $indexes);
5152
self::assertSame(['k' => 1], $indexes[1]['key']);
@@ -64,7 +65,7 @@ public function testEnsureShardingForCollectionWithDocuments(): void
6465
$this->dm->getSchemaManager()->ensureDocumentSharding($class);
6566

6667
$collection = $this->dm->getDocumentCollection($class);
67-
$stats = $this->dm->getDocumentDatabase($class)->command(['collstats' => $collection->getCollectionName()])->toArray()[0];
68+
$stats = $this->dm->getDocumentDatabase($class)->command(['collstats' => $collection->getCollectionName()], ['typeMap' => DocumentManager::CLIENT_TYPEMAP])->toArray()[0];
6869

6970
self::assertTrue($stats['sharded']);
7071
}
@@ -83,7 +84,7 @@ public function testEnsureShardingForCollectionWithDocumentsThrowsIndexError():
8384
$this->dm->getSchemaManager()->ensureDocumentSharding($class);
8485

8586
$collection = $this->dm->getDocumentCollection($class);
86-
$stats = $this->dm->getDocumentDatabase($class)->command(['collstats' => $collection->getCollectionName()])->toArray()[0];
87+
$stats = $this->dm->getDocumentDatabase($class)->command(['collstats' => $collection->getCollectionName()], ['typeMap' => DocumentManager::CLIENT_TYPEMAP])->toArray()[0];
8788

8889
self::assertFalse($stats['sharded']);
8990
}
@@ -97,7 +98,7 @@ public function testEnsureShardingForCollectionWithShardingEnabled(): void
9798
$this->dm->getSchemaManager()->ensureDocumentSharding(ShardedOne::class);
9899

99100
$collection = $this->dm->getDocumentCollection($class);
100-
$stats = $this->dm->getDocumentDatabase($class)->command(['collstats' => $collection->getCollectionName()])->toArray()[0];
101+
$stats = $this->dm->getDocumentDatabase($class)->command(['collstats' => $collection->getCollectionName()], ['typeMap' => DocumentManager::CLIENT_TYPEMAP])->toArray()[0];
101102

102103
self::assertTrue($stats['sharded']);
103104
}
@@ -110,7 +111,7 @@ public function testEnsureDocumentShardingWithShardByReference(): void
110111
$this->dm->getSchemaManager()->ensureDocumentSharding($class);
111112

112113
$collection = $this->dm->getDocumentCollection($class);
113-
$stats = $this->dm->getDocumentDatabase($class)->command(['collstats' => $collection->getCollectionName()])->toArray()[0];
114+
$stats = $this->dm->getDocumentDatabase($class)->command(['collstats' => $collection->getCollectionName()], ['typeMap' => DocumentManager::CLIENT_TYPEMAP])->toArray()[0];
114115
$indexes = iterator_to_array($collection->listIndexes());
115116

116117
self::assertTrue($stats['sharded']);

tests/Doctrine/ODM/MongoDB/Tests/Repository/DefaultGridFSRepositoryTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,21 @@ public function testUploadFileWithoutChunkSize(): void
279279
self::assertSame(261120, $file->getChunkSize());
280280
}
281281

282+
public function testReadingFileWithMetadata(): void
283+
{
284+
$uploadOptions = new UploadOptions();
285+
$uploadOptions->metadata = new FileMetadata();
286+
$uploadOptions->metadata->getEmbedOne()->name = 'foo';
287+
288+
$file = $this->getRepository()->uploadFromFile(__FILE__, uploadOptions: $uploadOptions);
289+
$this->dm->detach($file);
290+
291+
$retrievedFile = $this->getRepository()->find($file->getId());
292+
self::assertInstanceOf(File::class, $retrievedFile);
293+
self::assertInstanceOf(FileMetadata::class, $retrievedFile->getMetadata());
294+
self::assertSame('foo', $retrievedFile->getMetadata()->getEmbedOne()->name);
295+
}
296+
282297
/**
283298
* @param class-string<T> $className
284299
*

0 commit comments

Comments
 (0)