This repository was archived by the owner on Dec 26, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -174,4 +174,12 @@ public static function getEnumByValue($value)
174
174
)
175
175
);
176
176
}
177
+
178
+ /**
179
+ * @return string
180
+ */
181
+ public function __toString ()
182
+ {
183
+ return sprintf ("%s::%s " , get_called_class (), $ this ->getName ());
184
+ }
177
185
}
Original file line number Diff line number Diff line change @@ -69,4 +69,25 @@ public function testGetMembersWorks()
69
69
"MY_FALSE " => 2
70
70
], MyBoolean::getMembers ());
71
71
}
72
+
73
+ /**
74
+ * @dataProvider dataToStringWorks
75
+ * @param mixed $enum
76
+ * @param mixed $expectedString
77
+ */
78
+ public function testToStringWorks ($ enum , $ expectedString )
79
+ {
80
+ $ this ->assertSame ($ expectedString , $ enum ->__toString ());
81
+ $ this ->assertSame ($ expectedString , (string ) $ enum );
82
+ $ this ->assertSame ($ expectedString , "{$ enum }" );
83
+ $ this ->assertSame ($ expectedString , $ enum . "" );
84
+ }
85
+
86
+ public function dataToStringWorks ()
87
+ {
88
+ return [
89
+ [MyBoolean::MY_TRUE (), MyBoolean::getClass () . "::MY_TRUE " ],
90
+ [MyBoolean::MY_FALSE (), MyBoolean::getClass () . "::MY_FALSE " ],
91
+ ];
92
+ }
72
93
}
You can’t perform that action at this time.
0 commit comments