|
1 | 1 | ; Class that follow the naming convention of PHPUnit test classes |
2 | 2 | ; and that doesn't have the abstract modifier |
| 3 | +; and extends a base class (PHPUnit test classes always inherit from TestCase, |
| 4 | +; directly or transitively; a *Test class with no `extends` at all is not |
| 5 | +; PHPUnit — most likely a Testo test — so requiring a base_clause avoids |
| 6 | +; tagging those as phpunit-test) |
3 | 7 | ; and have a method that follow the naming convention of PHPUnit test methods |
4 | 8 | ; and the method is public |
5 | 9 | ( |
|
9 | 13 | . |
10 | 14 | name: (_) @_name |
11 | 15 | (#match? @_name ".*Test$") |
| 16 | + (base_clause) |
12 | 17 | body: (declaration_list |
13 | 18 | (method_declaration |
14 | 19 | (visibility_modifier)? @_visibility |
|
23 | 28 |
|
24 | 29 | ; Class that follow the naming convention of PHPUnit test classes |
25 | 30 | ; and that doesn't have the abstract modifier |
| 31 | +; and extends a base class (see note above — filters out inheritance-less |
| 32 | +; Testo classes) |
26 | 33 | ; and have a method that has the @test annotation |
27 | 34 | ; and the method is public |
28 | 35 | ( |
|
32 | 39 | . |
33 | 40 | name: (_) @_name |
34 | 41 | (#match? @_name ".*Test$") |
| 42 | + (base_clause) |
35 | 43 | body: (declaration_list |
36 | 44 | ((comment) @_comment |
37 | 45 | (#match? @_comment ".*@test\\b.*") |
|
47 | 55 | (#set! tag phpunit-test) |
48 | 56 | ) |
49 | 57 |
|
50 | | -; Class that follow the naming convention of PHPUnit test classes |
51 | | -; and that doesn't have the abstract modifier |
52 | | -; and have a method that has the #[Test] attribute |
53 | | -; and the method is public |
| 58 | +; Method carrying the #[Test] attribute, disambiguated to PHPUnit via the |
| 59 | +; file's `use` import. Both PHPUnit (PHPUnit\Framework\Attributes\Test) and |
| 60 | +; Testo (Testo\Test) expose a method-level #[Test]; since PHP forbids two |
| 61 | +; imports sharing an alias, the presence of `use PHPUnit\Framework\Attributes\Test` |
| 62 | +; proves the attribute is PHPUnit's. This replaces the old class-name (*Test) |
| 63 | +; gate so that a Testo file's #[Test] methods are no longer tagged phpunit-test. |
| 64 | +; (Trade-off: a PHPUnit file importing the attribute via a group use or writing |
| 65 | +; it fully-qualified won't match here — it still gets class-level buttons.) |
| 66 | +; |
| 67 | +; Form 1: no namespace, or `namespace X;` — `use` and class are siblings. |
54 | 68 | ( |
55 | | - (class_declaration |
56 | | - (_)* @_modifier |
57 | | - (#not-any-eq? @_modifier "abstract") |
58 | | - . |
59 | | - name: (_) @_name |
60 | | - (#match? @_name ".*Test$") |
61 | | - body: (declaration_list |
62 | | - (method_declaration |
63 | | - (attribute_list |
64 | | - (attribute_group |
65 | | - (attribute (name) @_attribute) |
66 | | - ) |
67 | | - ) |
68 | | - (#eq? @_attribute "Test") |
69 | | - (visibility_modifier)? @_visibility |
70 | | - (#eq? @_visibility "public") |
71 | | - name: (_) @run |
72 | | - (#not-match? @run "^test.*") |
73 | | - ) |
74 | | - ) |
| 69 | + (program |
| 70 | + (namespace_use_declaration |
| 71 | + (namespace_use_clause (qualified_name) @_use)) |
| 72 | + (#eq? @_use "PHPUnit\\Framework\\Attributes\\Test") |
| 73 | + (class_declaration |
| 74 | + body: (declaration_list |
| 75 | + (method_declaration |
| 76 | + attributes: (attribute_list |
| 77 | + (attribute_group |
| 78 | + (attribute (name) @_attribute))) |
| 79 | + (#eq? @_attribute "Test") |
| 80 | + (visibility_modifier)? @_visibility |
| 81 | + (#eq? @_visibility "public") |
| 82 | + name: (_) @run |
| 83 | + (#not-match? @run "^test.*")))) |
| 84 | + ) @_phpunit-test |
| 85 | + (#set! tag phpunit-test) |
| 86 | +) |
| 87 | + |
| 88 | +; Form 2: braced `namespace X { ... }`. |
| 89 | +( |
| 90 | + (namespace_definition |
| 91 | + body: (compound_statement |
| 92 | + (namespace_use_declaration |
| 93 | + (namespace_use_clause (qualified_name) @_use)) |
| 94 | + (#eq? @_use "PHPUnit\\Framework\\Attributes\\Test") |
| 95 | + (class_declaration |
| 96 | + body: (declaration_list |
| 97 | + (method_declaration |
| 98 | + attributes: (attribute_list |
| 99 | + (attribute_group |
| 100 | + (attribute (name) @_attribute))) |
| 101 | + (#eq? @_attribute "Test") |
| 102 | + (visibility_modifier)? @_visibility |
| 103 | + (#eq? @_visibility "public") |
| 104 | + name: (_) @run |
| 105 | + (#not-match? @run "^test.*"))))) |
75 | 106 | ) @_phpunit-test |
76 | 107 | (#set! tag phpunit-test) |
77 | 108 | ) |
78 | 109 |
|
79 | 110 | ; Class that follow the naming convention of PHPUnit test classes |
80 | 111 | ; and that doesn't have the abstract modifier |
| 112 | +; and extends a base class (see note above — filters out inheritance-less |
| 113 | +; Testo classes) |
81 | 114 | ( |
82 | 115 | (class_declaration |
83 | 116 | (_)* @_modifier |
84 | 117 | (#not-any-eq? @_modifier "abstract") |
85 | 118 | . |
86 | 119 | name: (_) @run |
87 | 120 | (#match? @run ".*Test$") |
| 121 | + (base_clause) |
| 122 | + ) @_phpunit-test |
| 123 | + (#set! tag phpunit-test) |
| 124 | +) |
| 125 | + |
| 126 | +; Method carrying a fully-qualified `#[\PHPUnit\Framework\Attributes\Test]` |
| 127 | +; attribute — self-identifying, so no `use` correlation is needed. |
| 128 | +( |
| 129 | + (method_declaration |
| 130 | + attributes: (attribute_list |
| 131 | + (attribute_group |
| 132 | + (attribute (qualified_name) @_attribute))) |
| 133 | + (#eq? @_attribute "\\PHPUnit\\Framework\\Attributes\\Test") |
| 134 | + (visibility_modifier)? @_visibility |
| 135 | + (#eq? @_visibility "public") |
| 136 | + name: (_) @run |
88 | 137 | ) @_phpunit-test |
89 | 138 | (#set! tag phpunit-test) |
90 | 139 | ) |
|
0 commit comments