diff --git a/config/static-rules.neon b/config/static-rules.neon index 22455d0b..e8a44ec6 100644 --- a/config/static-rules.neon +++ b/config/static-rules.neon @@ -1,7 +1,6 @@ rules: - Symplify\PHPStanRules\Rules\NoProtectedClassElementRule - Symplify\PHPStanRules\Rules\ForbiddenExtendOfNonAbstractClassRule - - Symplify\PHPStanRules\Rules\NoConstructorInTestRule - Symplify\PHPStanRules\Rules\Complexity\ForbiddenSameNamedNewInstanceRule # domain diff --git a/docs/rules_overview.md b/docs/rules_overview.md index e4f25f31..0d3b8447 100644 --- a/docs/rules_overview.md +++ b/docs/rules_overview.md @@ -1,4 +1,4 @@ -# 49 Rules Overview +# 48 Rules Overview ## AnnotateRegexClassConstWithRegexLinkRule @@ -688,40 +688,6 @@ class SomeClass
-## NoConstructorInTestRule - -Do not use constructor in tests. Move to `setUp()` method - -- class: [`Symplify\PHPStanRules\Rules\NoConstructorInTestRule`](../src/Rules/NoConstructorInTestRule.php) - -```php -final class SomeTest -{ - public function __construct() - { - // ... - } -} -``` - -:x: - -
- -```php -final class SomeTest -{ - public function setUp() - { - // ... - } -} -``` - -:+1: - -
- ## NoDuplicatedShortClassNameRule Class with base "%s" name is already used in "%s". Use unique name to make classes easy to recognize diff --git a/phpunit.xml b/phpunit.xml index 893eef76..a94c8d42 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,7 +2,6 @@ tests - tests/Rules/NoConstructorInTestRule/Fixture tests/Rules/ClassNameRespectsParentSuffixRule/Fixture/ diff --git a/src/Enum/MethodName.php b/src/Enum/MethodName.php index 5a64d0a5..ebb10c10 100644 --- a/src/Enum/MethodName.php +++ b/src/Enum/MethodName.php @@ -6,11 +6,6 @@ final class MethodName { - /** - * @var string - */ - public const CONSTRUCTOR = '__construct'; - /** * @var string */ diff --git a/src/Rules/ClassNameRespectsParentSuffixRule.php b/src/Rules/ClassNameRespectsParentSuffixRule.php index 9d5c2103..24eafb1b 100644 --- a/src/Rules/ClassNameRespectsParentSuffixRule.php +++ b/src/Rules/ClassNameRespectsParentSuffixRule.php @@ -49,7 +49,7 @@ final class ClassNameRespectsParentSuffixRule implements Rule, DocumentedRuleInt ]; /** - * @var class-string[] + * @var string[] */ private array $parentClasses = []; diff --git a/src/Rules/NoConstructorInTestRule.php b/src/Rules/NoConstructorInTestRule.php deleted file mode 100644 index a9ca43c3..00000000 --- a/src/Rules/NoConstructorInTestRule.php +++ /dev/null @@ -1,93 +0,0 @@ - - */ - public function getNodeType(): string - { - return InClassNode::class; - } - - /** - * @param InClassNode $node - * @return RuleError[] - */ - public function processNode(Node $node, Scope $scope): array - { - $classReflection = $node->getClassReflection(); - if (! \str_ends_with($classReflection->getName(), 'Test')) { - return []; - } - - // no parent class, probably not a test case - if (! $classReflection->getParentClass() instanceof ClassReflection) { - return []; - } - - $classLike = $node->getOriginalNode(); - $constructorClassMethod = $classLike->getMethod(MethodName::CONSTRUCTOR); - if (! $constructorClassMethod instanceof ClassMethod) { - return []; - } - - $ruleError = RuleErrorBuilder::message(self::ERROR_MESSAGE) - ->line($constructorClassMethod->getLine()) - ->build(); - - return [$ruleError]; - } - - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition(self::ERROR_MESSAGE, [ - new CodeSample( - <<<'CODE_SAMPLE' -final class SomeTest -{ - public function __construct() - { - // ... - } -} -CODE_SAMPLE - , - <<<'CODE_SAMPLE' -final class SomeTest -{ - public function setUp() - { - // ... - } -} -CODE_SAMPLE - ), - ]); - } -} diff --git a/tests/Rules/NoConstructorInTestRule/Fixture/Test1/SkipTestWithoutConstructTest.php b/tests/Rules/NoConstructorInTestRule/Fixture/Test1/SkipTestWithoutConstructTest.php deleted file mode 100644 index 63bd0bae..00000000 --- a/tests/Rules/NoConstructorInTestRule/Fixture/Test1/SkipTestWithoutConstructTest.php +++ /dev/null @@ -1,15 +0,0 @@ -obj = new stdClass; - } -} diff --git a/tests/Rules/NoConstructorInTestRule/Fixture/Test2/SomeTest.php b/tests/Rules/NoConstructorInTestRule/Fixture/Test2/SomeTest.php deleted file mode 100644 index d139cfed..00000000 --- a/tests/Rules/NoConstructorInTestRule/Fixture/Test2/SomeTest.php +++ /dev/null @@ -1,16 +0,0 @@ -obj = new stdClass; - } -} diff --git a/tests/Rules/NoConstructorInTestRule/Fixture/Test3/SkipTestWithoutParentTest.php b/tests/Rules/NoConstructorInTestRule/Fixture/Test3/SkipTestWithoutParentTest.php deleted file mode 100644 index 5de6c6f7..00000000 --- a/tests/Rules/NoConstructorInTestRule/Fixture/Test3/SkipTestWithoutParentTest.php +++ /dev/null @@ -1,15 +0,0 @@ -obj = new stdClass; - } -} diff --git a/tests/Rules/NoConstructorInTestRule/NoConstructorInTestRuleTest.php b/tests/Rules/NoConstructorInTestRule/NoConstructorInTestRuleTest.php deleted file mode 100644 index 5ab31ca6..00000000 --- a/tests/Rules/NoConstructorInTestRule/NoConstructorInTestRuleTest.php +++ /dev/null @@ -1,44 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/Test1/SkipTestWithoutConstructTest.php', []]; - yield [__DIR__ . '/Fixture/Test3/SkipTestWithoutParentTest.php', []]; - - yield [__DIR__ . '/Fixture/Test2/SomeTest.php', [[NoConstructorInTestRule::ERROR_MESSAGE, 12]]]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(NoConstructorInTestRule::class); - } -} diff --git a/tests/Rules/NoConstructorInTestRule/config/configured_rule.neon b/tests/Rules/NoConstructorInTestRule/config/configured_rule.neon deleted file mode 100644 index 819a0606..00000000 --- a/tests/Rules/NoConstructorInTestRule/config/configured_rule.neon +++ /dev/null @@ -1,5 +0,0 @@ -includes: - - ../../../config/included_services.neon - -rules: - - Symplify\PHPStanRules\Rules\NoConstructorInTestRule