77use BackedEnum ;
88use UnitEnum ;
99
10+ use function is_string ;
1011use function sprintf ;
1112
1213/**
@@ -26,39 +27,31 @@ final class EnumDataProvider
2627 /**
2728 * Generates test cases for enum-based attribute scenarios.
2829 *
29- * Normalizes each enum case and produces an expected value as either an attribute fragment (when `$asHtml` is
30- * `true`) or the enum case instance (when `$asHtml` is `false`).
31- *
32- * @phpstan-param class-string<UnitEnum> $enumClass Enum class name implementing UnitEnum.
30+ * Normalizes each enum case and produces an expected value as either an attribute fragment.
3331 *
3432 * @param string $enumClass Enum class name implementing UnitEnum.
3533 * @param string|UnitEnum $attribute Attribute name used to build the expected fragment.
36- * @param bool $asHtml Whether to generate expected output as an attribute fragment or enum instance. Default is
37- * `true`.
3834 *
3935 * @return array Structured test cases indexed by a normalized enum value key.
4036 *
41- * @phpstan-return array<string, array{UnitEnum, mixed[], string|UnitEnum, string}>
37+ * @phpstan-param class-string<UnitEnum> $enumClass Enum class name implementing UnitEnum.
38+ * @phpstan-return array<string, array{UnitEnum, mixed[], UnitEnum, string, string}>
4239 */
43- public static function attributeCases (string $ enumClass , string |UnitEnum $ attribute, bool $ asHtml = true ): array
40+ public static function attributeCases (string $ enumClass , string |UnitEnum $ attribute ): array
4441 {
42+ $ attribute = self ::normalizeValue ($ attribute );
4543 $ cases = [];
46- $ attributeName = is_string ($ attribute ) ? $ attribute : sprintf ('%s ' , self ::normalizeValue ($ attribute ));
4744
4845 foreach ($ enumClass ::cases () as $ case ) {
4946 $ normalizedValue = self ::normalizeValue ($ case );
50-
5147 $ key = "enum: {$ normalizedValue }" ;
52- $ expected = $ asHtml ? " {$ attributeName }= \"{$ normalizedValue }\"" : $ case ;
53- $ message = $ asHtml
54- ? "Should return the ' {$ attributeName }' attribute value for enum case: {$ normalizedValue }. "
55- : "Should return the enum instance for case: {$ normalizedValue }. " ;
5648
5749 $ cases [$ key ] = [
5850 $ case ,
5951 [],
60- $ expected ,
61- $ message ,
52+ $ case ,
53+ " {$ attribute }= \"{$ normalizedValue }\"" ,
54+ "Should return the ' {$ attribute }' attribute value for enum case: {$ normalizedValue }. " ,
6255 ];
6356 }
6457
@@ -90,8 +83,19 @@ public static function tagCases(string $enumClass, string $category): array
9083 return $ data ;
9184 }
9285
93- private static function normalizeValue (UnitEnum $ enum ): string
86+ /**
87+ * Normalizes the enum value to a string representation.
88+ *
89+ * @param string|UnitEnum $enum Enum instance or string value.
90+ *
91+ * @return string Normalized string value of the enum.
92+ */
93+ private static function normalizeValue (string |UnitEnum $ enum ): string
9494 {
95+ if (is_string ($ enum )) {
96+ return $ enum ;
97+ }
98+
9599 return match ($ enum instanceof BackedEnum) {
96100 true => (string ) $ enum ->value ,
97101 false => $ enum ->name ,
0 commit comments