3
3
namespace gapple \Tests \StructuredFields \Httpwg ;
4
4
5
5
use gapple \Tests \StructuredFields \Rule ;
6
- use gapple \Tests \StructuredFields \RulesetTest ;
6
+ use gapple \Tests \StructuredFields \RulesetTestBase ;
7
7
8
- abstract class HttpwgTest extends RulesetTest
8
+ abstract class HttpwgTestBase extends RulesetTestBase
9
9
{
10
+ protected static string $ ruleset ;
11
+
10
12
/**
11
- * @var string
13
+ * @return array< string, array{Rule}>
12
14
*/
13
- protected $ ruleset ;
14
-
15
- protected function rulesetDataProvider (): array
15
+ protected static function rulesetDataProvider (): array
16
16
{
17
- $ path = __DIR__ . '/../../vendor/httpwg/structured-field-tests/ ' . $ this -> ruleset . '.json ' ;
17
+ $ path = __DIR__ . '/../../vendor/httpwg/structured-field-tests/ ' . static :: $ ruleset . '.json ' ;
18
18
if (!file_exists ($ path )) {
19
19
throw new \RuntimeException ('Ruleset file does not exist ' );
20
20
}
@@ -34,29 +34,22 @@ protected function rulesetDataProvider(): array
34
34
foreach ($ rules as $ rawRule ) {
35
35
if (isset ($ rawRule ->expected )) {
36
36
try {
37
- switch ($ rawRule ->header_type ) {
38
- case 'item ' :
39
- $ rawRule ->expected = HttpwgRuleExpectedConverter::item ($ rawRule ->expected );
40
- break ;
41
- case 'list ' :
42
- $ rawRule ->expected = HttpwgRuleExpectedConverter::list ($ rawRule ->expected );
43
- break ;
44
- case 'dictionary ' :
45
- $ rawRule ->expected = HttpwgRuleExpectedConverter::dictionary ($ rawRule ->expected );
46
- break ;
47
- default :
48
- throw new \UnexpectedValueException ('Unknown header type ' );
49
- }
37
+ $ rawRule ->expected = match ($ rawRule ->header_type ) {
38
+ 'item ' => HttpwgRuleExpectedConverter::item ($ rawRule ->expected ),
39
+ 'list ' => HttpwgRuleExpectedConverter::list ($ rawRule ->expected ),
40
+ 'dictionary ' => HttpwgRuleExpectedConverter::dictionary ($ rawRule ->expected ),
41
+ default => throw new \UnexpectedValueException ('Unknown header type ' ),
42
+ };
50
43
} catch (\UnexpectedValueException | \AssertionError $ e ) {
51
44
// Skip rules that cannot be parsed.
52
45
continue ;
53
46
}
54
47
}
55
- $ rule = Rule::fromClass ($ rawRule );
48
+ $ rule = Rule::fromClass ($ rawRule ); // @phpstan-ignore argument.type
56
49
57
50
if (isset ($ dataset [$ rule ->name ])) {
58
51
user_error (
59
- 'Ruleset " ' . $ this -> ruleset . '" contains duplicate rule name " ' . $ rule ->name . '" ' ,
52
+ 'Ruleset " ' . static :: $ ruleset . '" contains duplicate rule name " ' . $ rule ->name . '" ' ,
60
53
E_USER_WARNING
61
54
);
62
55
}
0 commit comments