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 1010use Documents81 \Card ;
1111use Documents81 \Suit ;
1212use Error ;
13+ use Jean85 \PrettyVersions ;
1314use MongoDB \BSON \ObjectId ;
1415use ValueError ;
1516
1617use function preg_quote ;
1718use function sprintf ;
19+ use function version_compare ;
1820
1921/** @requires PHP >= 8.1 */
2022class EnumTest extends BaseTestCase
@@ -35,6 +37,25 @@ public function testPersistNew(): void
3537 self ::assertNull ($ saved ->nullableSuit );
3638 }
3739
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+
3859 public function testLoadingInvalidBackingValueThrowsError (): void
3960 {
4061 $ document = [
Original file line number Diff line number Diff line change @@ -26,5 +26,13 @@ class Card
2626 #[ODM \Field(type: 'string ' , enumType: Suit::class, nullable: true )]
2727 public ?Suit $ nullableSuit ;
2828
29+ /**
30+ * @ODM\Field(enumType=Suit::class)
31+ *
32+ * @var Suit[]
33+ */
34+ #[ODM \Field(enumType: Suit::class)]
35+ public array $ suits ;
36+
2937 public ?SuitNonBacked $ suitNonBacked ;
3038}
You can’t perform that action at this time.
0 commit comments