File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
Doctrine/ODM/MongoDB/Tests/Functional Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 10
10
use Documents81 \Card ;
11
11
use Documents81 \Suit ;
12
12
use Error ;
13
+ use Jean85 \PrettyVersions ;
13
14
use MongoDB \BSON \ObjectId ;
14
15
use ValueError ;
15
16
16
17
use function preg_quote ;
17
18
use function sprintf ;
19
+ use function version_compare ;
18
20
19
21
/** @requires PHP >= 8.1 */
20
22
class EnumTest extends BaseTestCase
@@ -35,6 +37,25 @@ public function testPersistNew(): void
35
37
self ::assertNull ($ saved ->nullableSuit );
36
38
}
37
39
40
+ public function testArrayOfEnums (): void
41
+ {
42
+ $ persistenceVersion = PrettyVersions::getVersion ('doctrine/persistence ' )->getPrettyVersion ();
43
+ if (version_compare ('3.2.0 ' , $ persistenceVersion , '> ' )) {
44
+ self ::markTestSkipped ('Support for array of enums was introduced in doctrine/persistence 3.2.0 ' );
45
+ }
46
+
47
+ $ doc = new Card ();
48
+ $ doc ->suits = ['foo ' => Suit::Clubs, 'bar ' => Suit::Diamonds];
49
+
50
+ $ this ->dm ->persist ($ doc );
51
+ $ this ->dm ->flush ();
52
+ $ this ->dm ->clear ();
53
+
54
+ $ saved = $ this ->dm ->find (Card::class, $ doc ->id );
55
+ self ::assertInstanceOf (Card::class, $ saved );
56
+ self ::assertSame (['foo ' => Suit::Clubs, 'bar ' => Suit::Diamonds], $ saved ->suits );
57
+ }
58
+
38
59
public function testLoadingInvalidBackingValueThrowsError (): void
39
60
{
40
61
$ document = [
Original file line number Diff line number Diff line change @@ -26,5 +26,13 @@ class Card
26
26
#[ODM \Field(type: 'string ' , enumType: Suit::class, nullable: true )]
27
27
public ?Suit $ nullableSuit ;
28
28
29
+ /**
30
+ * @ODM\Field(enumType=Suit::class)
31
+ *
32
+ * @var Suit[]
33
+ */
34
+ #[ODM \Field(enumType: Suit::class)]
35
+ public array $ suits ;
36
+
29
37
public ?SuitNonBacked $ suitNonBacked ;
30
38
}
You can’t perform that action at this time.
0 commit comments