From 27002d10758b9548ced123523beebe335dc456f6 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Fri, 10 Jan 2025 09:40:44 +0100 Subject: [PATCH 1/3] Install latest python version to fix CI (#2714) --- .github/workflows/continuous-integration.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index cf9b10606..169724059 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -118,6 +118,11 @@ jobs: dependency-versions: "${{ matrix.dependencies }}" composer-options: "--prefer-dist" + - name: "Install latest Python version" + uses: actions/setup-python@v5 + with: + python-version: '3.13' + - id: setup-mongodb uses: mongodb-labs/drivers-evergreen-tools@master with: From 0b9c1c7555c6f7d359ddfbab02a225d0785cb127 Mon Sep 17 00:00:00 2001 From: parada85 Date: Fri, 17 Jan 2025 11:02:37 +0100 Subject: [PATCH 2/3] Fix discriminatorValue key 0 (#2716) --- .../Mapping/Annotations/DiscriminatorMap.php | 4 +- .../MongoDB/Persisters/DocumentPersister.php | 2 +- .../Tests/Functional/Ticket/GH2158Test.php | 46 +++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2158Test.php diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/DiscriminatorMap.php b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/DiscriminatorMap.php index cd1131a25..644e24443 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/DiscriminatorMap.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/DiscriminatorMap.php @@ -16,10 +16,10 @@ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY)] final class DiscriminatorMap implements Annotation { - /** @var array */ + /** @var array */ public $value; - /** @param array $value */ + /** @param array $value */ public function __construct(array $value) { $this->value = $value; diff --git a/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php b/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php index 780c0c600..061b0c9da 100644 --- a/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php +++ b/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php @@ -1470,7 +1470,7 @@ private function getClassDiscriminatorValues(ClassMetadata $metadata): array foreach ($metadata->subClasses as $className) { $key = array_search($className, $metadata->discriminatorMap); - if (! $key) { + if ($key === false) { continue; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2158Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2158Test.php new file mode 100644 index 000000000..f01456ce2 --- /dev/null +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2158Test.php @@ -0,0 +1,46 @@ +dm->persist($obj); + $this->dm->flush(); + + self::assertEquals($this->dm->find(GH2158Abstract::class, $obj->getId()), $obj); + } +} + +#[ODM\Document(collection: 'documents')] +#[ODM\InheritanceType('SINGLE_COLLECTION')] +#[ODM\DiscriminatorField('type')] +#[ODM\DiscriminatorMap([0 => GH2158FirstType::class, 1 => GH2158SecondType::class])] +abstract class GH2158Abstract +{ + /** @var string */ + #[ODM\Id] + protected $id; + + public function getId(): string + { + return $this->id; + } +} + +#[ODM\Document] +class GH2158FirstType extends GH2158Abstract +{ +} + +#[ODM\Document] +class GH2158SecondType extends GH2158Abstract +{ +} From 8f0b3702b0c600d54bafc7c418ec13f4c2e990be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 17 Jan 2025 15:16:04 +0100 Subject: [PATCH 3/3] Relax final constrain on stage classes (#2717) --- lib/Doctrine/ODM/MongoDB/Aggregation/Stage/AddFields.php | 3 ++- lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Set.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/AddFields.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/AddFields.php index b658656bb..61355728b 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/AddFields.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/AddFields.php @@ -11,8 +11,9 @@ * * @psalm-import-type OperatorExpression from Expr * @psalm-type AddFieldsStageExpression = array{'$addFields': array} + * @final */ -final class AddFields extends Operator +class AddFields extends Operator { /** @return AddFieldsStageExpression */ public function getExpression(): array diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Set.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Set.php index cca5aed34..3d4afacac 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Set.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Set.php @@ -11,8 +11,9 @@ * * @psalm-import-type OperatorExpression from Expr * @psalm-type SetStageExpression = array{'$set': array} + * @final */ -final class Set extends Operator +class Set extends Operator { /** @psalm-return SetStageExpression */ public function getExpression(): array