File tree Expand file tree Collapse file tree 3 files changed +49
-3
lines changed
tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket Expand file tree Collapse file tree 3 files changed +49
-3
lines changed Original file line number Diff line number Diff line change 1616#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY )]
1717final class DiscriminatorMap implements Annotation
1818{
19- /** @var array<string, class-string> */
19+ /** @var array<class-string> */
2020 public $ value ;
2121
22- /** @param array<string, class-string> $value */
22+ /** @param array<class-string> $value */
2323 public function __construct (array $ value )
2424 {
2525 $ this ->value = $ value ;
Original file line number Diff line number Diff line change @@ -1470,7 +1470,7 @@ private function getClassDiscriminatorValues(ClassMetadata $metadata): array
14701470
14711471 foreach ($ metadata ->subClasses as $ className ) {
14721472 $ key = array_search ($ className , $ metadata ->discriminatorMap );
1473- if (! $ key ) {
1473+ if ($ key === false ) {
14741474 continue ;
14751475 }
14761476
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Doctrine \ODM \MongoDB \Tests \Functional \Ticket ;
6+
7+ use Doctrine \ODM \MongoDB \Mapping \Annotations as ODM ;
8+ use Doctrine \ODM \MongoDB \Tests \BaseTestCase ;
9+
10+ class GH2158Test extends BaseTestCase
11+ {
12+ public function testDiscriminatorMapCreationType (): void
13+ {
14+ $ obj = new GH2158FirstType ();
15+ $ this ->dm ->persist ($ obj );
16+ $ this ->dm ->flush ();
17+
18+ self ::assertEquals ($ this ->dm ->find (GH2158Abstract::class, $ obj ->getId ()), $ obj );
19+ }
20+ }
21+
22+ #[ODM \Document(collection: 'documents ' )]
23+ #[ODM \InheritanceType('SINGLE_COLLECTION ' )]
24+ #[ODM \DiscriminatorField('type ' )]
25+ #[ODM \DiscriminatorMap([0 => GH2158FirstType::class, 1 => GH2158SecondType::class])]
26+ abstract class GH2158Abstract
27+ {
28+ /** @var string */
29+ #[ODM \Id]
30+ protected $ id ;
31+
32+ public function getId (): string
33+ {
34+ return $ this ->id ;
35+ }
36+ }
37+
38+ #[ODM \Document]
39+ class GH2158FirstType extends GH2158Abstract
40+ {
41+ }
42+
43+ #[ODM \Document]
44+ class GH2158SecondType extends GH2158Abstract
45+ {
46+ }
You can’t perform that action at this time.
0 commit comments