From 608e7f6f53c1c65af65694eda4dcc5bba1d895f3 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 18 Oct 2023 20:43:59 +0200 Subject: [PATCH] Remove CheckNotTestsNamespaceOutsideTestsDirectoryRule as overly specific and strict --- config/test-rules.neon | 1 - docs/rules_overview.md | 52 +--------- phpunit.xml | 1 - ...estsNamespaceOutsideTestsDirectoryRule.php | 96 ------------------- src/ValueObject/Regex.php | 16 ---- ...NamespaceOutsideTestsDirectoryRuleTest.php | 55 ----------- .../FailNotInTestsDirectoryTest.php | 9 -- .../Tests/NameSpaceEndWithTestsFileTest.php | 9 -- .../NameSpaceContainsTestsFileTest.php | 9 -- .../NameSpaceStarttWithTestsFileTest.php | 9 -- ...estsNamespaceInsideTestsDirectoryClass.php | 10 -- .../config/configured_rule.neon | 5 - 12 files changed, 3 insertions(+), 269 deletions(-) delete mode 100644 src/Rules/CheckNotTestsNamespaceOutsideTestsDirectoryRule.php delete mode 100644 src/ValueObject/Regex.php delete mode 100644 tests/Rules/CheckNotTestsNamespaceOutsideTestsDirectoryRule/CheckNotTestsNamespaceOutsideTestsDirectoryRuleTest.php delete mode 100644 tests/Rules/CheckNotTestsNamespaceOutsideTestsDirectoryRule/Fixture/Fail/NotInTestsDirectory/FailNotInTestsDirectoryTest.php delete mode 100644 tests/Rules/CheckNotTestsNamespaceOutsideTestsDirectoryRule/Fixture/Pass/EndWithTests/Tests/NameSpaceEndWithTestsFileTest.php delete mode 100644 tests/Rules/CheckNotTestsNamespaceOutsideTestsDirectoryRule/Fixture/Pass/Tests/ContainsTestsDirectory/NameSpaceContainsTestsFileTest.php delete mode 100644 tests/Rules/CheckNotTestsNamespaceOutsideTestsDirectoryRule/Fixture/Tests/InTestsDirectory/NameSpaceStarttWithTestsFileTest.php delete mode 100644 tests/Rules/CheckNotTestsNamespaceOutsideTestsDirectoryRule/Fixture/Tests/SkipTestsNamespaceInsideTestsDirectoryClass.php delete mode 100644 tests/Rules/CheckNotTestsNamespaceOutsideTestsDirectoryRule/config/configured_rule.neon diff --git a/config/test-rules.neon b/config/test-rules.neon index 3f3cf920..daf6ec2e 100644 --- a/config/test-rules.neon +++ b/config/test-rules.neon @@ -1,3 +1,2 @@ rules: - Symplify\PHPStanRules\Rules\NoConstructorInTestRule - - Symplify\PHPStanRules\Rules\CheckNotTestsNamespaceOutsideTestsDirectoryRule diff --git a/docs/rules_overview.md b/docs/rules_overview.md index 572f7cfb..0b113dde 100644 --- a/docs/rules_overview.md +++ b/docs/rules_overview.md @@ -1,4 +1,4 @@ -# 56 Rules Overview +# 55 Rules Overview ## AnnotateRegexClassConstWithRegexLinkRule @@ -97,52 +97,6 @@ class Baz
-## CheckNotTestsNamespaceOutsideTestsDirectoryRule - -"*Test.php" file cannot be located outside "Tests" namespace - -- class: [`Symplify\PHPStanRules\Rules\CheckNotTestsNamespaceOutsideTestsDirectoryRule`](../src/Rules/CheckNotTestsNamespaceOutsideTestsDirectoryRule.php) - -```php -// file: "SomeTest.php -namespace App; - -class SomeTest -{ -} -``` - -:x: - -
- -```php -// file: "SomeTest.php -namespace App\Tests; - -class SomeTest -{ -} - -// file: "AnotherTest.php -namespace App\Tests\Features; - -class AnotherTest -{ -} - -// file: "SomeOtherTest.php -namespace Tests\Features; - -class SomeOtherTest -{ -} -``` - -:+1: - -
- ## CheckRequiredInterfaceInContractNamespaceRule Interface must be located in "Contract" or "Contracts" namespace @@ -1458,7 +1412,7 @@ Do not name "%s", shorter than %d chars :wrench: **configure it!** -- class: [`Symplify\PHPStanRules\ObjectCalisthenics\Rules\NoShortNameRule`](../packages/ObjectCalisthenics/Rules/NoShortNameRule.php) +- class: [`Symplify\PHPStanRules\ObjectCalisthenics\Rules\NoShortNameRule`](../src/ObjectCalisthenics/Rules/NoShortNameRule.php) ```yaml services: @@ -1947,7 +1901,7 @@ final class SomeException extends Exception Use invokable controller with `__invoke()` method instead of named action method -- class: [`Symplify\PHPStanRules\Symfony\Rules\RequireInvokableControllerRule`](../packages/Symfony/Rules/RequireInvokableControllerRule.php) +- class: [`Symplify\PHPStanRules\Symfony\Rules\RequireInvokableControllerRule`](../src/Symfony/Rules/RequireInvokableControllerRule.php) ```php use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; diff --git a/phpunit.xml b/phpunit.xml index 4ffeae8e..893eef76 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -4,6 +4,5 @@ tests tests/Rules/NoConstructorInTestRule/Fixture tests/Rules/ClassNameRespectsParentSuffixRule/Fixture/ - tests/Rules/CheckNotTestsNamespaceOutsideTestsDirectoryRule/Fixture diff --git a/src/Rules/CheckNotTestsNamespaceOutsideTestsDirectoryRule.php b/src/Rules/CheckNotTestsNamespaceOutsideTestsDirectoryRule.php deleted file mode 100644 index 034c3bf9..00000000 --- a/src/Rules/CheckNotTestsNamespaceOutsideTestsDirectoryRule.php +++ /dev/null @@ -1,96 +0,0 @@ - - */ - public function getNodeType(): string - { - return Namespace_::class; - } - - /** - * @param Namespace_ $node - * @return string[] - */ - public function processNode(Node $node, Scope $scope): array - { - if (! $node->name instanceof Name) { - return []; - } - - $matches = Strings::match($node->name->toString(), Regex::TESTS_PART_REGEX); - if ($matches !== null) { - return []; - } - - if (! \str_ends_with($scope->getFile(), 'Test.php')) { - return []; - } - - return [self::ERROR_MESSAGE]; - } - - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition(self::ERROR_MESSAGE, [ - new CodeSample( - <<<'CODE_SAMPLE' -// file: "SomeTest.php -namespace App; - -class SomeTest -{ -} -CODE_SAMPLE - , - <<<'CODE_SAMPLE' -// file: "SomeTest.php -namespace App\Tests; - -class SomeTest -{ -} - -// file: "AnotherTest.php -namespace App\Tests\Features; - -class AnotherTest -{ -} - -// file: "SomeOtherTest.php -namespace Tests\Features; - -class SomeOtherTest -{ -} -CODE_SAMPLE - ), - ]); - } -} diff --git a/src/ValueObject/Regex.php b/src/ValueObject/Regex.php deleted file mode 100644 index bf6fbf83..00000000 --- a/src/ValueObject/Regex.php +++ /dev/null @@ -1,16 +0,0 @@ -analyse([$filePath], $expectedErrorsWithLines); - } - - /** - * @return Iterator> - */ - public static function provideData(): Iterator - { - // expect error - yield [ - __DIR__ . '/Fixture/Fail/NotInTestsDirectory/FailNotInTestsDirectoryTest.php', - [[CheckNotTestsNamespaceOutsideTestsDirectoryRule::ERROR_MESSAGE, 5]]]; - - // Skip - yield [__DIR__ . '/Fixture/Tests/SkipTestsNamespaceInsideTestsDirectoryClass.php', []]; - - // Good - yield [__DIR__ . '/Fixture/Pass/EndWithTests/Tests/NameSpaceEndWithTestsFileTest.php', []]; - yield [__DIR__ . '/Fixture/Pass/Tests/ContainsTestsDirectory/NameSpaceContainsTestsFileTest.php', []]; - yield [__DIR__ . '/Fixture/Tests/InTestsDirectory/NameSpaceStarttWithTestsFileTest.php', []]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(CheckNotTestsNamespaceOutsideTestsDirectoryRule::class); - } -} diff --git a/tests/Rules/CheckNotTestsNamespaceOutsideTestsDirectoryRule/Fixture/Fail/NotInTestsDirectory/FailNotInTestsDirectoryTest.php b/tests/Rules/CheckNotTestsNamespaceOutsideTestsDirectoryRule/Fixture/Fail/NotInTestsDirectory/FailNotInTestsDirectoryTest.php deleted file mode 100644 index 55f23dd6..00000000 --- a/tests/Rules/CheckNotTestsNamespaceOutsideTestsDirectoryRule/Fixture/Fail/NotInTestsDirectory/FailNotInTestsDirectoryTest.php +++ /dev/null @@ -1,9 +0,0 @@ -