2323use Guanguans \PHPStanRules \Rule \AbstractRule ;
2424use Illuminate \Support \Str ;
2525use PHPStan \Testing \RuleTestCase ;
26- use Webmozart \Assert \Assert ;
2726
2827abstract class AbstractRuleTestCase extends RuleTestCase
2928{
29+ private const ERROR_MESSAGE_METHOD_NAME = 'errorMessage ' ;
30+
3031 /**
3132 * @dataProvider provideRuleCases()
3233 *
33- * @param array<int, list< int|string>> $expectedErrorMessagesWithLines
34+ * @param list<array{0: string, 1: int, 2?: null |string}> $expectedErrorMessages
3435 *
3536 * @noinspection PhpUndefinedNamespaceInspection
3637 * @noinspection PhpLanguageLevelInspection
@@ -39,21 +40,25 @@ abstract class AbstractRuleTestCase extends RuleTestCase
3940 * @noinspection PhpUnitTestsInspection
4041 */
4142 #[\PHPUnit \Framework \Attributes \DataProvider('provideRuleCases ' )]
42- final public function testRule (string $ filePath , array $ expectedErrorMessagesWithLines ): void
43+ final public function testRule (string $ filePath , array $ expectedErrorMessages ): void
4344 {
44- Assert::allInteger (array_keys ($ expectedErrorMessagesWithLines ));
45- $ this ->analyse ([$ filePath ], $ expectedErrorMessagesWithLines );
45+ $ this ->analyse ([$ filePath ], $ expectedErrorMessages );
4646 }
4747
4848 final public function testRuleWithoutErrorMessage (): void
4949 {
5050 $ this ->analyse (glob (static ::directory ().'/Fixtures/Skip*.php ' ), []);
5151 }
5252
53- final public function testRuleCommon (): void
53+ final public function testRuleBasicInformation (): void
5454 {
55- // self::assertInstanceOf(static::ruleClass(), $this->getRule());
56- self ::assertTrue (method_exists ($ this ->getRule (), 'errorMessage ' ));
55+ self ::assertTrue (is_subclass_of (static ::ruleClass (), AbstractRule::class));
56+ self ::assertTrue (method_exists ($ this ->getRule (), self ::ERROR_MESSAGE_METHOD_NAME ));
57+ self ::assertFileExists (\sprintf (
58+ '%s/Fixtures/%s.php ' ,
59+ static ::directory (),
60+ Str::beforeLast (static ::ruleReflectionClass ()->getShortName (), 'Rule ' )
61+ ));
5762 }
5863
5964 /**
@@ -79,15 +84,15 @@ protected static function rawGetRule(): AbstractRule
7984 return static ::getContainer ()->getByType (static ::ruleClass ());
8085 }
8186
82- protected static function invokeErrorMessage (...$ args )
87+ protected static function invokeRuleErrorMessageMethod (...$ args )
8388 {
84- return static ::invoke ( ' errorMessage ' , ...$ args );
89+ return static ::invokeRuleMethod ( self :: ERROR_MESSAGE_METHOD_NAME , ...$ args );
8590 }
8691
87- protected static function invoke (string $ method , ...$ args )
92+ protected static function invokeRuleMethod (string $ method , ...$ args )
8893 {
8994 $ reflectionMethod = static ::ruleReflectionClass ()->getMethod ($ method );
90- $ reflectionMethod ->setAccessible (true );
95+ \ PHP_VERSION_ID < 80100 and $ reflectionMethod ->setAccessible (true );
9196
9297 return $ reflectionMethod ->invoke (static ::rawGetRule (), ...$ args );
9398 }
0 commit comments