File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -250,6 +250,16 @@ final public static function clear()
250
250
unset(self ::$ instances [$ class ], self ::$ constants [$ class ]);
251
251
}
252
252
253
+ /**
254
+ * Get a list of enumerator instances ordered by ordinal number
255
+ *
256
+ * @return static[]
257
+ */
258
+ final public static function getEnumerators ()
259
+ {
260
+ return array_map ('self::getByName ' , array_keys (self ::detectConstants (get_called_class ())));
261
+ }
262
+
253
263
/**
254
264
* Get all available constants of the called class
255
265
*
Original file line number Diff line number Diff line change @@ -106,6 +106,22 @@ public function testGetByExtendedInstanceOfKnownValue()
106
106
EnumBasic::get ($ enum );
107
107
}
108
108
109
+ public function testGetEnumerators ()
110
+ {
111
+ $ constants = EnumInheritance::getConstants ();
112
+ $ enumerators = EnumInheritance::getEnumerators ();
113
+
114
+ $ this ->assertSame (count ($ constants ), count ($ enumerators ));
115
+ for ($ i = 0 ; $ i < count ($ enumerators ); ++$ i ) {
116
+ $ this ->assertArrayHasKey ($ i , $ enumerators );
117
+ $ this ->assertInstanceOf ('MabeEnumTest\TestAsset\EnumInheritance ' , $ enumerators [$ i ]);
118
+
119
+ $ enumerator = $ enumerators [$ i ];
120
+ $ this ->assertArrayHasKey ($ enumerator ->getName (), $ constants );
121
+ $ this ->assertSame ($ constants [$ enumerator ->getName ()], $ enumerator ->getValue ());
122
+ }
123
+ }
124
+
109
125
public function testGetAllValues ()
110
126
{
111
127
$ constants = EnumBasic::getConstants ();
You can’t perform that action at this time.
0 commit comments