@@ -34,14 +34,14 @@ class YourRuleTest extends RuleTestCase
3434
3535 public function testRule(): void
3636 {
37- $this->analyseFile(__DIR__ . '/data /YourRule/code.php');
37+ $this->analyseFile(__DIR__ . '/Data /YourRule/code.php');
3838 }
3939}
4040```
4141
4242### 2. Create Test Data File
4343
44- Create ` tests/Rule/data /YourRule/code.php ` :
44+ Create ` tests/Rule/Data /YourRule/code.php ` :
4545
4646``` php
4747<?php declare(strict_types = 1);
@@ -82,7 +82,7 @@ During development, automatically generate error comments:
8282public function testRule(): void
8383{
8484 // Set to true temporarily to generate error comments
85- $this->analyseFile(__DIR__ . '/data /code.php', autofix: true);
85+ $this->analyseFile(__DIR__ . '/Data /code.php', autofix: true);
8686}
8787```
8888
@@ -110,13 +110,13 @@ class ComplexRuleTest extends RuleTestCase
110110
111111 public function testDefault(): void
112112 {
113- $this->analyseFile(__DIR__ . '/data /ComplexRule/default.php');
113+ $this->analyseFile(__DIR__ . '/Data /ComplexRule/default.php');
114114 }
115115
116116 public function testStrict(): void
117117 {
118118 $this->strictMode = true;
119- $this->analyseFile(__DIR__ . '/data /ComplexRule/strict.php');
119+ $this->analyseFile(__DIR__ . '/Data /ComplexRule/strict.php');
120120 }
121121}
122122```
@@ -127,13 +127,13 @@ class ComplexRuleTest extends RuleTestCase
127127public function testPhp82Features(): void
128128{
129129 $this->phpVersion = $this->createPhpVersion(80_200);
130- $this->analyseFile(__DIR__ . '/data /Rule/php82-features.php');
130+ $this->analyseFile(__DIR__ . '/Data /Rule/php82-features.php');
131131}
132132```
133133
134134### Custom PHPStan Configuration
135135
136- Create ` tests/Rule/data /YourRule/config.neon ` :
136+ Create ` tests/Rule/Data /YourRule/config.neon ` :
137137
138138``` neon
139139parameters:
@@ -147,7 +147,7 @@ public static function getAdditionalConfigFiles(): array
147147{
148148 return array_merge(
149149 parent::getAdditionalConfigFiles(),
150- [__DIR__ . '/data /YourRule/config.neon'],
150+ [__DIR__ . '/Data /YourRule/config.neon'],
151151 );
152152}
153153```
@@ -171,7 +171,7 @@ tests/
171171├── Rule/
172172│ ├── YourRuleTest.php
173173│ ├── AnotherRuleTest.php
174- │ └── data /
174+ │ └── Data /
175175│ ├── YourRule/
176176│ │ ├── code.php # Main test file
177177│ │ ├── edge-cases.php # Additional scenarios
@@ -180,97 +180,6 @@ tests/
180180│ └── code.php
181181```
182182
183- ## Common Patterns
184-
185- ### Testing Different Error Scenarios
186-
187- ``` php
188- <?php
189-
190- // Valid usage - no error comment
191- $valid = getValue();
192-
193- // Invalid usage with expected error
194- $invalid = badFunction(); // error: Function badFunction() is not allowed
195-
196- // Multiple errors on same line
197- $a = bad1(); $b = bad2(); // error: Function bad1() is not allowed // error: Function bad2() is not allowed
198- ```
199-
200- ### Testing Complex Error Messages
201-
202- ``` php
203- <?php
204-
205- function test($param) {
206- // Error with variable content
207- return $param + null; // error: Null value involved in binary operation: int + null
208-
209- // Error with specific types
210- $array['key'] = $value; // error: Unsafe array key access, key type: mixed
211- }
212- ```
213-
214- ## Error Comment Rules
215-
216- 1 . ** Format** : ` // error: <message> `
217- 2 . ** Placement** : At the end of the line that should trigger the error
218- 3 . ** Multiple errors** : Use separate comments: ` // error: First // error: Second `
219- 4 . ** No error expected** : Don't add any comment
220- 5 . ** Exact matching** : Error message must match exactly (whitespace sensitive)
221-
222- ## Development Workflow
223-
224- ### 1. Write the Rule
225-
226- ``` php
227- class YourRule implements Rule
228- {
229- public function getNodeType(): string
230- {
231- return Node\Expr\FuncCall::class;
232- }
233-
234- public function processNode(Node $node, Scope $scope): array
235- {
236- // Your rule logic
237- return [
238- RuleErrorBuilder::message('Error message')
239- ->identifier('shipmonk.yourRule.errorType')
240- ->build(),
241- ];
242- }
243- }
244- ```
245-
246- ### 2. Create Test with Autofix
247-
248- ``` php
249- public function testRule(): void
250- {
251- $this->analyseFile(__DIR__ . '/data/code.php', autofix: true);
252- }
253- ```
254-
255- ### 3. Run Test to Generate Comments
256-
257- ``` bash
258- vendor/bin/phpunit tests/Rule/YourRuleTest.php
259- ```
260-
261- ### 4. Review Generated Comments
262-
263- Check the test data file - error comments will be automatically added.
264-
265- ### 5. Remove Autofix and Commit
266-
267- ``` php
268- public function testRule(): void
269- {
270- $this->analyseFile(__DIR__ . '/data/code.php'); // autofix: true removed
271- }
272- ```
273-
274183## Development
275184
276185``` bash
@@ -292,12 +201,6 @@ composer check:collisions # Check for name collisions
292201composer fix:cs
293202```
294203
295- ## Requirements
296-
297- - PHP 7.4 or higher
298- - PHPStan 2.1.8 or higher
299- - PHPUnit 9.6.22 or higher (for testing)
300-
301204## License
302205
303206MIT License - see [ LICENSE] ( LICENSE ) file.
0 commit comments