Skip to content

Commit 7c859d8

Browse files
committed
Add a test to test all rules are registered
Inspired by https://x.com/janedbal/status/1920102533520929185
1 parent 3ec5291 commit 7c859d8

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/AllRulesRegisteredTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace Spaze\PHPStan\Rules\Disallowed;
5+
6+
use DirectoryIterator;
7+
use PHPStan\Testing\PHPStanTestCase;
8+
9+
class AllRulesRegisteredTest extends PHPStanTestCase
10+
{
11+
12+
private const RULES_DIRS = [
13+
'Calls',
14+
'Usages',
15+
'HelperRules',
16+
];
17+
18+
19+
public function testAllRulesRegistered(): void
20+
{
21+
foreach (self::RULES_DIRS as $directory) {
22+
foreach (new DirectoryIterator(__DIR__ . '/../src/' . $directory) as $file) {
23+
if ($file->getExtension() === 'php') {
24+
$class = sprintf('Spaze\PHPStan\Rules\Disallowed\%s\%s', $directory, $file->getBasename('.php'));
25+
if (!class_exists($class)) {
26+
continue;
27+
}
28+
$services = self::getContainer()->findServiceNamesByType($class);
29+
self::assertNotEmpty($services, "{$class} is not a registered rule");
30+
}
31+
}
32+
}
33+
}
34+
35+
36+
public static function getAdditionalConfigFiles(): array
37+
{
38+
return [
39+
__DIR__ . '/../extension.neon',
40+
];
41+
}
42+
43+
}

0 commit comments

Comments
 (0)