|
147 | 147 | - **`README.md`** - User-facing documentation, installation, usage, available rules |
148 | 148 | - **`CONTRIBUTING.md`** - How to contribute (code, tests, docs) |
149 | 149 | - **`CONTRIBUTORS.md`** - List of project contributors |
150 | | -- **`claude.md`** - This file (Claude AI context) |
| 150 | +- **`CLAUDE.md`** - This file (Claude AI context) |
151 | 151 |
|
152 | 152 | ### Configuration Files |
153 | 153 | - **`phparkitect.php`** - Example configuration file for users |
@@ -288,10 +288,62 @@ make test # Runs tests on configured PHP version |
288 | 288 | - Mixed scenarios that could break |
289 | 289 | 5. **Test coverage:** Always add unit tests for new functionality |
290 | 290 |
|
| 291 | +## Reflection-based expression rules (Option B — mandatory autoloading) |
| 292 | + |
| 293 | +All `src/Expression/ForClasses/` expressions (`Implement`, `NotImplement`, `Extend`, |
| 294 | +`NotExtend`, `HaveTrait`, `NotHaveTrait`) use **pure reflection** with no static fallback: |
| 295 | + |
| 296 | +```php |
| 297 | +try { |
| 298 | + $reflection = new \ReflectionClass($theClass->getFQCN()); |
| 299 | + // ... use reflection ... |
| 300 | +} catch (\ReflectionException $e) { |
| 301 | + return; // class not autoloadable → skip silently |
| 302 | +} |
| 303 | +``` |
| 304 | + |
| 305 | +**Consequence:** every fixture class used in tests must be autoloadable. No vfsStream, |
| 306 | +no inline PHP strings with fake namespaces. |
| 307 | + |
| 308 | +### Test fixture conventions |
| 309 | + |
| 310 | +- Real fixture files live in `tests/*/Fixtures/` subdirectories |
| 311 | +- PSR-4 namespaced fixtures → covered by `"Arkitect\\Tests\\": "tests/"` in autoload-dev |
| 312 | +- Global-namespace traits (e.g. `DatabaseTransactions`) → listed in `classmap` in `composer.json` |
| 313 | +- E2E mvc fixtures (`App\Controller\*`, etc.) → `"App\\": "tests/E2E/_fixtures/mvc/"` |
| 314 | +- `ContainerAwareInterface` (global namespace) → listed in `classmap` |
| 315 | +- After adding fixtures: run `composer dump-autoload` |
| 316 | + |
| 317 | +### composer.json autoload-dev (current state) |
| 318 | + |
| 319 | +```json |
| 320 | +"autoload-dev": { |
| 321 | + "psr-4": { |
| 322 | + "Arkitect\\Tests\\": "tests/", |
| 323 | + "App\\": "tests/E2E/_fixtures/mvc/" |
| 324 | + }, |
| 325 | + "classmap": [ |
| 326 | + "tests/E2E/_fixtures/mvc/ContainerAwareInterface.php", |
| 327 | + "tests/Integration/PHPUnit/Fixtures/DatabaseTransactions.php", |
| 328 | + "tests/Integration/PHPUnit/Fixtures/RefreshDatabase.php", |
| 329 | + "tests/Integration/PHPUnit/Fixtures/HasUuid.php" |
| 330 | + ] |
| 331 | +} |
| 332 | +``` |
| 333 | + |
| 334 | +### phpunit.xml — fixture directories excluded from test discovery |
| 335 | + |
| 336 | +```xml |
| 337 | +<exclude>tests/Integration/PHPUnit/Fixtures</exclude> |
| 338 | +<exclude>tests/Integration/Fixtures</exclude> |
| 339 | +<exclude>tests/Unit/Analyzer/FileParser/Fixtures</exclude> |
| 340 | +<exclude>tests/Unit/Rules/Fixtures</exclude> |
| 341 | +``` |
| 342 | + |
291 | 343 | ## Testing Guidelines |
292 | 344 |
|
293 | 345 | - Unit tests go in `tests/` mirroring the `src/` structure |
294 | | -- Use PHPUnit (7.5+, 9.0+, or 10.0+) |
| 346 | +- Use PHPUnit (9.6+, 10.0+, 11.0+) |
295 | 347 | - Use prophecy for mocking |
296 | 348 | - Aim for good coverage of critical paths |
297 | 349 | - Test both success and edge cases |
|
0 commit comments