File tree 3 files changed +36
-0
lines changed
3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ Static methods:
62
62
63
63
- ` toArray() ` method Returns all possible values as an array (constant name in key, constant value in value)
64
64
- ` keys() ` Returns the names (keys) of all constants in the Enum class
65
+ - ` values() ` Returns instances of the Enum class of all Enum constants (constant name in key, Enum instance in value)
65
66
- ` isValid() ` Check if tested value is valid on enum set
66
67
- ` isValidKey() ` Check if tested key is valid on enum set
67
68
- ` search() ` Return key for searched value
Original file line number Diff line number Diff line change @@ -83,6 +83,22 @@ public static function keys()
83
83
return array_keys (self ::toArray ());
84
84
}
85
85
86
+ /**
87
+ * Returns instances of the Enum class of all Enum constants
88
+ *
89
+ * @return array Constant name in key, Enum instance in value
90
+ */
91
+ public static function values ()
92
+ {
93
+ $ values = array ();
94
+
95
+ foreach (self ::toArray () as $ key => $ value ) {
96
+ $ values [$ key ] = new static ($ value );
97
+ }
98
+
99
+ return $ values ;
100
+ }
101
+
86
102
/**
87
103
* Returns all possible values as an array
88
104
*
Original file line number Diff line number Diff line change @@ -98,6 +98,25 @@ public function testKeys()
98
98
$ this ->assertSame ($ expectedValues , $ values );
99
99
}
100
100
101
+ /**
102
+ * values()
103
+ */
104
+ public function testValues ()
105
+ {
106
+ $ values = EnumFixture::values ();
107
+ $ expectedValues = array (
108
+ "FOO " => new EnumFixture (EnumFixture::FOO ),
109
+ "BAR " => new EnumFixture (EnumFixture::BAR ),
110
+ "NUMBER " => new EnumFixture (EnumFixture::NUMBER ),
111
+ "PROBLEMATIC_NUMBER " => new EnumFixture (EnumFixture::PROBLEMATIC_NUMBER ),
112
+ "PROBLEMATIC_NULL " => new EnumFixture (EnumFixture::PROBLEMATIC_NULL ),
113
+ "PROBLEMATIC_EMPTY_STRING " => new EnumFixture (EnumFixture::PROBLEMATIC_EMPTY_STRING ),
114
+ "PROBLEMATIC_BOOLEAN_FALSE " => new EnumFixture (EnumFixture::PROBLEMATIC_BOOLEAN_FALSE ),
115
+ );
116
+
117
+ $ this ->assertEquals ($ expectedValues , $ values );
118
+ }
119
+
101
120
/**
102
121
* toArray()
103
122
*/
You can’t perform that action at this time.
0 commit comments