From c7c2bc36c8630619998c46552d173053d6e3fd40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 5 Jan 2025 23:12:38 +0100 Subject: [PATCH] Fix: Remove abstract test case --- .php-cs-fixer.fixture.php | 22 +- composer.json | 1 + composer.lock | 2 +- .../Classes/FinalRule/AbstractClass.php | 9 + .../Classes/FinalRule/ExampleInterface.php | 9 + .../Classes/FinalRule/ExampleTrait.php | 9 + .../FinalRule/Failure/AbstractClass.php | 9 - test/Fixture/Classes/FinalRule/FinalClass.php | 9 + .../FinalClassWithAnonymousClass.php | 2 +- .../NeitherAbstractNorFinalClass.php | 2 +- ...inalClassWithAliasedOrmEntityAttribute.php | 2 +- ...ssWithEntityAnnotationInInlineDocBlock.php | 2 +- ...ithEntityAnnotationInMultilineDocBlock.php | 2 +- ...ithOrmEntityAnnotationInInlineDocBlock.php | 2 +- ...OrmEntityAnnotationInMultilineDocBlock.php | 2 +- ...appingEntityAnnotationInInlineDocBlock.php | 2 +- ...ingEntityAnnotationInMultilineDocBlock.php | 2 +- ...ifiedDoctrineOrmMappingEntityAttribute.php | 2 +- ...FinalClassWithQualifiedEntityAttribute.php | 2 +- ...assWithQualifiedMappingEntityAttribute.php | 2 +- ...WithQualifiedOrmMappingEntityAttribute.php | 2 +- ...ifiedDoctrineOrmMappingEntityAttribute.php | 2 +- ...nalClassWithUnqualifiedEntityAttribute.php | 2 +- ...ClassWithUnqualifiedOrmEntityAttribute.php | 2 +- ...thUnqualifiedOrmMappingEntityAttribute.php | 2 +- ...ithoutEntityAnnotationInInlineDocBlock.php | 2 +- ...outEntityAnnotationInMultilineDocBlock.php | 2 +- ...outOrmEntityAnnotationInInlineDocBlock.php | 2 +- ...OrmEntityAnnotationInMultilineDocBlock.php | 2 +- .../FinalRule/Success/ExampleInterface.php | 9 - .../FinalRule/Success/ExampleTrait.php | 9 - .../Classes/FinalRule/Success/FinalClass.php | 9 - .../{Success => }/TraitWithAnonymousClass.php | 2 +- .../anonymous-class.php => script.php} | 2 +- .../Failure/AbstractClass.php | 9 - .../Failure/NeitherAbstractNorFinalClass.php | 9 - .../Success/ExampleInterface.php | 9 - .../Success/ExampleTrait.php | 9 - .../Success/FinalClass.php | 9 - .../Success/FinalClassWithAnonymousClass.php | 18 -- .../Success/TraitWithAnonymousClass.php | 18 -- .../Success/anonymous-class.php | 12 - .../Failure/AbstractClass.php | 9 - .../Failure/NeitherAbstractNorFinalClass.php | 9 - .../Success/ExampleInterface.php | 9 - .../Success/ExampleTrait.php | 9 - .../Success/FinalClass.php | 9 - .../Success/FinalClassWithAnonymousClass.php | 18 -- ...herAbstractNorFinalClassButWhitelisted.php | 9 - .../Success/TraitWithAnonymousClass.php | 18 -- .../Success/anonymous-class.php | 12 - .../ClassExtendingOtherClass.php | 2 +- ...ClassExtendingPhpUnitFrameworkTestCase.php | 2 +- .../{Success => }/ExampleClass.php | 2 +- .../{Success => }/ExampleInterface.php | 2 +- .../anonymous-class-extending-other-class.php | 12 - .../InterfaceExtendingOtherInterface.php | 4 +- .../{Failure => }/OtherClass.php | 2 +- .../{Success => }/OtherInterface.php | 2 +- .../anonymous-class.php => script.php} | 9 +- .../Failure/ClassExtendingOtherClass.php | 9 - .../Failure/OtherClass.php | 9 - .../anonymous-class-extending-other-class.php | 12 - .../Success/ClassAllowedToBeExtended.php | 9 - ...ClassExtendingClassAllowedToBeExtended.php | 9 - ...ClassExtendingPhpUnitFrameworkTestCase.php | 11 - .../Success/ExampleClass.php | 9 - .../Success/ExampleInterface.php | 9 - .../InterfaceExtendingOtherInterface.php | 9 - .../Success/OtherInterface.php | 9 - ...extending-class-allowed-to-be-extended.php | 12 - .../Success/anonymous-class.php | 12 - .../{Failure => }/AbstractTestCase.php | 2 +- ...ExtendingAbstractTestCaseWithoutSuffix.php | 9 + .../ConcreteTestCaseWithSuffixTest.php | 2 +- ....php => ConcreteTestCaseWithoutSuffix.php} | 4 +- ...ndingAbstractTestCaseWithoutTestSuffix.php | 9 - .../ConcreteTestCaseWithoutTestSuffix.php | 15 - .../Success/ImplicitlyAbstractTestCase.php | 12 - ...-with-nullable-return-type-declaration.php | 9 - ...ble-union-type-return-type-declaration.php | 9 - .../closure-with-return-type-declaration.php | 9 - ...losure-without-return-type-declaration.php | 9 - .../script.php | 21 ++ ...with-parameter-with-null-default-value.php | 9 - ...amespace-referenced-null-default-value.php | 9 - ...wrongly-capitalized-null-default-value.php | 9 - ...-parameter-with-non-null-default-value.php | 9 - ...e-with-parameter-without-default-value.php | 9 - .../Success/closure-without-parameters.php | 8 - .../script.php | 28 ++ ...rameter-with-nullable-type-declaration.php | 9 - ...r-with-nullable-union-type-declaration.php | 9 - ...e-with-parameter-with-type-declaration.php | 9 - ...ith-parameter-without-type-declaration.php | 9 - .../Success/closure-without-parameters.php | 8 - .../script.php | 24 ++ .../Failure/compact-used-with-alias.php | 15 - .../compact-used-with-correct-case.php | 13 - .../compact-used-with-incorrect-case.php | 13 - .../compact-not-used.php => script.php} | 21 +- .../Success/error-suppression-not-used.php | 7 - .../error-suppression-used.php => script.php} | 4 +- .../Failure/eval-used-with-correct-case.php | 7 - .../Failure/eval-used-with-incorrect-case.php | 7 - .../{Success/eval-not-used.php => script.php} | 6 +- .../Failure/isset-used-with-correct-case.php | 9 - .../isset-used-with-incorrect-case.php | 9 - .../isset-not-used.php => script.php} | 10 +- .../{Success => }/file-empty.php | 0 ...re-strict-types-off-and-invalid-casing.php | 0 ...strict-types-off-and-multiple-declares.php | 0 ...h-comment-and-declare-strict-types-off.php | 0 ...are-strict-types-on-and-invalid-casing.php | 0 ...-strict-types-on-and-multiple-declares.php | 0 ...ict-types-on-and-namespace-declaration.php | 2 +- ...th-comment-and-declare-strict-types-on.php | 0 ...re-strict-types-off-and-invalid-casing.php | 0 ...strict-types-off-and-multiple-declares.php | 0 .../file-with-declare-strict-types-off.php | 0 ...are-strict-types-on-and-invalid-casing.php | 0 ...-strict-types-on-and-multiple-declares.php | 0 ...ict-types-on-and-namespace-declaration.php | 2 +- .../file-with-declare-strict-types-on.php | 0 .../{Failure => }/file-with-declare-ticks.php | 0 ...re-strict-types-off-and-invalid-casing.php | 0 ...strict-types-off-and-multiple-declares.php | 0 ...doc-block-and-declare-strict-types-off.php | 0 ...are-strict-types-on-and-invalid-casing.php | 0 ...-strict-types-on-and-multiple-declares.php | 0 ...ict-types-on-and-namespace-declaration.php | 2 +- ...-doc-block-and-declare-strict-types-on.php | 0 ...other-one-text-line-before-opening-tag.php | 0 ...h-shebang-and-declare-strict-types-off.php | 0 ...th-shebang-and-declare-strict-types-on.php | 0 .../file-with-text-before-opening-tag.php | 0 ...strict-types-and-namespace-declaration.php | 2 +- .../file-without-declare-strict-types.php | 0 ...-with-nullable-return-type-declaration.php | 10 - ...nullable-union-return-type-declaration.php | 10 - .../function-with-return-type-declaration.php | 10 - ...nction-without-return-type-declaration.php | 10 - .../script.php | 25 ++ ...with-parameter-with-null-default-value.php | 10 - ...amespace-referenced-null-default-value.php | 10 - ...wrongly-capitalized-null-default-value.php | 10 - ...-parameter-with-non-null-default-value.php | 10 - ...n-with-parameter-without-default-value.php | 10 - .../Success/function-without-parameters.php | 9 - .../script.php | 34 +++ ...rameter-with-nullable-type-declaration.php | 10 - ...r-with-nullable-union-type-declaration.php | 10 - ...n-with-parameter-with-type-declaration.php | 10 - ...ith-parameter-without-type-declaration.php | 10 - .../Success/function-without-parameters.php | 9 - .../script.php | 29 ++ .../AbstractClassWithAbstractMethod.php | 2 +- .../AbstractClassWithFinalProtectedMethod.php | 2 +- .../AbstractClassWithFinalPublicMethod.php | 2 +- .../AbstractClassWithNonFinalConstructor.php | 2 +- .../AbstractClassWithPrivateMethod.php | 2 +- .../AbstractClassWithProtectedMethod.php | 2 +- ...ndEmbeddableAnnotationInInlineDocBlock.php | 2 +- ...mbeddableAnnotationInMultilineDocBlock.php | 2 +- ...hProtectedMethodAndEmbeddableAttribute.php | 2 +- ...hodAndEntityAnnotationInInlineDocBlock.php | 2 +- ...AndEntityAnnotationInMultilineDocBlock.php | 2 +- ...sWithProtectedMethodAndEntityAttribute.php | 2 +- ...rmEmbeddableAnnotationInInlineDocBlock.php | 2 +- ...mbeddableAnnotationInMultilineDocBlock.php | 2 +- ...AndOrmEntityAnnotationInInlineDocBlock.php | 2 +- ...OrmEntityAnnotationInMultilineDocBlock.php | 2 +- ...ngEmbeddableAnnotationInInlineDocBlock.php | 2 +- ...mbeddableAnnotationInMultilineDocBlock.php | 2 +- ...appingEntityAnnotationInInlineDocBlock.php | 2 +- ...ingEntityAnnotationInMultilineDocBlock.php | 2 +- .../AbstractClassWithPublicMethod.php | 2 +- ...ndEmbeddableAnnotationInInlineDocBlock.php | 2 +- ...mbeddableAnnotationInMultilineDocBlock.php | 2 +- ...WithPublicMethodAndEmbeddableAttribute.php | 2 +- ...hodAndEntityAnnotationInInlineDocBlock.php | 2 +- ...AndEntityAnnotationInMultilineDocBlock.php | 2 +- ...lassWithPublicMethodAndEntityAttribute.php | 2 +- ...rmEmbeddableAnnotationInInlineDocBlock.php | 2 +- ...mbeddableAnnotationInMultilineDocBlock.php | 2 +- ...AndOrmEntityAnnotationInInlineDocBlock.php | 2 +- ...OrmEntityAnnotationInMultilineDocBlock.php | 2 +- ...ngEmbeddableAnnotationInInlineDocBlock.php | 2 +- ...mbeddableAnnotationInMultilineDocBlock.php | 2 +- ...appingEntityAnnotationInInlineDocBlock.php | 2 +- ...ingEntityAnnotationInMultilineDocBlock.php | 2 +- .../InterfaceWithPublicMethod.php | 2 +- ...orInClassWithParameterWithDefaultValue.php | 2 +- ...nClassWithParameterWithoutDefaultValue.php | 2 +- .../ConstructorInClassWithoutParameters.php | 2 +- ...orInTraitWithParameterWithDefaultValue.php | 2 +- ...nTraitWithParameterWithoutDefaultValue.php | 2 +- .../ConstructorInTraitWithoutParameters.php | 2 +- ...onInClassWithParameterWithDefaultValue.php | 2 +- ...lass-with-parameter-with-default-value.php | 11 - ...lass-with-parameter-with-default-value.php | 11 - ...odInClassWithParameterWithDefaultValue.php | 2 +- ...odInTraitWithParameterWithDefaultValue.php | 2 +- ...s-with-parameter-without-default-value.php | 11 - ...-in-anonymous-class-without-parameters.php | 11 - ...lass-with-parameter-with-default-value.php | 11 - .../script.php | 35 +++ ...ClassWithNullableReturnTypeDeclaration.php | 18 -- ...WithNullableUnionReturnTypeDeclaration.php | 18 -- ...ClassWithNullableReturnTypeDeclaration.php | 2 +- ...WithNullableUnionReturnTypeDeclaration.php | 2 +- ...MethodInClassWithReturnTypeDeclaration.php | 2 +- ...hodInClassWithoutReturnTypeDeclaration.php | 2 +- ...rfaceWithNullableReturnTypeDeclaration.php | 2 +- ...WithNullableUnionReturnTypeDeclaration.php | 2 +- ...odInInterfaceWithReturnTypeDeclaration.php | 2 +- ...nInterfaceWithoutReturnTypeDeclaration.php | 2 +- ...TraitWithNullableReturnTypeDeclaration.php | 2 +- ...MethodInTraitWithReturnTypeDeclaration.php | 2 +- ...hodInTraitWithoutReturnTypeDeclaration.php | 2 +- ...nonymousClassWithReturnTypeDeclaration.php | 18 -- ...ymousClassWithoutReturnTypeDeclaration.php | 18 -- .../script.php | 33 +++ .../ClassImplementingContainerInterface.php | 4 +- ...WithParameterWithSelfAsTypeDeclaration.php | 2 +- ...ingContainerInterfaceAsTypeDeclaration.php | 2 +- ...ceAsTypeDeclarationWhereNameIsExcluded.php | 4 +- ...ithContainerInterfaceAsTypeDeclaration.php | 2 +- ...ingContainerInterfaceAsTypeDeclaration.php | 2 +- ...dWithParameterWithOtherTypeDeclaration.php | 2 +- .../ClassWithMethodWithoutParameter.php | 2 +- .../{Success => }/ContainerInterface.php | 2 +- ...ontainer-interface-as-type-declaration.php | 12 - ...ontainer-interface-as-type-declaration.php | 14 - ...ontainer-interface-as-type-declaration.php | 12 - .../InterfaceExtendingContainerInterface.php | 2 +- ...ithContainerInterfaceAsTypeDeclaration.php | 2 +- ...ceAsTypeDeclarationWhereNameIsExcluded.php | 2 +- ...dWithParameterWithOtherTypeDeclaration.php | 2 +- .../InterfaceWithMethodWithoutParameter.php | 2 +- ...ype-declaration-where-name-is-excluded.php | 12 - ...-parameter-with-other-type-declaration.php | 11 - ...us-class-with-method-without-parameter.php | 11 - .../script.php | 46 +++ ...with-parameter-with-null-default-value.php | 12 - ...amespace-referenced-null-default-value.php | 12 - ...wrongly-capitalized-null-default-value.php | 12 - ...ssWithParameterWithNonNullDefaultValue.php | 2 +- ...ClassWithParameterWithNullDefaultValue.php | 2 +- ...ootNamespaceReferencedNullDefaultValue.php | 2 +- ...WithWronglyCapitalizedNullDefaultValue.php | 2 +- ...nClassWithParameterWithoutDefaultValue.php | 2 +- .../MethodInClassWithoutParameters.php | 2 +- ...ceWithParameterWithNonNullDefaultValue.php | 2 +- ...rfaceWithParameterWithNullDefaultValue.php | 2 +- ...ootNamespaceReferencedNullDefaultValue.php | 2 +- ...WithWronlgyCapitalizedNullDefaultValue.php | 2 +- ...erfaceWithParameterWithoutDefaultValue.php | 2 +- .../MethodInInterfaceWithoutParameters.php | 2 +- ...odInTraitWithParameterWithDefaultValue.php | 2 +- ...itWithParameterWithNonNullDefaultValue.php | 2 +- ...ootNamespaceReferencedNullDefaultValue.php | 2 +- ...WithWronlgyCapitalizedNullDefaultValue.php | 2 +- ...nTraitWithParameterWithoutDefaultValue.php | 2 +- .../MethodInTraitWithoutParameters.php | 2 +- ...-parameter-with-non-null-default-value.php | 12 - ...s-with-parameter-without-default-value.php | 12 - ...-in-anonymous-class-without-parameters.php | 11 - .../script.php | 46 +++ ...rameter-with-nullable-type-declaration.php | 12 - ...r-with-nullable-union-type-declaration.php | 12 - ...thParameterWithNullableTypeDeclaration.php | 2 +- ...ameterWithNullableUnionTypeDeclaration.php | 2 +- ...nClassWithParameterWithTypeDeclaration.php | 2 +- ...assWithParameterWithoutTypeDeclaration.php | 2 +- .../MethodInClassWithoutParameters.php | 2 +- ...thParameterWithNullableTypeDeclaration.php | 2 +- ...ameterWithNullableUnionTypeDeclaration.php | 2 +- ...erfaceWithParameterWithTypeDeclaration.php | 2 +- ...aceWithParameterWithoutTypeDeclaration.php | 2 +- .../MethodInInterfaceWithoutParameters.php | 2 +- ...thParameterWithNullableTypeDeclaration.php | 2 +- ...nTraitWithParameterWithTypeDeclaration.php | 2 +- ...aitWithParameterWithoutTypeDeclaration.php | 2 +- .../MethodInTraitWithoutParameters.php | 2 +- ...s-with-parameter-with-type-declaration.php | 12 - ...ith-parameter-without-type-declaration.php | 12 - ...-in-anonymous-class-without-parameters.php | 11 - .../script.php | 40 +++ ...endingAbstractClassWithProtectedMethod.php | 2 +- .../AbstractClassWithProtectedMethod.php | 2 +- .../ClassWithProtectedMethod.php | 2 +- .../FinalClassWithPrivateMethod.php | 2 +- .../FinalClassWithProtectedMethod.php | 2 +- ...sExtendingClassWithSameProtectedMethod.php | 2 +- ...dExtendingClassWithSameProtectedMethod.php | 2 +- ...FinalClassWithProtectedMethodFromTrait.php | 2 +- .../FinalClassWithPublicMethod.php | 2 +- .../TraitWithProtectedMethod.php | 2 +- ...lassWithProtectedMethod.php => script.php} | 4 +- .../Failure/switch-used-with-correct-case.php | 2 +- .../switch-used-with-incorrect-case.php | 2 +- .../NoSwitchRule/Success/switch-not-used.php | 2 +- test/Integration/AbstractTestCase.php | 2 + test/Integration/Classes/FinalRuleTest.php | 264 ++++++++++++++---- ...inalRuleWithAbstractClassesAllowedTest.php | 80 ------ .../Classes/FinalRuleWithAttributesTest.php | 108 ------- .../FinalRuleWithExcludedClassNamesTest.php | 92 ------ .../Integration/Classes/NoExtendsRuleTest.php | 70 +++-- ...RuleWithClassesAllowedToBeExtendedTest.php | 90 ------ .../Framework/TestCaseWithSuffixRuleTest.php | 48 +--- ...oNullableReturnTypeDeclarationRuleTest.php | 47 +--- ...oParameterWithNullDefaultValueRuleTest.php | 53 +--- ...terWithNullableTypeDeclarationRuleTest.php | 48 +--- .../Expressions/NoCompactRuleTest.php | 51 +--- .../NoErrorSuppressionRuleTest.php | 41 +-- .../Expressions/NoEvalRuleTest.php | 46 +-- .../Expressions/NoIssetRuleTest.php | 46 +-- .../Files/DeclareStrictTypesRuleTest.php | 94 +------ ...oNullableReturnTypeDeclarationRuleTest.php | 51 +--- ...oParameterWithNullDefaultValueRuleTest.php | 59 ++-- ...terWithNullableTypeDeclarationRuleTest.php | 52 +--- .../Methods/FinalInAbstractClassRuleTest.php | 79 +----- ...uctorParameterWithDefaultValueRuleTest.php | 79 ++---- ...oNullableReturnTypeDeclarationRuleTest.php | 87 ++---- ...erWithContainerTypeDeclarationRuleTest.php | 114 +++----- ...oParameterWithNullDefaultValueRuleTest.php | 114 ++------ ...terWithNullableTypeDeclarationRuleTest.php | 90 ++---- .../Methods/PrivateInFinalClassRuleTest.php | 61 ++-- .../Statements/NoSwitchRuleTest.php | 42 +-- test/Util/Helper.php | 35 +++ 331 files changed, 1208 insertions(+), 2720 deletions(-) create mode 100644 test/Fixture/Classes/FinalRule/AbstractClass.php create mode 100644 test/Fixture/Classes/FinalRule/ExampleInterface.php create mode 100644 test/Fixture/Classes/FinalRule/ExampleTrait.php delete mode 100644 test/Fixture/Classes/FinalRule/Failure/AbstractClass.php create mode 100644 test/Fixture/Classes/FinalRule/FinalClass.php rename test/Fixture/Classes/FinalRule/{Success => }/FinalClassWithAnonymousClass.php (78%) rename test/Fixture/Classes/FinalRule/{Failure => }/NeitherAbstractNorFinalClass.php (50%) rename test/Fixture/Classes/{FinalRuleWithAttributes/Success => FinalRule}/NonFinalClassWithAliasedOrmEntityAttribute.php (61%) rename test/Fixture/Classes/FinalRule/{Success => }/NonFinalClassWithEntityAnnotationInInlineDocBlock.php (59%) rename test/Fixture/Classes/FinalRule/{Success => }/NonFinalClassWithEntityAnnotationInMultilineDocBlock.php (65%) rename test/Fixture/Classes/FinalRule/{Success => }/NonFinalClassWithOrmEntityAnnotationInInlineDocBlock.php (61%) rename test/Fixture/Classes/FinalRule/{Success => }/NonFinalClassWithOrmEntityAnnotationInMultilineDocBlock.php (67%) rename test/Fixture/Classes/FinalRule/{Success => }/NonFinalClassWithOrmMappingEntityAnnotationInInlineDocBlock.php (64%) rename test/Fixture/Classes/FinalRule/{Success => }/NonFinalClassWithOrmMappingEntityAnnotationInMultilineDocBlock.php (70%) rename test/Fixture/Classes/{FinalRuleWithAttributes/Success => FinalRule}/NonFinalClassWithQualifiedDoctrineOrmMappingEntityAttribute.php (61%) rename test/Fixture/Classes/{FinalRuleWithAttributes/Success => FinalRule}/NonFinalClassWithQualifiedEntityAttribute.php (60%) rename test/Fixture/Classes/{FinalRuleWithAttributes/Success => FinalRule}/NonFinalClassWithQualifiedMappingEntityAttribute.php (61%) rename test/Fixture/Classes/{FinalRuleWithAttributes/Success => FinalRule}/NonFinalClassWithQualifiedOrmMappingEntityAttribute.php (61%) rename test/Fixture/Classes/{FinalRuleWithAttributes/Failure => FinalRule}/NonFinalClassWithUnqualifiedDoctrineOrmMappingEntityAttribute.php (61%) rename test/Fixture/Classes/{FinalRuleWithAttributes/Failure => FinalRule}/NonFinalClassWithUnqualifiedEntityAttribute.php (53%) rename test/Fixture/Classes/{FinalRuleWithAttributes/Failure => FinalRule}/NonFinalClassWithUnqualifiedOrmEntityAttribute.php (55%) rename test/Fixture/Classes/{FinalRuleWithAttributes/Failure => FinalRule}/NonFinalClassWithUnqualifiedOrmMappingEntityAttribute.php (58%) rename test/Fixture/Classes/FinalRule/{Failure => }/NonFinalClassWithoutEntityAnnotationInInlineDocBlock.php (60%) rename test/Fixture/Classes/FinalRule/{Failure => }/NonFinalClassWithoutEntityAnnotationInMultilineDocBlock.php (66%) rename test/Fixture/Classes/FinalRule/{Failure => }/NonFinalClassWithoutOrmEntityAnnotationInInlineDocBlock.php (61%) rename test/Fixture/Classes/FinalRule/{Failure => }/NonFinalClassWithoutOrmEntityAnnotationInMultilineDocBlock.php (67%) delete mode 100644 test/Fixture/Classes/FinalRule/Success/ExampleInterface.php delete mode 100644 test/Fixture/Classes/FinalRule/Success/ExampleTrait.php delete mode 100644 test/Fixture/Classes/FinalRule/Success/FinalClass.php rename test/Fixture/Classes/FinalRule/{Success => }/TraitWithAnonymousClass.php (77%) rename test/Fixture/Classes/FinalRule/{Success/anonymous-class.php => script.php} (64%) delete mode 100644 test/Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Failure/AbstractClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Failure/NeitherAbstractNorFinalClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/ExampleInterface.php delete mode 100644 test/Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/ExampleTrait.php delete mode 100644 test/Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/FinalClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/FinalClassWithAnonymousClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/TraitWithAnonymousClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/anonymous-class.php delete mode 100644 test/Fixture/Classes/FinalRuleWithExcludedClassNames/Failure/AbstractClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithExcludedClassNames/Failure/NeitherAbstractNorFinalClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithExcludedClassNames/Success/ExampleInterface.php delete mode 100644 test/Fixture/Classes/FinalRuleWithExcludedClassNames/Success/ExampleTrait.php delete mode 100644 test/Fixture/Classes/FinalRuleWithExcludedClassNames/Success/FinalClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithExcludedClassNames/Success/FinalClassWithAnonymousClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithExcludedClassNames/Success/NeitherAbstractNorFinalClassButWhitelisted.php delete mode 100644 test/Fixture/Classes/FinalRuleWithExcludedClassNames/Success/TraitWithAnonymousClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithExcludedClassNames/Success/anonymous-class.php rename test/Fixture/Classes/NoExtendsRule/{Failure => }/ClassExtendingOtherClass.php (92%) rename test/Fixture/Classes/NoExtendsRule/{Success => }/ClassExtendingPhpUnitFrameworkTestCase.php (94%) rename test/Fixture/Classes/NoExtendsRule/{Success => }/ExampleClass.php (90%) rename test/Fixture/Classes/NoExtendsRule/{Success => }/ExampleInterface.php (90%) delete mode 100644 test/Fixture/Classes/NoExtendsRule/Failure/anonymous-class-extending-other-class.php rename test/Fixture/Classes/NoExtendsRule/{Success => }/InterfaceExtendingOtherInterface.php (64%) rename test/Fixture/Classes/NoExtendsRule/{Failure => }/OtherClass.php (90%) rename test/Fixture/Classes/NoExtendsRule/{Success => }/OtherInterface.php (90%) rename test/Fixture/Classes/NoExtendsRule/{Success/anonymous-class.php => script.php} (58%) delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Failure/ClassExtendingOtherClass.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Failure/OtherClass.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Failure/anonymous-class-extending-other-class.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ClassAllowedToBeExtended.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ClassExtendingClassAllowedToBeExtended.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ClassExtendingPhpUnitFrameworkTestCase.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ExampleClass.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ExampleInterface.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/InterfaceExtendingOtherInterface.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/OtherInterface.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/anonymous-class-extending-class-allowed-to-be-extended.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/anonymous-class.php rename test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/{Failure => }/AbstractTestCase.php (82%) create mode 100644 test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/ConcreteTestCaseExtendingAbstractTestCaseWithoutSuffix.php rename test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/{Success => }/ConcreteTestCaseWithSuffixTest.php (88%) rename test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/{Success/ExplicitlyAbstractTestCase.php => ConcreteTestCaseWithoutSuffix.php} (55%) delete mode 100644 test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Failure/ConcreteTestCaseExtendingAbstractTestCaseWithoutTestSuffix.php delete mode 100644 test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Failure/ConcreteTestCaseWithoutTestSuffix.php delete mode 100644 test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Success/ImplicitlyAbstractTestCase.php delete mode 100644 test/Fixture/Closures/NoNullableReturnTypeDeclarationRule/Failure/closure-with-nullable-return-type-declaration.php delete mode 100644 test/Fixture/Closures/NoNullableReturnTypeDeclarationRule/Failure/closure-with-nullable-union-type-return-type-declaration.php delete mode 100644 test/Fixture/Closures/NoNullableReturnTypeDeclarationRule/Success/closure-with-return-type-declaration.php delete mode 100644 test/Fixture/Closures/NoNullableReturnTypeDeclarationRule/Success/closure-without-return-type-declaration.php create mode 100644 test/Fixture/Closures/NoNullableReturnTypeDeclarationRule/script.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullDefaultValueRule/Failure/closure-with-parameter-with-null-default-value.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullDefaultValueRule/Failure/closure-with-parameter-with-root-namespace-referenced-null-default-value.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullDefaultValueRule/Failure/closure-with-parameter-with-wrongly-capitalized-null-default-value.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullDefaultValueRule/Success/closure-with-parameter-with-non-null-default-value.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullDefaultValueRule/Success/closure-with-parameter-without-default-value.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullDefaultValueRule/Success/closure-without-parameters.php create mode 100644 test/Fixture/Closures/NoParameterWithNullDefaultValueRule/script.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Failure/closure-with-parameter-with-nullable-type-declaration.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Failure/closure-with-parameter-with-nullable-union-type-declaration.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Success/closure-with-parameter-with-type-declaration.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Success/closure-with-parameter-without-type-declaration.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Success/closure-without-parameters.php create mode 100644 test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/script.php delete mode 100644 test/Fixture/Expressions/NoCompactRule/Failure/compact-used-with-alias.php delete mode 100644 test/Fixture/Expressions/NoCompactRule/Failure/compact-used-with-correct-case.php delete mode 100644 test/Fixture/Expressions/NoCompactRule/Failure/compact-used-with-incorrect-case.php rename test/Fixture/Expressions/NoCompactRule/{Success/compact-not-used.php => script.php} (53%) delete mode 100644 test/Fixture/Expressions/NoErrorSuppressionRule/Success/error-suppression-not-used.php rename test/Fixture/Expressions/NoErrorSuppressionRule/{Failure/error-suppression-used.php => script.php} (75%) delete mode 100644 test/Fixture/Expressions/NoEvalRule/Failure/eval-used-with-correct-case.php delete mode 100644 test/Fixture/Expressions/NoEvalRule/Failure/eval-used-with-incorrect-case.php rename test/Fixture/Expressions/NoEvalRule/{Success/eval-not-used.php => script.php} (77%) delete mode 100644 test/Fixture/Expressions/NoIssetRule/Failure/isset-used-with-correct-case.php delete mode 100644 test/Fixture/Expressions/NoIssetRule/Failure/isset-used-with-incorrect-case.php rename test/Fixture/Expressions/NoIssetRule/{Success/isset-not-used.php => script.php} (67%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-empty.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-comment-and-declare-strict-types-off-and-invalid-casing.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-comment-and-declare-strict-types-off-and-multiple-declares.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-comment-and-declare-strict-types-off.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-comment-and-declare-strict-types-on-and-invalid-casing.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-comment-and-declare-strict-types-on-and-multiple-declares.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-comment-and-declare-strict-types-on-and-namespace-declaration.php (84%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-comment-and-declare-strict-types-on.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-declare-strict-types-off-and-invalid-casing.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-declare-strict-types-off-and-multiple-declares.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-declare-strict-types-off.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-declare-strict-types-on-and-invalid-casing.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-declare-strict-types-on-and-multiple-declares.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-declare-strict-types-on-and-namespace-declaration.php (83%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-declare-strict-types-on.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-declare-ticks.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-doc-block-and-declare-strict-types-off-and-invalid-casing.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-doc-block-and-declare-strict-types-off-and-multiple-declares.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-doc-block-and-declare-strict-types-off.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-doc-block-and-declare-strict-types-on-and-invalid-casing.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-doc-block-and-declare-strict-types-on-and-multiple-declares.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-doc-block-and-declare-strict-types-on-and-namespace-declaration.php (85%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-doc-block-and-declare-strict-types-on.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-shebang-and-another-one-text-line-before-opening-tag.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-shebang-and-declare-strict-types-off.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-shebang-and-declare-strict-types-on.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-text-before-opening-tag.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-without-declare-strict-types-and-namespace-declaration.php (79%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-without-declare-strict-types.php (100%) delete mode 100644 test/Fixture/Functions/NoNullableReturnTypeDeclarationRule/Failure/function-with-nullable-return-type-declaration.php delete mode 100644 test/Fixture/Functions/NoNullableReturnTypeDeclarationRule/Failure/function-with-nullable-union-return-type-declaration.php delete mode 100644 test/Fixture/Functions/NoNullableReturnTypeDeclarationRule/Success/function-with-return-type-declaration.php delete mode 100644 test/Fixture/Functions/NoNullableReturnTypeDeclarationRule/Success/function-without-return-type-declaration.php create mode 100644 test/Fixture/Functions/NoNullableReturnTypeDeclarationRule/script.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullDefaultValueRule/Failure/function-with-parameter-with-null-default-value.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullDefaultValueRule/Failure/function-with-parameter-with-root-namespace-referenced-null-default-value.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullDefaultValueRule/Failure/function-with-parameter-with-wrongly-capitalized-null-default-value.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullDefaultValueRule/Success/function-with-parameter-with-non-null-default-value.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullDefaultValueRule/Success/function-with-parameter-without-default-value.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullDefaultValueRule/Success/function-without-parameters.php create mode 100644 test/Fixture/Functions/NoParameterWithNullDefaultValueRule/script.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Failure/function-with-parameter-with-nullable-type-declaration.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Failure/function-with-parameter-with-nullable-union-type-declaration.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Success/function-with-parameter-with-type-declaration.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Success/function-with-parameter-without-type-declaration.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Success/function-without-parameters.php create mode 100644 test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/script.php rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithAbstractMethod.php (88%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithFinalProtectedMethod.php (89%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithFinalPublicMethod.php (89%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithNonFinalConstructor.php (89%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPrivateMethod.php (89%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Failure => }/AbstractClassWithProtectedMethod.php (89%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndEmbeddableAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndEmbeddableAnnotationInMultilineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndEmbeddableAttribute.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndEntityAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndEntityAnnotationInMultilineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndEntityAttribute.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndOrmEmbeddableAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndOrmEmbeddableAnnotationInMultilineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndOrmEntityAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndOrmEntityAnnotationInMultilineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndOrmMappingEmbeddableAnnotationInInlineDocBlock.php (92%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndOrmMappingEmbeddableAnnotationInMultilineDocBlock.php (92%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndOrmMappingEntityAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndOrmMappingEntityAnnotationInMultilineDocBlock.php (92%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Failure => }/AbstractClassWithPublicMethod.php (88%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndEmbeddableAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndEmbeddableAnnotationInMultilineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndEmbeddableAttribute.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndEntityAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndEntityAnnotationInMultilineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndEntityAttribute.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndOrmEmbeddableAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndOrmEmbeddableAnnotationInMultilineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndOrmEntityAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndOrmEntityAnnotationInMultilineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndOrmMappingEmbeddableAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndOrmMappingEmbeddableAnnotationInMultilineDocBlock.php (92%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndOrmMappingEntityAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndOrmMappingEntityAnnotationInMultilineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/InterfaceWithPublicMethod.php (87%) rename test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/{Failure => }/ConstructorInClassWithParameterWithDefaultValue.php (83%) rename test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/{Success => }/ConstructorInClassWithParameterWithoutDefaultValue.php (83%) rename test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/{Success => }/ConstructorInClassWithoutParameters.php (82%) rename test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/{Success => }/ConstructorInTraitWithParameterWithDefaultValue.php (83%) rename test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/{Success => }/ConstructorInTraitWithParameterWithoutDefaultValue.php (83%) rename test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/{Success => }/ConstructorInTraitWithoutParameters.php (81%) rename test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/{Failure => }/ConstructorWithWrongCapitalizationInClassWithParameterWithDefaultValue.php (85%) delete mode 100644 test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Failure/constructor-in-anonymous-class-with-parameter-with-default-value.php delete mode 100644 test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Failure/constructor-with-wrong-capitalization-in-anonymous-class-with-parameter-with-default-value.php rename test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/{Success => }/MethodInClassWithParameterWithDefaultValue.php (83%) rename test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/{Success => }/MethodInTraitWithParameterWithDefaultValue.php (83%) delete mode 100644 test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/constructor-in-anonymous-class-with-parameter-without-default-value.php delete mode 100644 test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/constructor-in-anonymous-class-without-parameters.php delete mode 100644 test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/method-in-anonymous-class-with-parameter-with-default-value.php create mode 100644 test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/script.php delete mode 100644 test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInAnonymousClassWithNullableReturnTypeDeclaration.php delete mode 100644 test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInAnonymousClassWithNullableUnionReturnTypeDeclaration.php rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Failure => }/MethodInClassWithNullableReturnTypeDeclaration.php (87%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Failure => }/MethodInClassWithNullableUnionReturnTypeDeclaration.php (87%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Success => }/MethodInClassWithReturnTypeDeclaration.php (86%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Success => }/MethodInClassWithoutReturnTypeDeclaration.php (86%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Failure => }/MethodInInterfaceWithNullableReturnTypeDeclaration.php (85%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Failure => }/MethodInInterfaceWithNullableUnionReturnTypeDeclaration.php (85%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Success => }/MethodInInterfaceWithReturnTypeDeclaration.php (84%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Success => }/MethodInInterfaceWithoutReturnTypeDeclaration.php (84%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Success => }/MethodInTraitWithNullableReturnTypeDeclaration.php (86%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Success => }/MethodInTraitWithReturnTypeDeclaration.php (86%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Success => }/MethodInTraitWithoutReturnTypeDeclaration.php (86%) delete mode 100644 test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInAnonymousClassWithReturnTypeDeclaration.php delete mode 100644 test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInAnonymousClassWithoutReturnTypeDeclaration.php create mode 100644 test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/script.php rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Failure => }/ClassImplementingContainerInterface.php (77%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Failure => }/ClassImplementingContainerInterfaceWithMethodWithParameterWithSelfAsTypeDeclaration.php (90%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Failure => }/ClassWithMethodWithParameterWithClassImplementingContainerInterfaceAsTypeDeclaration.php (87%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Success => }/ClassWithMethodWithParameterWithClassImplementingContainerInterfaceAsTypeDeclarationWhereNameIsExcluded.php (63%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Failure => }/ClassWithMethodWithParameterWithContainerInterfaceAsTypeDeclaration.php (87%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Failure => }/ClassWithMethodWithParameterWithInterfaceExtendingContainerInterfaceAsTypeDeclaration.php (87%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Success => }/ClassWithMethodWithParameterWithOtherTypeDeclaration.php (84%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Success => }/ClassWithMethodWithoutParameter.php (81%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Success => }/ContainerInterface.php (75%) delete mode 100644 test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/anonymous-class-with-method-with-parameter-with-class-implementing-container-interface-as-type-declaration.php delete mode 100644 test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/anonymous-class-with-method-with-parameter-with-container-interface-as-type-declaration.php delete mode 100644 test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/anonymous-class-with-method-with-parameter-with-interface-extending-container-interface-as-type-declaration.php rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Failure => }/InterfaceExtendingContainerInterface.php (82%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Failure => }/InterfaceWithMethodWithParameterWithContainerInterfaceAsTypeDeclaration.php (86%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Success => }/InterfaceWithMethodWithParameterWithContainerInterfaceAsTypeDeclarationWhereNameIsExcluded.php (87%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Success => }/InterfaceWithMethodWithParameterWithOtherTypeDeclaration.php (84%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Success => }/InterfaceWithMethodWithoutParameter.php (81%) delete mode 100644 test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/anonymous-class-with-method-with-parameter-with-class-implementing-container-interface-as-type-declaration-where-name-is-excluded.php delete mode 100644 test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/anonymous-class-with-method-with-parameter-with-other-type-declaration.php delete mode 100644 test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/anonymous-class-with-method-without-parameter.php create mode 100644 test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/script.php delete mode 100644 test/Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/method-in-anonymous-class-with-parameter-with-null-default-value.php delete mode 100644 test/Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/method-in-anonymous-class-with-parameter-with-root-namespace-referenced-null-default-value.php delete mode 100644 test/Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/method-in-anonymous-class-with-parameter-with-wrongly-capitalized-null-default-value.php rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInClassWithParameterWithNonNullDefaultValue.php (86%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Failure => }/MethodInClassWithParameterWithNullDefaultValue.php (86%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Failure => }/MethodInClassWithParameterWithRootNamespaceReferencedNullDefaultValue.php (87%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Failure => }/MethodInClassWithParameterWithWronglyCapitalizedNullDefaultValue.php (87%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInClassWithParameterWithoutDefaultValue.php (86%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInClassWithoutParameters.php (84%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInInterfaceWithParameterWithNonNullDefaultValue.php (85%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Failure => }/MethodInInterfaceWithParameterWithNullDefaultValue.php (85%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Failure => }/MethodInInterfaceWithParameterWithRootNamespaceReferencedNullDefaultValue.php (86%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Failure => }/MethodInInterfaceWithParameterWithWronlgyCapitalizedNullDefaultValue.php (86%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInInterfaceWithParameterWithoutDefaultValue.php (84%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInInterfaceWithoutParameters.php (83%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInTraitWithParameterWithDefaultValue.php (86%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInTraitWithParameterWithNonNullDefaultValue.php (86%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInTraitWithParameterWithRootNamespaceReferencedNullDefaultValue.php (87%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInTraitWithParameterWithWronlgyCapitalizedNullDefaultValue.php (87%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInTraitWithParameterWithoutDefaultValue.php (86%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInTraitWithoutParameters.php (83%) delete mode 100644 test/Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/method-in-anonymous-class-with-parameter-with-non-null-default-value.php delete mode 100644 test/Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/method-in-anonymous-class-with-parameter-without-default-value.php delete mode 100644 test/Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/method-in-anonymous-class-without-parameters.php create mode 100644 test/Fixture/Methods/NoParameterWithNullDefaultValueRule/script.php delete mode 100644 test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Failure/method-in-anonymous-class-with-parameter-with-nullable-type-declaration.php delete mode 100644 test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Failure/method-in-anonymous-class-with-parameter-with-nullable-union-type-declaration.php rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Failure => }/MethodInClassWithParameterWithNullableTypeDeclaration.php (85%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Failure => }/MethodInClassWithParameterWithNullableUnionTypeDeclaration.php (85%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInClassWithParameterWithTypeDeclaration.php (84%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInClassWithParameterWithoutTypeDeclaration.php (84%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInClassWithoutParameters.php (81%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Failure => }/MethodInInterfaceWithParameterWithNullableTypeDeclaration.php (83%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Failure => }/MethodInInterfaceWithParameterWithNullableUnionTypeDeclaration.php (83%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInInterfaceWithParameterWithTypeDeclaration.php (82%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInInterfaceWithParameterWithoutTypeDeclaration.php (82%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInInterfaceWithoutParameters.php (80%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInTraitWithParameterWithNullableTypeDeclaration.php (84%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInTraitWithParameterWithTypeDeclaration.php (84%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInTraitWithParameterWithoutTypeDeclaration.php (83%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInTraitWithoutParameters.php (81%) delete mode 100644 test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/method-in-anonymous-class-with-parameter-with-type-declaration.php delete mode 100644 test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/method-in-anonymous-class-with-parameter-without-type-declaration.php delete mode 100644 test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/method-in-anonymous-class-without-parameters.php create mode 100644 test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/script.php rename test/Fixture/Methods/PrivateInFinalClassRule/{Success => }/AbstractClassExtendingAbstractClassWithProtectedMethod.php (90%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Success => }/AbstractClassWithProtectedMethod.php (89%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Success => }/ClassWithProtectedMethod.php (88%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Success => }/FinalClassWithPrivateMethod.php (89%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Failure => }/FinalClassWithProtectedMethod.php (89%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Success => }/FinalClassWithProtectedMethodExtendingClassExtendingClassWithSameProtectedMethod.php (93%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Success => }/FinalClassWithProtectedMethodExtendingClassWithSameProtectedMethod.php (92%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Success => }/FinalClassWithProtectedMethodFromTrait.php (89%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Success => }/FinalClassWithPublicMethod.php (89%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Success => }/TraitWithProtectedMethod.php (88%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Failure/AnonymousClassWithProtectedMethod.php => script.php} (80%) delete mode 100644 test/Integration/Classes/FinalRuleWithAbstractClassesAllowedTest.php delete mode 100644 test/Integration/Classes/FinalRuleWithAttributesTest.php delete mode 100644 test/Integration/Classes/FinalRuleWithExcludedClassNamesTest.php delete mode 100644 test/Integration/Classes/NoExtendsRuleWithClassesAllowedToBeExtendedTest.php create mode 100644 test/Util/Helper.php diff --git a/.php-cs-fixer.fixture.php b/.php-cs-fixer.fixture.php index fbc479d8..debeb30e 100644 --- a/.php-cs-fixer.fixture.php +++ b/.php-cs-fixer.fixture.php @@ -26,6 +26,7 @@ 'lowercase_keywords' => false, 'magic_method_casing' => false, 'native_function_casing' => false, + 'native_function_invocation' => false, 'nullable_type_declaration' => false, 'protected_to_private' => false, 'static_lambda' => false, @@ -36,17 +37,16 @@ $config->getFinder() ->in(__DIR__ . '/test/Fixture/') ->notPath([ - 'Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Success/ImplicitlyAbstractTestCase.php', - 'Closures/NoNullableReturnTypeDeclarationRule/Failure/closure-with-nullable-union-type-return-type-declaration.php', - 'Closures/NoParameterWithNullableTypeDeclarationRule/Failure/closure-with-parameter-with-nullable-union-type-declaration.php', - 'Functions/NoNullableReturnTypeDeclarationRule/Failure/function-with-nullable-union-return-type-declaration.php', - 'Functions/NoParameterWithNullableTypeDeclarationRule/Failure/function-with-parameter-with-nullable-union-type-declaration.php', - 'Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInAnonymousClassWithNullableUnionReturnTypeDeclaration.php', - 'Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInClassWithNullableUnionReturnTypeDeclaration.php', - 'Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInInterfaceWithNullableUnionReturnTypeDeclaration.php', - 'Methods/NoParameterWithNullableTypeDeclarationRule/Failure/method-in-anonymous-class-with-parameter-with-nullable-union-type-declaration.php', - 'Methods/NoParameterWithNullableTypeDeclarationRule/Failure/MethodInClassWithParameterWithNullableUnionTypeDeclaration.php', - 'Methods/NoParameterWithNullableTypeDeclarationRule/Failure/MethodInInterfaceWithParameterWithNullableUnionTypeDeclaration.php', + 'Closures/NoNullableReturnTypeDeclarationRule/script.php', + 'Closures/NoParameterWithNullableTypeDeclarationRule/script.php', + 'Functions/NoNullableReturnTypeDeclarationRule/script.php', + 'Functions/NoParameterWithNullableTypeDeclarationRule/script.php', + 'Methods/NoNullableReturnTypeDeclarationRule/MethodInClassWithNullableUnionReturnTypeDeclaration.php', + 'Methods/NoNullableReturnTypeDeclarationRule/MethodInInterfaceWithNullableUnionReturnTypeDeclaration.php', + 'Methods/NoNullableReturnTypeDeclarationRule/script.php', + 'Methods/NoParameterWithNullableTypeDeclarationRule/MethodInClassWithParameterWithNullableUnionTypeDeclaration.php', + 'Methods/NoParameterWithNullableTypeDeclarationRule/MethodInInterfaceWithParameterWithNullableUnionTypeDeclaration.php', + 'Methods/NoParameterWithNullableTypeDeclarationRule/script.php', ]); $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php_cs.fixture.cache'); diff --git a/composer.json b/composer.json index e9e6e714..40192616 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,7 @@ "phpstan/phpstan-strict-rules": "^1.6.1", "phpunit/phpunit": "^9.6.21", "psr/container": "^2.0.2", + "symfony/finder": "^5.4.45", "symfony/process": "^5.4.47" }, "autoload": { diff --git a/composer.lock b/composer.lock index b28749e1..38817c5c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a59576f025172422ac893480a8da1701", + "content-hash": "31f0e1fba4524e34ac08c37e71265e3c", "packages": [ { "name": "phpstan/phpstan", diff --git a/test/Fixture/Classes/FinalRule/AbstractClass.php b/test/Fixture/Classes/FinalRule/AbstractClass.php new file mode 100644 index 00000000..fa9f7101 --- /dev/null +++ b/test/Fixture/Classes/FinalRule/AbstractClass.php @@ -0,0 +1,9 @@ + */ abstract class AbstractTestCase extends Testing\RuleTestCase diff --git a/test/Integration/Classes/FinalRuleTest.php b/test/Integration/Classes/FinalRuleTest.php index 63ef1b72..542ffc41 100644 --- a/test/Integration/Classes/FinalRuleTest.php +++ b/test/Integration/Classes/FinalRuleTest.php @@ -15,121 +15,265 @@ use Ergebnis\PHPStan\Rules\Classes; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Classes\FinalRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class FinalRuleTest extends Test\Integration\AbstractTestCase +final class FinalRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'final-class' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/FinalClass.php', - 'final-class-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/FinalClassWithAnonymousClass.php', - 'interface' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/ExampleInterface.php', - 'non-final-class-with-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/NonFinalClassWithEntityAnnotationInInlineDocBlock.php', - 'non-final-class-with-entity-annotation-in-multi-line-doc-block' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/NonFinalClassWithEntityAnnotationInMultilineDocBlock.php', - 'non-final-class-with-orm-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/NonFinalClassWithOrmEntityAnnotationInInlineDocBlock.php', - 'non-final-class-with-orm-entity-annotation-in-multi-line-doc-block' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/NonFinalClassWithOrmEntityAnnotationInMultilineDocBlock.php', - 'non-final-class-with-orm-mapping-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/NonFinalClassWithOrmMappingEntityAnnotationInInlineDocBlock.php', - 'non-final-class-with-orm-mapping-entity-annotation-in-multi-line-doc-block' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/NonFinalClassWithOrmMappingEntityAnnotationInMultilineDocBlock.php', - 'script-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/anonymous-class.php', - 'trait' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/ExampleTrait.php', - 'trait-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/TraitWithAnonymousClass.php', - ]; + use Test\Util\Helper; + private bool $allowAbstractClasses; - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + /** + * @var list + */ + private array $classesNotRequiredToBeAbstractOrFinal; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testFinalRule(): void { - $paths = [ - 'abstract-class' => [ - __DIR__ . '/../../Fixture/Classes/FinalRule/Failure/AbstractClass.php', + $this->allowAbstractClasses = false; + $this->classesNotRequiredToBeAbstractOrFinal = []; + + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Classes/FinalRule'), + [ [ \sprintf( 'Class %s is not final.', - Test\Fixture\Classes\FinalRule\Failure\AbstractClass::class, + Test\Fixture\Classes\FinalRule\AbstractClass::class, ), 7, ], - ], - 'neither-abstract-nor-final-class' => [ - __DIR__ . '/../../Fixture/Classes/FinalRule/Failure/NeitherAbstractNorFinalClass.php', [ \sprintf( 'Class %s is not final.', - Test\Fixture\Classes\FinalRule\Failure\NeitherAbstractNorFinalClass::class, + Test\Fixture\Classes\FinalRule\NeitherAbstractNorFinalClass::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedDoctrineOrmMappingEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedOrmEntityAttribute::class, ), 7, ], - ], - 'non-final-class-without-entity-annotation-in-inline-doc-block' => [ - __DIR__ . '/../../Fixture/Classes/FinalRule/Failure/NonFinalClassWithoutEntityAnnotationInInlineDocBlock.php', [ \sprintf( 'Class %s is not final.', - Test\Fixture\Classes\FinalRule\Failure\NonFinalClassWithoutEntityAnnotationInInlineDocBlock::class, + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedOrmMappingEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutEntityAnnotationInInlineDocBlock::class, ), 8, ], - ], - 'non-final-class-without-entity-annotation-in-multi-line-doc-block' => [ - __DIR__ . '/../../Fixture/Classes/FinalRule/Failure/NonFinalClassWithoutEntityAnnotationInMultilineDocBlock.php', [ \sprintf( 'Class %s is not final.', - Test\Fixture\Classes\FinalRule\Failure\NonFinalClassWithoutEntityAnnotationInMultilineDocBlock::class, + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutEntityAnnotationInMultilineDocBlock::class, ), 12, ], - ], - 'non-final-class-without-orm-entity-annotation-in-inline-doc-block' => [ - __DIR__ . '/../../Fixture/Classes/FinalRule/Failure/NonFinalClassWithoutOrmEntityAnnotationInInlineDocBlock.php', [ \sprintf( 'Class %s is not final.', - Test\Fixture\Classes\FinalRule\Failure\NonFinalClassWithoutOrmEntityAnnotationInInlineDocBlock::class, + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutOrmEntityAnnotationInInlineDocBlock::class, ), 8, ], - ], - 'non-final-class-without-orm-entity-annotation-in-multi-line-doc-block' => [ - __DIR__ . '/../../Fixture/Classes/FinalRule/Failure/NonFinalClassWithoutOrmEntityAnnotationInMultilineDocBlock.php', [ \sprintf( 'Class %s is not final.', - Test\Fixture\Classes\FinalRule\Failure\NonFinalClassWithoutOrmEntityAnnotationInMultilineDocBlock::class, + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutOrmEntityAnnotationInMultilineDocBlock::class, ), 12, ], ], + ); + } + + public function testFinalRuleWithAllowAbstractClasses(): void + { + $this->allowAbstractClasses = true; + $this->classesNotRequiredToBeAbstractOrFinal = []; + + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Classes/FinalRule'), + [ + [ + \sprintf( + 'Class %s is neither abstract nor final.', + Test\Fixture\Classes\FinalRule\NeitherAbstractNorFinalClass::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is neither abstract nor final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedDoctrineOrmMappingEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is neither abstract nor final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is neither abstract nor final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedOrmEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is neither abstract nor final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedOrmMappingEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is neither abstract nor final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutEntityAnnotationInInlineDocBlock::class, + ), + 8, + ], + [ + \sprintf( + 'Class %s is neither abstract nor final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutEntityAnnotationInMultilineDocBlock::class, + ), + 12, + ], + [ + \sprintf( + 'Class %s is neither abstract nor final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutOrmEntityAnnotationInInlineDocBlock::class, + ), + 8, + ], + [ + \sprintf( + 'Class %s is neither abstract nor final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutOrmEntityAnnotationInMultilineDocBlock::class, + ), + 12, + ], + ], + ); + } + + public function testFinalRuleWithClassesNotRequiredToBeAbstractOrFinal(): void + { + $this->allowAbstractClasses = false; + $this->classesNotRequiredToBeAbstractOrFinal = [ + Test\Fixture\Classes\FinalRule\NeitherAbstractNorFinalClass::class, ]; - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Classes/FinalRule'), + [ + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\AbstractClass::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedDoctrineOrmMappingEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedOrmEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedOrmMappingEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutEntityAnnotationInInlineDocBlock::class, + ), + 8, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutEntityAnnotationInMultilineDocBlock::class, + ), + 12, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutOrmEntityAnnotationInInlineDocBlock::class, + ), + 8, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutOrmEntityAnnotationInMultilineDocBlock::class, + ), + 12, + ], + ], + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Classes\FinalRule( - false, - [], + $this->allowAbstractClasses, + $this->classesNotRequiredToBeAbstractOrFinal, ); } } diff --git a/test/Integration/Classes/FinalRuleWithAbstractClassesAllowedTest.php b/test/Integration/Classes/FinalRuleWithAbstractClassesAllowedTest.php deleted file mode 100644 index f2cc5544..00000000 --- a/test/Integration/Classes/FinalRuleWithAbstractClassesAllowedTest.php +++ /dev/null @@ -1,80 +0,0 @@ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Failure/AbstractClass.php', - 'final-class' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/FinalClass.php', - 'final-class-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/FinalClassWithAnonymousClass.php', - 'interface' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/ExampleInterface.php', - 'script-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/anonymous-class.php', - 'trait' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/ExampleTrait.php', - 'trait-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/TraitWithAnonymousClass.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } - - public static function provideCasesWhereAnalysisShouldFail(): iterable - { - $paths = [ - 'neither-abstract-nor-final-class' => [ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Failure/NeitherAbstractNorFinalClass.php', - [ - \sprintf( - 'Class %s is neither abstract nor final.', - Test\Fixture\Classes\FinalRuleWithAbstractClassesAllowed\Failure\NeitherAbstractNorFinalClass::class, - ), - 7, - ], - ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } - } - - /** - * @return Rules\Rule - */ - protected function getRule(): Rules\Rule - { - return new Classes\FinalRule( - true, - [], - ); - } -} diff --git a/test/Integration/Classes/FinalRuleWithAttributesTest.php b/test/Integration/Classes/FinalRuleWithAttributesTest.php deleted file mode 100644 index abd42661..00000000 --- a/test/Integration/Classes/FinalRuleWithAttributesTest.php +++ /dev/null @@ -1,108 +0,0 @@ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithAttributes/Success/NonFinalClassWithAliasedOrmEntityAttribute.php', - 'non-final-class-with-qualified-doctrine-orm-mapping-entity-attribute' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAttributes/Success/NonFinalClassWithQualifiedDoctrineOrmMappingEntityAttribute.php', - 'non-final-class-with-qualified-entity-attribute' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAttributes/Success/NonFinalClassWithQualifiedEntityAttribute.php', - 'non-final-class-with-qualified-mapping-entity-attribute' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAttributes/Success/NonFinalClassWithQualifiedMappingEntityAttribute.php', - 'non-final-class-with-qualified-orm-mapping-entity-attribute' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAttributes/Success/NonFinalClassWithQualifiedOrmMappingEntityAttribute.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } - - public static function provideCasesWhereAnalysisShouldFail(): iterable - { - $paths = [ - 'non-final-class-with-unqualified-doctrine-orm-mapping-entity-attribute' => [ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithAttributes/Failure/NonFinalClassWithUnqualifiedDoctrineOrmMappingEntityAttribute.php', - [ - \sprintf( - 'Class %s is not final.', - Test\Fixture\Classes\FinalRuleWithAttributes\Failure\NonFinalClassWithUnqualifiedDoctrineOrmMappingEntityAttribute::class, - ), - 7, - ], - ], - 'non-final-class-with-unqualified-entity-attribute' => [ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithAttributes/Failure/NonFinalClassWithUnqualifiedEntityAttribute.php', - [ - \sprintf( - 'Class %s is not final.', - Test\Fixture\Classes\FinalRuleWithAttributes\Failure\NonFinalClassWithUnqualifiedEntityAttribute::class, - ), - 7, - ], - ], - 'non-final-class-with-unqualified-orm-entity-attribute' => [ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithAttributes/Failure/NonFinalClassWithUnqualifiedOrmEntityAttribute.php', - [ - \sprintf( - 'Class %s is not final.', - Test\Fixture\Classes\FinalRuleWithAttributes\Failure\NonFinalClassWithUnqualifiedOrmEntityAttribute::class, - ), - 7, - ], - ], - 'non-final-class-with-unqualified-orm-mapping-entity-attribute' => [ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithAttributes/Failure/NonFinalClassWithUnqualifiedOrmMappingEntityAttribute.php', - [ - \sprintf( - 'Class %s is not final.', - Test\Fixture\Classes\FinalRuleWithAttributes\Failure\NonFinalClassWithUnqualifiedOrmMappingEntityAttribute::class, - ), - 7, - ], - ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } - } - - /** - * @return Rules\Rule - */ - protected function getRule(): Rules\Rule - { - return new Classes\FinalRule( - false, - [], - ); - } -} diff --git a/test/Integration/Classes/FinalRuleWithExcludedClassNamesTest.php b/test/Integration/Classes/FinalRuleWithExcludedClassNamesTest.php deleted file mode 100644 index 189f9268..00000000 --- a/test/Integration/Classes/FinalRuleWithExcludedClassNamesTest.php +++ /dev/null @@ -1,92 +0,0 @@ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithExcludedClassNames/Success/NeitherAbstractNorFinalClassButWhitelisted.php', - 'final-class' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithExcludedClassNames/Success/FinalClass.php', - 'final-class-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithExcludedClassNames/Success/FinalClassWithAnonymousClass.php', - 'interface' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithExcludedClassNames/Success/ExampleInterface.php', - 'script-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithExcludedClassNames/Success/anonymous-class.php', - 'trait' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithExcludedClassNames/Success/ExampleTrait.php', - 'trait-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithExcludedClassNames/Success/TraitWithAnonymousClass.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } - - public static function provideCasesWhereAnalysisShouldFail(): iterable - { - $paths = [ - 'abstract-class' => [ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithExcludedClassNames/Failure/AbstractClass.php', - [ - \sprintf( - 'Class %s is not final.', - Test\Fixture\Classes\FinalRuleWithExcludedClassNames\Failure\AbstractClass::class, - ), - 7, - ], - ], - 'neither-abstract-nor-final-class' => [ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithExcludedClassNames/Failure/NeitherAbstractNorFinalClass.php', - [ - \sprintf( - 'Class %s is not final.', - Test\Fixture\Classes\FinalRuleWithExcludedClassNames\Failure\NeitherAbstractNorFinalClass::class, - ), - 7, - ], - ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } - } - - /** - * @return Rules\Rule - */ - protected function getRule(): Rules\Rule - { - return new Classes\FinalRule( - false, - [ - Test\Fixture\Classes\FinalRuleWithExcludedClassNames\Success\NeitherAbstractNorFinalClassButWhitelisted::class, - ], - ); - } -} diff --git a/test/Integration/Classes/NoExtendsRuleTest.php b/test/Integration/Classes/NoExtendsRuleTest.php index 2b9a94de..9667bb40 100644 --- a/test/Integration/Classes/NoExtendsRuleTest.php +++ b/test/Integration/Classes/NoExtendsRuleTest.php @@ -15,72 +15,66 @@ use Ergebnis\PHPStan\Rules\Classes; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Classes\NoExtendsRule * + * @extends Testing\RuleTestCase + * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier */ -final class NoExtendsRuleTest extends Test\Integration\AbstractTestCase +final class NoExtendsRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'class' => __DIR__ . '/../../Fixture/Classes/NoExtendsRule/Success/ExampleClass.php', - 'class-extending-php-unit-framework-test-case' => __DIR__ . '/../../Fixture/Classes/NoExtendsRule/Success/ClassExtendingPhpUnitFrameworkTestCase.php', - 'interface' => __DIR__ . '/../../Fixture/Classes/NoExtendsRule/Success/ExampleInterface.php', - 'interface-extending-other-interface' => __DIR__ . '/../../Fixture/Classes/NoExtendsRule/Success/InterfaceExtendingOtherInterface.php', - 'script-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/NoExtendsRule/Success/anonymous-class.php', - ]; + use Test\Util\Helper; - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + /** + * @var list + */ + private array $classesAllowedToBeExtended; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoExtendsRule(): void { - $paths = [ - 'class-extending-other-class' => [ - __DIR__ . '/../../Fixture/Classes/NoExtendsRule/Failure/ClassExtendingOtherClass.php', + $this->classesAllowedToBeExtended = []; + + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Classes/NoExtendsRule'), + [ [ \sprintf( 'Class "%s" is not allowed to extend "%s".', - Test\Fixture\Classes\NoExtendsRule\Failure\ClassExtendingOtherClass::class, - Test\Fixture\Classes\NoExtendsRule\Failure\OtherClass::class, + Test\Fixture\Classes\NoExtendsRule\ClassExtendingOtherClass::class, + Test\Fixture\Classes\NoExtendsRule\OtherClass::class, ), 7, ], - ], - 'script-with-anonymous-class-extending-other-class' => [ - __DIR__ . '/../../Fixture/Classes/NoExtendsRule/Failure/anonymous-class-extending-other-class.php', [ \sprintf( 'Anonymous class is not allowed to extend "%s".', - Test\Fixture\Classes\NoExtendsRule\Failure\OtherClass::class, + Test\Fixture\Classes\NoExtendsRule\OtherClass::class, ), - 7, + 10, ], ], + ); + } + + public function testNoExtendsRuleWithClassesAllowedToBeExtended(): void + { + $this->classesAllowedToBeExtended = [ + Test\Fixture\Classes\NoExtendsRule\OtherClass::class, ]; - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Classes/NoExtendsRule'), + [ + ], + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { - return new Classes\NoExtendsRule([]); + return new Classes\NoExtendsRule($this->classesAllowedToBeExtended); } } diff --git a/test/Integration/Classes/NoExtendsRuleWithClassesAllowedToBeExtendedTest.php b/test/Integration/Classes/NoExtendsRuleWithClassesAllowedToBeExtendedTest.php deleted file mode 100644 index 8e412e59..00000000 --- a/test/Integration/Classes/NoExtendsRuleWithClassesAllowedToBeExtendedTest.php +++ /dev/null @@ -1,90 +0,0 @@ - __DIR__ . '/../../Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ExampleClass.php', - 'class-extending-class-allowed-to-be-extended' => __DIR__ . '/../../Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ClassExtendingClassAllowedToBeExtended.php', - 'class-extending-php-unit-framework-test-case' => __DIR__ . '/../../Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ClassExtendingPhpUnitFrameworkTestCase.php', - 'interface' => __DIR__ . '/../../Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ExampleInterface.php', - 'interface-extending-other-interface' => __DIR__ . '/../../Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/InterfaceExtendingOtherInterface.php', - 'script-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/anonymous-class.php', - 'script-with-anonymous-class-extending-class-allowed-to-be-extended' => __DIR__ . '/../../Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/anonymous-class-extending-class-allowed-to-be-extended.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } - - public static function provideCasesWhereAnalysisShouldFail(): iterable - { - $paths = [ - 'class-extending-other-class' => [ - __DIR__ . '/../../Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Failure/ClassExtendingOtherClass.php', - [ - \sprintf( - 'Class "%s" is not allowed to extend "%s".', - Test\Fixture\Classes\NoExtendsRuleWithClassesAllowedToBeExtended\Failure\ClassExtendingOtherClass::class, - Test\Fixture\Classes\NoExtendsRuleWithClassesAllowedToBeExtended\Failure\OtherClass::class, - ), - 7, - ], - ], - 'script-with-anonymous-class-extending-other-class' => [ - __DIR__ . '/../../Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Failure/anonymous-class-extending-other-class.php', - [ - \sprintf( - 'Anonymous class is not allowed to extend "%s".', - Test\Fixture\Classes\NoExtendsRuleWithClassesAllowedToBeExtended\Failure\OtherClass::class, - ), - 7, - ], - ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } - } - - /** - * @return Rules\Rule - */ - protected function getRule(): Rules\Rule - { - return new Classes\NoExtendsRule([ - Test\Fixture\Classes\NoExtendsRuleWithClassesAllowedToBeExtended\Success\ClassAllowedToBeExtended::class, - ]); - } -} diff --git a/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php b/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php index 5715df39..206ebf87 100644 --- a/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php +++ b/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php @@ -15,70 +15,46 @@ use Ergebnis\PHPStan\Rules\Classes; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; use PHPUnit\Framework; /** * @covers \Ergebnis\PHPStan\Rules\Classes\PHPUnit\Framework\TestCaseWithSuffixRule * + * @extends Testing\RuleTestCase + * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier */ -final class TestCaseWithSuffixRuleTest extends Test\Integration\AbstractTestCase +final class TestCaseWithSuffixRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'concrete-test-case-with-suffix-test' => __DIR__ . '/../../../../Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Success/ConcreteTestCaseWithSuffixTest.php', - 'explicitly-abstract-test-case' => __DIR__ . '/../../../../Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Success/ExplicitlyAbstractTestCase.php', - 'implicitly-abstract-test-case' => __DIR__ . '/../../../../Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Success/ExplicitlyAbstractTestCase.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testTestCaseWithSuffixRule(): void { - $paths = [ - 'concrete-test-case-extending-abstract-test-case-without-test-suffix' => [ - __DIR__ . '/../../../../Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Failure/ConcreteTestCaseExtendingAbstractTestCaseWithoutTestSuffix.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../../../Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule'), + [ [ \sprintf( 'Class %s extends %s, is concrete, but does not have a Test suffix.', - Test\Fixture\Classes\PHPUnit\Framework\TestCaseWithSuffixRule\Failure\ConcreteTestCaseExtendingAbstractTestCaseWithoutTestSuffix::class, + Test\Fixture\Classes\PHPUnit\Framework\TestCaseWithSuffixRule\ConcreteTestCaseExtendingAbstractTestCaseWithoutSuffix::class, Framework\TestCase::class, ), 7, ], - ], - 'concrete-test-case-without-test-suffix' => [ - __DIR__ . '/../../../../Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Failure/ConcreteTestCaseWithoutTestSuffix.php', [ \sprintf( 'Class %s extends %s, is concrete, but does not have a Test suffix.', - Test\Fixture\Classes\PHPUnit\Framework\TestCaseWithSuffixRule\Failure\ConcreteTestCaseWithoutTestSuffix::class, + Test\Fixture\Classes\PHPUnit\Framework\TestCaseWithSuffixRule\ConcreteTestCaseWithoutSuffix::class, Framework\TestCase::class, ), 9, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Classes\PHPUnit\Framework\TestCaseWithSuffixRule(self::createReflectionProvider()); diff --git a/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php index ae5837d2..a2e61cc9 100644 --- a/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php @@ -15,60 +15,37 @@ use Ergebnis\PHPStan\Rules\Closures; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Closures\NoNullableReturnTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoNullableReturnTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase +final class NoNullableReturnTypeDeclarationRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'closure-with-return-type-declaration' => __DIR__ . '/../../Fixture/Closures/NoNullableReturnTypeDeclarationRule/Success/closure-with-return-type-declaration.php', - 'closure-function-without-return-type-declaration' => __DIR__ . '/../../Fixture/Closures/NoNullableReturnTypeDeclarationRule/Success/closure-without-return-type-declaration.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoNullableReturnTypeDeclarationRule(): void { - $paths = [ - 'closure-with-nullable-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Closures/NoNullableReturnTypeDeclarationRule/Failure/closure-with-nullable-return-type-declaration.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Closures/NoNullableReturnTypeDeclarationRule'), + [ [ 'Closure has a nullable return type declaration.', - 7, + 15, ], - ], - 'closure-with-nullable-union-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Closures/NoNullableReturnTypeDeclarationRule/Failure/closure-with-nullable-union-type-return-type-declaration.php', [ 'Closure has a nullable return type declaration.', - 7, + 19, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Closures\NoNullableReturnTypeDeclarationRule(); diff --git a/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php b/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php index 2eb841a0..9b3d4847 100644 --- a/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php +++ b/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php @@ -15,68 +15,41 @@ use Ergebnis\PHPStan\Rules\Closures; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Closures\NoParameterWithNullDefaultValueRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoParameterWithNullDefaultValueRuleTest extends Test\Integration\AbstractTestCase +final class NoParameterWithNullDefaultValueRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'closure-with-parameter-with-non-null-default-value' => __DIR__ . '/../../Fixture/Closures/NoParameterWithNullDefaultValueRule/Success/closure-with-parameter-with-non-null-default-value.php', - 'closure-with-parameter-without-default-value' => __DIR__ . '/../../Fixture/Closures/NoParameterWithNullDefaultValueRule/Success/closure-with-parameter-without-default-value.php', - 'closure-with-parameter-without-parameters' => __DIR__ . '/../../Fixture/Closures/NoParameterWithNullDefaultValueRule/Success/closure-without-parameters.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoParameterWithNullDefaultValueRule(): void { - $paths = [ - 'closure-with-parameter-with-null-default-value' => [ - __DIR__ . '/../../Fixture/Closures/NoParameterWithNullDefaultValueRule/Failure/closure-with-parameter-with-null-default-value.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Closures/NoParameterWithNullDefaultValueRule'), + [ [ 'Closure has parameter $bar with null as default value.', - 7, + 18, ], - ], - 'closure-with-parameter-with-root-namespace-referenced-null-default-value' => [ - __DIR__ . '/../../Fixture/Closures/NoParameterWithNullDefaultValueRule/Failure/closure-with-parameter-with-root-namespace-referenced-null-default-value.php', [ 'Closure has parameter $bar with null as default value.', - 7, + 22, ], - ], - 'closure-with-parameter-with-wrongly-capitalized-null-default-value' => [ - __DIR__ . '/../../Fixture/Closures/NoParameterWithNullDefaultValueRule/Failure/closure-with-parameter-with-wrongly-capitalized-null-default-value.php', [ 'Closure has parameter $bar with null as default value.', - 7, + 26, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Closures\NoParameterWithNullDefaultValueRule(); diff --git a/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php index 0432bf48..5e6f09dc 100644 --- a/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -15,61 +15,37 @@ use Ergebnis\PHPStan\Rules\Closures; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Closures\NoParameterWithNullableTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoParameterWithNullableTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase +final class NoParameterWithNullableTypeDeclarationRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'closure-with-parameter-with-type-declaration' => __DIR__ . '/../../Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Success/closure-with-parameter-with-type-declaration.php', - 'closure-with-parameter-without-type-declaration' => __DIR__ . '/../../Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Success/closure-with-parameter-without-type-declaration.php', - 'closure-without-parameters' => __DIR__ . '/../../Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Success/closure-without-parameters.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoParameterWithNullableTypeDeclarationRule(): void { - $paths = [ - 'closure-with-parameter-with-nullable-type-declaration' => [ - __DIR__ . '/../../Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Failure/closure-with-parameter-with-nullable-type-declaration.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Closures/NoParameterWithNullableTypeDeclarationRule'), + [ [ 'Closure has parameter $bar with a nullable type declaration.', - 7, + 18, ], - ], - 'closure-with-parameter-with-nullable-union-type-declaration' => [ - __DIR__ . '/../../Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Failure/closure-with-parameter-with-nullable-union-type-declaration.php', [ 'Closure has parameter $bar with a nullable type declaration.', - 7, + 22, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Closures\NoParameterWithNullableTypeDeclarationRule(); diff --git a/test/Integration/Expressions/NoCompactRuleTest.php b/test/Integration/Expressions/NoCompactRuleTest.php index 2b45ab2b..12c86069 100644 --- a/test/Integration/Expressions/NoCompactRuleTest.php +++ b/test/Integration/Expressions/NoCompactRuleTest.php @@ -15,66 +15,41 @@ use Ergebnis\PHPStan\Rules\Expressions; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Expressions\NoCompactRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoCompactRuleTest extends Test\Integration\AbstractTestCase +final class NoCompactRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'compact-not-used' => __DIR__ . '/../../Fixture/Expressions/NoCompactRule/Success/compact-not-used.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoCompactRule(): void { - $paths = [ - 'compact-used-with-alias' => [ - __DIR__ . '/../../Fixture/Expressions/NoCompactRule/Failure/compact-used-with-alias.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Expressions/NoCompactRule'), + [ [ 'Function compact() should not be used.', - 12, + 22, ], - ], - 'compact-used-with-correct-case' => [ - __DIR__ . '/../../Fixture/Expressions/NoCompactRule/Failure/compact-used-with-correct-case.php', [ 'Function compact() should not be used.', - 10, + 27, ], - ], - 'compact-used-with-incorrect-case' => [ - __DIR__ . '/../../Fixture/Expressions/NoCompactRule/Failure/compact-used-with-incorrect-case.php', [ 'Function compact() should not be used.', - 10, + 32, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Expressions\NoCompactRule(); diff --git a/test/Integration/Expressions/NoErrorSuppressionRuleTest.php b/test/Integration/Expressions/NoErrorSuppressionRuleTest.php index 6dbbf326..0d6aef40 100644 --- a/test/Integration/Expressions/NoErrorSuppressionRuleTest.php +++ b/test/Integration/Expressions/NoErrorSuppressionRuleTest.php @@ -15,52 +15,33 @@ use Ergebnis\PHPStan\Rules\Expressions; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Expressions\NoErrorSuppressionRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoErrorSuppressionRuleTest extends Test\Integration\AbstractTestCase +final class NoErrorSuppressionRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'error-suppression-not-used' => __DIR__ . '/../../Fixture/Expressions/NoErrorSuppressionRule/Success/error-suppression-not-used.php', - ]; + use Test\Util\Helper; - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } - - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoErrorSuppressionRule(): void { - $paths = [ - 'error-suppression-used' => [ - __DIR__ . '/../../Fixture/Expressions/NoErrorSuppressionRule/Failure/error-suppression-used.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Expressions/NoErrorSuppressionRule'), + [ [ 'Error suppression via "@" should not be used.', - 7, + 9, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Expressions\NoErrorSuppressionRule(); diff --git a/test/Integration/Expressions/NoEvalRuleTest.php b/test/Integration/Expressions/NoEvalRuleTest.php index 70d0639c..28799d01 100644 --- a/test/Integration/Expressions/NoEvalRuleTest.php +++ b/test/Integration/Expressions/NoEvalRuleTest.php @@ -15,59 +15,37 @@ use Ergebnis\PHPStan\Rules\Expressions; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Expressions\NoEvalRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoEvalRuleTest extends Test\Integration\AbstractTestCase +final class NoEvalRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'eval-not-used' => __DIR__ . '/../../Fixture/Expressions/NoEvalRule/Success/eval-not-used.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoEvalRule(): void { - $paths = [ - 'eval-used-with-correct-case' => [ - __DIR__ . '/../../Fixture/Expressions/NoEvalRule/Failure/eval-used-with-correct-case.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Expressions/NoEvalRule'), + [ [ 'Language construct eval() should not be used.', - 7, + 13, ], - ], - 'eval-used-with-incorrect-case' => [ - __DIR__ . '/../../Fixture/Expressions/NoEvalRule/Failure/eval-used-with-incorrect-case.php', [ 'Language construct eval() should not be used.', - 7, + 15, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Expressions\NoEvalRule(); diff --git a/test/Integration/Expressions/NoIssetRuleTest.php b/test/Integration/Expressions/NoIssetRuleTest.php index 24d420e3..3052860c 100644 --- a/test/Integration/Expressions/NoIssetRuleTest.php +++ b/test/Integration/Expressions/NoIssetRuleTest.php @@ -15,59 +15,37 @@ use Ergebnis\PHPStan\Rules\Expressions; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Expressions\NoIssetRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoIssetRuleTest extends Test\Integration\AbstractTestCase +final class NoIssetRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'isset-not-used' => __DIR__ . '/../../Fixture/Expressions/NoIssetRule/Success/isset-not-used.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoIssetRule(): void { - $paths = [ - 'isset-used-with-correct-case' => [ - __DIR__ . '/../../Fixture/Expressions/NoIssetRule/Failure/isset-used-with-correct-case.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Expressions/NoIssetRule'), + [ [ 'Language construct isset() should not be used.', - 7, + 16, ], - ], - 'isset-used-with-incorrect-case' => [ - __DIR__ . '/../../Fixture/Expressions/NoIssetRule/Failure/isset-used-with-incorrect-case.php', [ 'Language construct isset() should not be used.', - 7, + 20, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Expressions\NoIssetRule(); diff --git a/test/Integration/Files/DeclareStrictTypesRuleTest.php b/test/Integration/Files/DeclareStrictTypesRuleTest.php index 92d6ffd8..449d4700 100644 --- a/test/Integration/Files/DeclareStrictTypesRuleTest.php +++ b/test/Integration/Files/DeclareStrictTypesRuleTest.php @@ -15,163 +15,89 @@ use Ergebnis\PHPStan\Rules\Files; use Ergebnis\PHPStan\Rules\Test; -use PHPStan\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Files\DeclareStrictTypesRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class DeclareStrictTypesRuleTest extends Test\Integration\AbstractTestCase +final class DeclareStrictTypesRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'file-empty' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-empty.php', - 'file-with-comment-and-declare-strict-types-on' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-comment-and-declare-strict-types-on.php', - 'file-with-comment-and-declare-strict-types-on-and-invalid-casing' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-comment-and-declare-strict-types-on-and-invalid-casing.php', - 'file-with-comment-and-declare-strict-types-on-and-multiple-declares' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-comment-and-declare-strict-types-on-and-multiple-declares.php', - 'file-with-comment-and-declare-strict-types-on-and-namespace-declaration' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-comment-and-declare-strict-types-on-and-namespace-declaration.php', - 'file-with-declare-strict-types-on' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-declare-strict-types-on.php', - 'file-with-declare-strict-types-on-and-invalid-casing' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-declare-strict-types-on-and-invalid-casing.php', - 'file-with-declare-strict-types-on-and-multiple-declares' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-declare-strict-types-on-and-multiple-declares.php', - 'file-with-declare-strict-types-on-and-namespace-declaration' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-declare-strict-types-on-and-namespace-declaration.php', - 'file-with-doc-block-and-declare-strict-types-on' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-doc-block-and-declare-strict-types-on.php', - 'file-with-doc-block-and-declare-strict-types-on-and-invalid-casing' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-doc-block-and-declare-strict-types-on-and-invalid-casing.php', - 'file-with-doc-block-and-declare-strict-types-on-and-multiple-declares' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-doc-block-and-declare-strict-types-on-and-multiple-declares.php', - 'file-with-doc-block-and-declare-strict-types-on-and-namespace-declaration' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-doc-block-and-declare-strict-types-on-and-namespace-declaration.php', - 'file-with-shebang-and-declare-strict-types-on' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-shebang-and-declare-strict-types-on.php', - ]; + use Test\Util\Helper; - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } - - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testDeclareStrictTypesRule(): void { - $paths = [ - 'file-with-comment-and-declare-strict-types-off' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-comment-and-declare-strict-types-off.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule'), + [ [ 'File is missing a "declare(strict_types=1)" declaration.', 5, ], - ], - 'file-with-comment-and-declare-strict-types-off-and-invalid-casing' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-comment-and-declare-strict-types-off-and-invalid-casing.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 5, ], - ], - 'file-with-comment-and-declare-strict-types-off-and-multiple-declares' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-comment-and-declare-strict-types-off-and-multiple-declares.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 5, ], - ], - 'file-with-declare-strict-types-off' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-declare-strict-types-off.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 3, ], - ], - 'file-with-declare-strict-types-off-and-invalid-casing' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-declare-strict-types-off-and-invalid-casing.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 3, ], - ], - 'file-with-declare-strict-types-off-and-multiple-declares' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-declare-strict-types-off-and-multiple-declares.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 3, ], - ], - 'file-with-declare-ticks' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-declare-ticks.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 3, ], - ], - 'file-with-doc-block-and-declare-strict-types-off' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-doc-block-and-declare-strict-types-off.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 7, ], - ], - 'file-with-doc-block-and-declare-strict-types-off-and-invalid-casing' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-doc-block-and-declare-strict-types-off-and-invalid-casing.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 7, ], - ], - 'file-with-doc-block-and-declare-strict-types-off-and-multiple-declares' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-doc-block-and-declare-strict-types-off-and-multiple-declares.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 7, ], - ], - 'file-with-shebang-and-another-one-text-line-before-opening-tag' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-shebang-and-another-one-text-line-before-opening-tag.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 1, ], - ], - 'file-with-shebang-and-declare-strict-types-off' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-shebang-and-declare-strict-types-off.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 1, ], - ], - 'file-with-text-before-opening-tag' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-text-before-opening-tag.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 1, ], - ], - 'file-without-declare-strict-types-and-namespace-declaration' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-without-declare-strict-types-and-namespace-declaration.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 3, ], - ], - 'file-without-declare-strict-types' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-without-declare-strict-types.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 3, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Files\DeclareStrictTypesRule(); diff --git a/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php index 64fc5017..c1d94b7e 100644 --- a/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php @@ -15,60 +15,37 @@ use Ergebnis\PHPStan\Rules\Functions; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Functions\NoNullableReturnTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoNullableReturnTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase +final class NoNullableReturnTypeDeclarationRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'function-with-return-type-declaration' => __DIR__ . '/../../Fixture/Functions/NoNullableReturnTypeDeclarationRule/Success/function-with-return-type-declaration.php', - 'function-without-return-type-declaration' => __DIR__ . '/../../Fixture/Functions/NoNullableReturnTypeDeclarationRule/Success/function-without-return-type-declaration.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoNullableReturnTypeDeclarationRule(): void { - $paths = [ - 'function-with-nullable-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Functions/NoNullableReturnTypeDeclarationRule/Failure/function-with-nullable-return-type-declaration.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Functions/NoNullableReturnTypeDeclarationRule'), + [ [ - 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoNullableReturnTypeDeclarationRule\Failure\foo() has a nullable return type declaration.', - 7, + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoNullableReturnTypeDeclarationRule\baz() has a nullable return type declaration.', + 17, ], - ], - 'function-with-nullable-union-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Functions/NoNullableReturnTypeDeclarationRule/Failure/function-with-nullable-union-return-type-declaration.php', [ - 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoNullableReturnTypeDeclarationRule\Failure\foo() has a nullable return type declaration.', - 7, + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoNullableReturnTypeDeclarationRule\quux() has a nullable return type declaration.', + 22, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Functions\NoNullableReturnTypeDeclarationRule(); diff --git a/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php b/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php index 84f2dc40..62753184 100644 --- a/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php +++ b/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php @@ -15,68 +15,41 @@ use Ergebnis\PHPStan\Rules\Functions; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Functions\NoParameterWithNullDefaultValueRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoParameterWithNullDefaultValueRuleTest extends Test\Integration\AbstractTestCase +final class NoParameterWithNullDefaultValueRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'function-with-parameter-with-non-null-default-value' => __DIR__ . '/../../Fixture/Functions/NoParameterWithNullDefaultValueRule/Success/function-with-parameter-with-non-null-default-value.php', - 'function-with-parameter-without-default-value' => __DIR__ . '/../../Fixture/Functions/NoParameterWithNullDefaultValueRule/Success/function-with-parameter-without-default-value.php', - 'function-without-parameters' => __DIR__ . '/../../Fixture/Functions/NoParameterWithNullDefaultValueRule/Success/function-without-parameters.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoParameterWithNullDefaultValueRule(): void { - $paths = [ - 'function-with-parameter-with-null-default-value' => [ - __DIR__ . '/../../Fixture/Functions/NoParameterWithNullDefaultValueRule/Failure/function-with-parameter-with-null-default-value.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Functions/NoParameterWithNullDefaultValueRule'), + [ [ - 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullDefaultValueRule\Failure\foo() has parameter $bar with null as default value.', - 7, + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullDefaultValueRule\qux() has parameter $bar with null as default value.', + 21, ], - ], - 'function-with-parameter-with-root-namespace-referenced-null-default-value' => [ - __DIR__ . '/../../Fixture/Functions/NoParameterWithNullDefaultValueRule/Failure/function-with-parameter-with-root-namespace-referenced-null-default-value.php', [ - 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullDefaultValueRule\Failure\foo() has parameter $bar with null as default value.', - 7, + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullDefaultValueRule\quux() has parameter $bar with null as default value.', + 26, ], - ], - 'function-with-parameter-with-wrongly-capitalized-null-default-value' => [ - __DIR__ . '/../../Fixture/Functions/NoParameterWithNullDefaultValueRule/Failure/function-with-parameter-with-wrongly-capitalized-null-default-value.php', [ - 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullDefaultValueRule\Failure\foo() has parameter $bar with null as default value.', - 7, + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullDefaultValueRule\quz() has parameter $bar with null as default value.', + 31, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Functions\NoParameterWithNullDefaultValueRule(); diff --git a/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php index 65d7c613..031ab514 100644 --- a/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -15,61 +15,37 @@ use Ergebnis\PHPStan\Rules\Functions; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Functions\NoParameterWithNullableTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoParameterWithNullableTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase +final class NoParameterWithNullableTypeDeclarationRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'function-with-parameter-with-type-declaration' => __DIR__ . '/../../Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Success/function-with-parameter-with-type-declaration.php', - 'function-with-parameter-without-type-declaration' => __DIR__ . '/../../Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Success/function-with-parameter-without-type-declaration.php', - 'function-without-parameters' => __DIR__ . '/../../Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Success/function-without-parameters.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoParameterWithNullableTypeDeclarationRule(): void { - $paths = [ - 'function-with-parameter-with-nullable-type-declaration' => [ - __DIR__ . '/../../Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Failure/function-with-parameter-with-nullable-type-declaration.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Functions/NoParameterWithNullableTypeDeclarationRule'), + [ [ - 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullableTypeDeclarationRule\Failure\foo() has parameter $bar with a nullable type declaration.', - 7, + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullableTypeDeclarationRule\qux() has parameter $bar with a nullable type declaration.', + 21, ], - ], - 'function-with-parameter-with-nullable-union-type-declaration' => [ - __DIR__ . '/../../Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Failure/function-with-parameter-with-nullable-union-type-declaration.php', [ - 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullableTypeDeclarationRule\Failure\foo() has parameter $bar with a nullable type declaration.', - 7, + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullableTypeDeclarationRule\quux() has parameter $bar with a nullable type declaration.', + 26, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Functions\NoParameterWithNullableTypeDeclarationRule(); diff --git a/test/Integration/Methods/FinalInAbstractClassRuleTest.php b/test/Integration/Methods/FinalInAbstractClassRuleTest.php index 40525595..30bf976e 100644 --- a/test/Integration/Methods/FinalInAbstractClassRuleTest.php +++ b/test/Integration/Methods/FinalInAbstractClassRuleTest.php @@ -15,98 +15,43 @@ use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Methods\FinalInAbstractClassRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class FinalInAbstractClassRuleTest extends Test\Integration\AbstractTestCase +final class FinalInAbstractClassRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'abstract-class-with-abstract-method' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithAbstractMethod.php', - 'abstract-class-with-final-protected-method' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithFinalProtectedMethod.php', - 'abstract-class-with-final-public-method' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithFinalPublicMethod.php', - 'abstract-class-with-non-final-constructor' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithNonFinalConstructor.php', - 'abstract-class-with-private-method' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPrivateMethod.php', - 'abstract-class-with-protected-method-and-embeddable-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEmbeddableAnnotationInInlineDocBlock.php', - 'abstract-class-with-protected-method-and-embeddable-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEmbeddableAnnotationInMultilineDocBlock.php', - 'abstract-class-with-protected-method-and-embeddable-attribute' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEmbeddableAttribute.php', - 'abstract-class-with-protected-method-and-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEntityAnnotationInInlineDocBlock.php', - 'abstract-class-with-protected-method-and-entity-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEntityAnnotationInMultilineDocBlock.php', - 'abstract-class-with-protected-method-and-entity-attribute' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEntityAttribute.php', - 'abstract-class-with-protected-method-and-orm-embeddable-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmEmbeddableAnnotationInMultilineDocBlock.php', - 'abstract-class-with-protected-method-and-orm-embeddable-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmEmbeddableAnnotationInInlineDocBlock.php', - 'abstract-class-with-protected-method-and-orm-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmEntityAnnotationInMultilineDocBlock.php', - 'abstract-class-with-protected-method-and-orm-entity-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmEntityAnnotationInInlineDocBlock.php', - 'abstract-class-with-protected-method-and-orm-mapping-embeddable-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmMappingEmbeddableAnnotationInInlineDocBlock.php', - 'abstract-class-with-protected-method-and-orm-mapping-embeddable-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmMappingEmbeddableAnnotationInMultilineDocBlock.php', - 'abstract-class-with-protected-method-and-orm-mapping-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmMappingEntityAnnotationInInlineDocBlock.php', - 'abstract-class-with-protected-method-and-orm-mapping-entity-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmMappingEntityAnnotationInMultilineDocBlock.php', - 'abstract-class-with-public-method-and-embeddable-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEmbeddableAnnotationInInlineDocBlock.php', - 'abstract-class-with-public-method-and-embeddable-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEmbeddableAnnotationInMultilineDocBlock.php', - 'abstract-class-with-public-method-and-embeddable-attribute' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEmbeddableAttribute.php', - 'abstract-class-with-public-method-and-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEntityAnnotationInInlineDocBlock.php', - 'abstract-class-with-public-method-and-entity-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEntityAnnotationInMultilineDocBlock.php', - 'abstract-class-with-public-method-and-entity-attribute' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEntityAttribute.php', - 'abstract-class-with-public-method-and-orm-embeddable-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmEmbeddableAnnotationInMultilineDocBlock.php', - 'abstract-class-with-public-method-and-orm-embeddable-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmEmbeddableAnnotationInInlineDocBlock.php', - 'abstract-class-with-public-method-and-orm-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmEntityAnnotationInMultilineDocBlock.php', - 'abstract-class-with-public-method-and-orm-entity-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmEntityAnnotationInInlineDocBlock.php', - 'abstract-class-with-public-method-and-orm-mapping-embeddable-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmMappingEmbeddableAnnotationInInlineDocBlock.php', - 'abstract-class-with-public-method-and-orm-mapping-embeddable-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmMappingEmbeddableAnnotationInMultilineDocBlock.php', - 'abstract-class-with-public-method-and-orm-mapping-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmMappingEntityAnnotationInInlineDocBlock.php', - 'abstract-class-with-public-method-and-orm-mapping-entity-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmMappingEntityAnnotationInMultilineDocBlock.php', - 'interface-with-public-method' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/InterfaceWithPublicMethod.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testFinalInAbstractClassRule(): void { - $paths = [ - 'abstract-class-with-protected-method' => [ - __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Failure/AbstractClassWithProtectedMethod.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule'), + [ [ \sprintf( 'Method %s::method() is not final, but since the containing class is abstract, it should be.', - Test\Fixture\Methods\FinalInAbstractClassRule\Failure\AbstractClassWithProtectedMethod::class, + Test\Fixture\Methods\FinalInAbstractClassRule\AbstractClassWithProtectedMethod::class, ), 9, ], - ], - 'abstract-class-with-public-method' => [ - __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Failure/AbstractClassWithPublicMethod.php', [ \sprintf( 'Method %s::method() is not final, but since the containing class is abstract, it should be.', - Test\Fixture\Methods\FinalInAbstractClassRule\Failure\AbstractClassWithPublicMethod::class, + Test\Fixture\Methods\FinalInAbstractClassRule\AbstractClassWithPublicMethod::class, ), 9, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Methods\FinalInAbstractClassRule(); diff --git a/test/Integration/Methods/NoConstructorParameterWithDefaultValueRuleTest.php b/test/Integration/Methods/NoConstructorParameterWithDefaultValueRuleTest.php index 59687e38..6edbfcef 100644 --- a/test/Integration/Methods/NoConstructorParameterWithDefaultValueRuleTest.php +++ b/test/Integration/Methods/NoConstructorParameterWithDefaultValueRuleTest.php @@ -15,90 +15,51 @@ use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Methods\NoConstructorParameterWithDefaultValueRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoConstructorParameterWithDefaultValueRuleTest extends Test\Integration\AbstractTestCase +final class NoConstructorParameterWithDefaultValueRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'constructor-in-anonymous-class-with-parameter-without-default-value' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/constructor-in-anonymous-class-with-parameter-without-default-value.php', - 'constructor-in-anonymous-class-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/constructor-in-anonymous-class-without-parameters.php', - 'constructor-in-class-with-parameter-without-default-value' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/ConstructorInClassWithParameterWithoutDefaultValue.php', - 'constructor-in-class-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/ConstructorInClassWithoutParameters.php', - // traits are not supported - 'constructor-in-trait-with-parameter-with-default-value' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/ConstructorInTraitWithParameterWithDefaultValue.php', - 'constructor-in-trait-with-parameter-without-default-value' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/ConstructorInTraitWithParameterWithoutDefaultValue.php', - 'constructor-in-trait-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/ConstructorInTraitWithoutParameters.php', - // non-constructor-methods - 'method-in-anonymous-class-with-parameter-with-default-value' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/method-in-anonymous-class-with-parameter-with-default-value.php', - 'method-in-class-with-parameter-with-default-value' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/MethodInClassWithParameterWithDefaultValue.php', - 'method-in-trait-with-parameter-with-default-value' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/MethodInTraitWithParameterWithDefaultValue.php', - ]; + use Test\Util\Helper; - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } - - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoConstructorParameterWithDefaultValueRule(): void { - $paths = [ - 'constructor-in-anonymous-class-with-parameter-with-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Failure/constructor-in-anonymous-class-with-parameter-with-default-value.php', - [ - 'Constructor in anonymous class has parameter $bar with default value.', - 8, - ], - ], - 'constructor-with-wrong-capitalization-in-anonymous-class-with-parameter-with-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Failure/constructor-with-wrong-capitalization-in-anonymous-class-with-parameter-with-default-value.php', - [ - 'Constructor in anonymous class has parameter $bar with default value.', - 8, - ], - ], - 'constructor-in-class-with-parameter-with-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Failure/ConstructorInClassWithParameterWithDefaultValue.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule'), + [ [ \sprintf( 'Constructor in %s has parameter $bar with default value.', - Test\Fixture\Methods\NoConstructorParameterWithDefaultValueRule\Failure\ConstructorInClassWithParameterWithDefaultValue::class, + Test\Fixture\Methods\NoConstructorParameterWithDefaultValueRule\ConstructorInClassWithParameterWithDefaultValue::class, ), 9, ], - ], - 'constructor-with-wrong-capitalization-in-class-with-parameter-with-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Failure/ConstructorWithWrongCapitalizationInClassWithParameterWithDefaultValue.php', [ \sprintf( 'Constructor in %s has parameter $bar with default value.', - Test\Fixture\Methods\NoConstructorParameterWithDefaultValueRule\Failure\ConstructorWithWrongCapitalizationInClassWithParameterWithDefaultValue::class, + Test\Fixture\Methods\NoConstructorParameterWithDefaultValueRule\ConstructorWithWrongCapitalizationInClassWithParameterWithDefaultValue::class, ), 9, ], + [ + 'Constructor in anonymous class has parameter $bar with default value.', + 26, + ], + [ + 'Constructor in anonymous class has parameter $bar with default value.', + 32, + ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Methods\NoConstructorParameterWithDefaultValueRule(); diff --git a/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php index 29bf375c..a565a4b7 100644 --- a/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php @@ -15,108 +15,65 @@ use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Methods\NoNullableReturnTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoNullableReturnTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase +final class NoNullableReturnTypeDeclarationRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'method-in-anonymous-class-with-return-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInAnonymousClassWithReturnTypeDeclaration.php', - 'method-in-anonymous-class-without-return-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInAnonymousClassWithoutReturnTypeDeclaration.php', - 'method-in-class-with-return-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInClassWithReturnTypeDeclaration.php', - 'method-in-class-without-return-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInClassWithoutReturnTypeDeclaration.php', - 'method-in-interface-with-return-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInInterfaceWithReturnTypeDeclaration.php', - 'method-in-interface-without-return-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInInterfaceWithoutReturnTypeDeclaration.php', - // traits are currently not supported - 'method-in-trait-with-nullable-return-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInTraitWithNullableReturnTypeDeclaration.php', - 'method-in-trait-with-return-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInTraitWithReturnTypeDeclaration.php', - 'method-in-trait-without-return-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInTraitWithoutReturnTypeDeclaration.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoNullableReturnTypeDeclarationRule(): void { - $paths = [ - 'method-in-anonymous-class-with-nullable-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInAnonymousClassWithNullableReturnTypeDeclaration.php', - [ - 'Method toString() in anonymous class has a nullable return type declaration.', - 12, - ], - ], - 'method-in-anonymous-class-with-nullable-union-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInAnonymousClassWithNullableUnionReturnTypeDeclaration.php', - [ - 'Method toString() in anonymous class has a nullable return type declaration.', - 12, - ], - ], - 'method-in-class-with-nullable-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInClassWithNullableReturnTypeDeclaration.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule'), + [ [ \sprintf( 'Method %s::toString() has a nullable return type declaration.', - Test\Fixture\Methods\NoNullableReturnTypeDeclarationRule\Failure\MethodInClassWithNullableReturnTypeDeclaration::class, + Test\Fixture\Methods\NoNullableReturnTypeDeclarationRule\MethodInClassWithNullableReturnTypeDeclaration::class, ), 9, ], - ], - 'method-in-class-with-nullable-union-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInClassWithNullableUnionReturnTypeDeclaration.php', [ \sprintf( 'Method %s::toString() has a nullable return type declaration.', - Test\Fixture\Methods\NoNullableReturnTypeDeclarationRule\Failure\MethodInClassWithNullableUnionReturnTypeDeclaration::class, + Test\Fixture\Methods\NoNullableReturnTypeDeclarationRule\MethodInClassWithNullableUnionReturnTypeDeclaration::class, ), 9, ], - ], - 'method-in-interface-with-nullable-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInInterfaceWithNullableReturnTypeDeclaration.php', [ \sprintf( 'Method %s::toString() has a nullable return type declaration.', - Test\Fixture\Methods\NoNullableReturnTypeDeclarationRule\Failure\MethodInInterfaceWithNullableReturnTypeDeclaration::class, + Test\Fixture\Methods\NoNullableReturnTypeDeclarationRule\MethodInInterfaceWithNullableReturnTypeDeclaration::class, ), 9, ], - ], - 'method-in-interface-with-nullable-union-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInInterfaceWithNullableUnionReturnTypeDeclaration.php', [ \sprintf( 'Method %s::toString() has a nullable return type declaration.', - Test\Fixture\Methods\NoNullableReturnTypeDeclarationRule\Failure\MethodInInterfaceWithNullableUnionReturnTypeDeclaration::class, + Test\Fixture\Methods\NoNullableReturnTypeDeclarationRule\MethodInInterfaceWithNullableUnionReturnTypeDeclaration::class, ), 9, ], + [ + 'Method toString() in anonymous class has a nullable return type declaration.', + 22, + ], + [ + 'Method toString() in anonymous class has a nullable return type declaration.', + 29, + ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Methods\NoNullableReturnTypeDeclarationRule(); diff --git a/test/Integration/Methods/NoParameterWithContainerTypeDeclarationRuleTest.php b/test/Integration/Methods/NoParameterWithContainerTypeDeclarationRuleTest.php index bfb4558f..a70fd387 100644 --- a/test/Integration/Methods/NoParameterWithContainerTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoParameterWithContainerTypeDeclarationRuleTest.php @@ -15,139 +15,91 @@ use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; use Psr\Container; /** * @covers \Ergebnis\PHPStan\Rules\Methods\NoParameterWithContainerTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoParameterWithContainerTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase +final class NoParameterWithContainerTypeDeclarationRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'anonymous-class-with-method-with-parameter-with-class-implementing-container-interface-as-type-declaration-where-name-is-excluded' => __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/anonymous-class-with-method-with-parameter-with-class-implementing-container-interface-as-type-declaration-where-name-is-excluded.php', - 'anonymous-class-with-method-with-parameter-with-other-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/anonymous-class-with-method-with-parameter-with-other-type-declaration.php', - 'anonymous-class-with-method-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/anonymous-class-with-method-without-parameter.php', - 'class-with-method-with-parameter-with-class-implementing-container-interface-as-type-declaration-where-name-is-excluded' => __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/ClassWithMethodWithParameterWithClassImplementingContainerInterfaceAsTypeDeclarationWhereNameIsExcluded.php', - 'class-with-method-with-parameter-with-other-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/ClassWithMethodWithParameterWithOtherTypeDeclaration.php', - 'class-with-method-without-parameter' => __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/ClassWithMethodWithoutParameter.php', - 'interface-with-method-with-parameter-with-class-implementing-container-interface-as-type-declaration-where-name-is-excluded' => __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/InterfaceWithMethodWithParameterWithContainerInterfaceAsTypeDeclarationWhereNameIsExcluded.php', - 'interface-with-method-with-parameter-with-other-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/InterfaceWithMethodWithParameterWithOtherTypeDeclaration.php', - 'interface-with-method-without-parameter' => __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/InterfaceWithMethodWithoutParameter.php', - ]; + use Test\Util\Helper; - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } - - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoParameterWithContainerTypeDeclarationRuleTest(): void { - $paths = [ - 'anonymous-class-with-method-with-parameter-with-class-implementing-container-interface-as-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/anonymous-class-with-method-with-parameter-with-class-implementing-container-interface-as-type-declaration.php', - [ - \sprintf( - 'Method __construct() in anonymous class has a parameter $container with a type declaration of %s, but containers should not be injected.', - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\ClassImplementingContainerInterface::class, - ), - 9, - ], - ], - 'anonymous-class-with-method-with-parameter-with-container-interface-as-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/anonymous-class-with-method-with-parameter-with-container-interface-as-type-declaration.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule'), + [ [ \sprintf( - 'Method __construct() in anonymous class has a parameter $container with a type declaration of %s, but containers should not be injected.', - Container\ContainerInterface::class, + 'Method %s::method() has a parameter $container with a type declaration of %s, but containers should not be injected.', + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\ClassImplementingContainerInterfaceWithMethodWithParameterWithSelfAsTypeDeclaration::class, + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\ClassImplementingContainerInterfaceWithMethodWithParameterWithSelfAsTypeDeclaration::class, ), 11, ], - ], - 'anonymous-class-with-method-with-parameter-with-interface-extending-container-interface-as-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/anonymous-class-with-method-with-parameter-with-interface-extending-container-interface-as-type-declaration.php', [ \sprintf( - 'Method __construct() in anonymous class has a parameter $container with a type declaration of %s, but containers should not be injected.', - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\InterfaceExtendingContainerInterface::class, + 'Method %s::method() has a parameter $container with a type declaration of %s, but containers should not be injected.', + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\ClassWithMethodWithParameterWithClassImplementingContainerInterfaceAsTypeDeclaration::class, + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\ClassImplementingContainerInterface::class, ), 9, ], - ], - 'class-implementing-container-interface-with-method-with-parameter-with-self-as-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/ClassImplementingContainerInterfaceWithMethodWithParameterWithSelfAsTypeDeclaration.php', [ \sprintf( 'Method %s::method() has a parameter $container with a type declaration of %s, but containers should not be injected.', - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\ClassImplementingContainerInterfaceWithMethodWithParameterWithSelfAsTypeDeclaration::class, - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\ClassImplementingContainerInterfaceWithMethodWithParameterWithSelfAsTypeDeclaration::class, + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\ClassWithMethodWithParameterWithContainerInterfaceAsTypeDeclaration::class, + Container\ContainerInterface::class, ), 11, ], - ], - 'class-with-method-with-parameter-with-class-implementing-container-interface-as-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/ClassWithMethodWithParameterWithClassImplementingContainerInterfaceAsTypeDeclaration.php', [ \sprintf( 'Method %s::method() has a parameter $container with a type declaration of %s, but containers should not be injected.', - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\ClassWithMethodWithParameterWithClassImplementingContainerInterfaceAsTypeDeclaration::class, - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\ClassImplementingContainerInterface::class, + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\ClassWithMethodWithParameterWithInterfaceExtendingContainerInterfaceAsTypeDeclaration::class, + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\InterfaceExtendingContainerInterface::class, ), 9, ], - ], - 'class-with-method-with-parameter-with-container-interface-as-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/ClassWithMethodWithParameterWithContainerInterfaceAsTypeDeclaration.php', [ \sprintf( 'Method %s::method() has a parameter $container with a type declaration of %s, but containers should not be injected.', - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\ClassWithMethodWithParameterWithContainerInterfaceAsTypeDeclaration::class, + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\InterfaceWithMethodWithParameterWithContainerInterfaceAsTypeDeclaration::class, Container\ContainerInterface::class, ), 11, ], - ], - 'class-with-method-with-parameter-with-interface-extending-container-interface-as-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/ClassWithMethodWithParameterWithInterfaceExtendingContainerInterfaceAsTypeDeclaration.php', [ \sprintf( - 'Method %s::method() has a parameter $container with a type declaration of %s, but containers should not be injected.', - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\ClassWithMethodWithParameterWithInterfaceExtendingContainerInterfaceAsTypeDeclaration::class, - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\InterfaceExtendingContainerInterface::class, + 'Method __construct() in anonymous class has a parameter $container with a type declaration of %s, but containers should not be injected.', + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\ClassImplementingContainerInterface::class, ), - 9, + 29, ], - ], - 'interface-with-method-with-parameter-with-container-interface-as-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/InterfaceWithMethodWithParameterWithContainerInterfaceAsTypeDeclaration.php', [ \sprintf( - 'Method %s::method() has a parameter $container with a type declaration of %s, but containers should not be injected.', - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\InterfaceWithMethodWithParameterWithContainerInterfaceAsTypeDeclaration::class, + 'Method __construct() in anonymous class has a parameter $container with a type declaration of %s, but containers should not be injected.', Container\ContainerInterface::class, ), - 11, + 36, + ], + [ + \sprintf( + 'Method __construct() in anonymous class has a parameter $container with a type declaration of %s, but containers should not be injected.', + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\InterfaceExtendingContainerInterface::class, + ), + 43, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Methods\NoParameterWithContainerTypeDeclarationRule( diff --git a/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php b/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php index 5ffc0c92..6783d93b 100644 --- a/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php +++ b/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php @@ -15,141 +15,83 @@ use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Methods\NoParameterWithNullDefaultValueRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoParameterWithNullDefaultValueRuleTest extends Test\Integration\AbstractTestCase +final class NoParameterWithNullDefaultValueRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'method-in-anonymous-class-with-parameter-with-non-null-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/method-in-anonymous-class-with-parameter-with-non-null-default-value.php', - 'method-in-anonymous-class-with-parameter-without-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/method-in-anonymous-class-with-parameter-without-default-value.php', - 'method-in-anonymous-class-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/method-in-anonymous-class-without-parameters.php', - 'method-in-class-with-parameter-with-non-null-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInClassWithParameterWithNonNullDefaultValue.php', - 'method-in-class-with-parameter-without-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInClassWithParameterWithoutDefaultValue.php', - 'method-in-class-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInClassWithoutParameters.php', - 'method-in-interface-with-parameter-with-non-null-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInInterfaceWithParameterWithNonNullDefaultValue.php', - 'method-in-interface-with-parameter-without-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInInterfaceWithParameterWithoutDefaultValue.php', - 'method-in-interface-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInInterfaceWithoutParameters.php', - // traits are not supported - 'method-in-trait-with-parameter-with-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInTraitWithParameterWithDefaultValue.php', - 'method-in-trait-with-parameter-with-non-null-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInTraitWithParameterWithNonNullDefaultValue.php', - 'method-in-trait-with-parameter-with-root-namespace-referenced-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInTraitWithParameterWithRootNamespaceReferencedNullDefaultValue.php', - 'method-in-trait-with-parameter-with-wrongly-capitalized-null-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInTraitWithParameterWithWronlgyCapitalizedNullDefaultValue.php', - 'method-in-trait-with-parameter-without-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInTraitWithParameterWithoutDefaultValue.php', - 'method-in-trait-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInTraitWithoutParameters.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoParameterWithNullDefaultValueRule(): void { - $paths = [ - 'method-in-anonymous-class-with-parameter-with-null-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/method-in-anonymous-class-with-parameter-with-null-default-value.php', - [ - 'Method foo() in anonymous class has parameter $bar with null as default value.', - 8, - ], - ], - 'method-in-anonymous-class-with-parameter-with-root-namespace-referenced-null-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/method-in-anonymous-class-with-parameter-with-root-namespace-referenced-null-default-value.php', - [ - 'Method foo() in anonymous class has parameter $bar with null as default value.', - 8, - ], - ], - 'method-in-anonymous-class-with-parameter-with-wrongly-capitalized-null-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/method-in-anonymous-class-with-parameter-with-wrongly-capitalized-null-default-value.php', - [ - 'Method foo() in anonymous class has parameter $bar with null as default value.', - 8, - ], - ], - 'method-in-class-with-parameter-with-null-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/MethodInClassWithParameterWithNullDefaultValue.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule'), + [ [ \sprintf( 'Method %s::foo() has parameter $bar with null as default value.', - Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\Failure\MethodInClassWithParameterWithNullDefaultValue::class, + Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\MethodInClassWithParameterWithNullDefaultValue::class, ), 9, ], - ], - 'method-in-class-with-parameter-with-root-namespace-referenced-null-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/MethodInClassWithParameterWithRootNamespaceReferencedNullDefaultValue.php', [ \sprintf( 'Method %s::foo() has parameter $bar with null as default value.', - Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\Failure\MethodInClassWithParameterWithRootNamespaceReferencedNullDefaultValue::class, + Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\MethodInClassWithParameterWithRootNamespaceReferencedNullDefaultValue::class, ), 9, ], - ], - 'method-in-class-with-parameter-with-wrongly-capitalized-null-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/MethodInClassWithParameterWithWronglyCapitalizedNullDefaultValue.php', [ \sprintf( 'Method %s::foo() has parameter $bar with null as default value.', - Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\Failure\MethodInClassWithParameterWithWronglyCapitalizedNullDefaultValue::class, + Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\MethodInClassWithParameterWithWronglyCapitalizedNullDefaultValue::class, ), 9, ], - ], - 'method-in-interface-with-parameter-with-null-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/MethodInInterfaceWithParameterWithNullDefaultValue.php', [ \sprintf( 'Method %s::foo() has parameter $bar with null as default value.', - Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\Failure\MethodInInterfaceWithParameterWithNullDefaultValue::class, + Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\MethodInInterfaceWithParameterWithNullDefaultValue::class, ), 9, ], - ], - 'method-in-interface-with-parameter-with-root-namespace-referenced-null-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/MethodInInterfaceWithParameterWithRootNamespaceReferencedNullDefaultValue.php', [ \sprintf( 'Method %s::foo() has parameter $bar with null as default value.', - Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\Failure\MethodInInterfaceWithParameterWithRootNamespaceReferencedNullDefaultValue::class, + Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\MethodInInterfaceWithParameterWithRootNamespaceReferencedNullDefaultValue::class, ), 9, ], - ], - 'method-in-interface-with-parameter-wrongly-capitalized-null-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/MethodInInterfaceWithParameterWithWronlgyCapitalizedNullDefaultValue.php', [ \sprintf( 'Method %s::foo() has parameter $bar with null as default value.', - Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\Failure\MethodInInterfaceWithParameterWithWronlgyCapitalizedNullDefaultValue::class, + Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\MethodInInterfaceWithParameterWithWronlgyCapitalizedNullDefaultValue::class, ), 9, ], + [ + 'Method foo() in anonymous class has parameter $bar with null as default value.', + 28, + ], + [ + 'Method foo() in anonymous class has parameter $bar with null as default value.', + 35, + ], + [ + 'Method foo() in anonymous class has parameter $bar with null as default value.', + 42, + ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Methods\NoParameterWithNullDefaultValueRule(); diff --git a/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php index c488bb9b..c4f81442 100644 --- a/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -15,111 +15,65 @@ use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Methods\NoParameterWithNullableTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoParameterWithNullableTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase +final class NoParameterWithNullableTypeDeclarationRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'method-in-anonymous-class-with-parameter-with-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/method-in-anonymous-class-with-parameter-with-type-declaration.php', - 'method-in-anonymous-class-with-parameter-without-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/method-in-anonymous-class-with-parameter-without-type-declaration.php', - 'method-in-anonymous-class-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/method-in-anonymous-class-without-parameters.php', - 'method-in-class-with-parameter-with-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/MethodInClassWithParameterWithTypeDeclaration.php', - 'method-in-class-with-parameter-without-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/MethodInClassWithParameterWithoutTypeDeclaration.php', - 'method-in-class-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/MethodInClassWithoutParameters.php', - 'method-in-interface-with-parameter-with-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/MethodInInterfaceWithParameterWithTypeDeclaration.php', - 'method-in-interface-with-parameter-without-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/MethodInInterfaceWithParameterWithoutTypeDeclaration.php', - 'method-in-interface-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/MethodInInterfaceWithoutParameters.php', - // traits are not supported - 'method-in-trait-with-parameter-with-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/MethodInTraitWithParameterWithTypeDeclaration.php', - 'method-in-trait-with-parameter-without-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/MethodInTraitWithParameterWithoutTypeDeclaration.php', - 'method-in-trait-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/MethodInTraitWithoutParameters.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoParameterWithNullableTypeDeclarationRule(): void { - $paths = [ - 'method-in-anonymous-class-with-parameter-with-nullable-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Failure/method-in-anonymous-class-with-parameter-with-nullable-type-declaration.php', - [ - 'Method foo() in anonymous class has parameter $bar with a nullable type declaration.', - 8, - ], - ], - 'method-in-anonymous-class-with-parameter-with-nullable-union-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Failure/method-in-anonymous-class-with-parameter-with-nullable-union-type-declaration.php', - [ - 'Method foo() in anonymous class has parameter $bar with a nullable type declaration.', - 8, - ], - ], - 'method-in-class-with-parameter-with-nullable-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Failure/MethodInClassWithParameterWithNullableTypeDeclaration.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule'), + [ [ \sprintf( 'Method %s::foo() has parameter $bar with a nullable type declaration.', - Test\Fixture\Methods\NoParameterWithNullableTypeDeclarationRule\Failure\MethodInClassWithParameterWithNullableTypeDeclaration::class, + Test\Fixture\Methods\NoParameterWithNullableTypeDeclarationRule\MethodInClassWithParameterWithNullableTypeDeclaration::class, ), 9, ], - ], - 'method-in-class-with-parameter-with-nullable-union-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Failure/MethodInClassWithParameterWithNullableUnionTypeDeclaration.php', [ \sprintf( 'Method %s::foo() has parameter $bar with a nullable type declaration.', - Test\Fixture\Methods\NoParameterWithNullableTypeDeclarationRule\Failure\MethodInClassWithParameterWithNullableUnionTypeDeclaration::class, + Test\Fixture\Methods\NoParameterWithNullableTypeDeclarationRule\MethodInClassWithParameterWithNullableUnionTypeDeclaration::class, ), 9, ], - ], - 'method-in-interface-with-parameter-with-nullable-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Failure/MethodInInterfaceWithParameterWithNullableTypeDeclaration.php', [ \sprintf( 'Method %s::foo() has parameter $bar with a nullable type declaration.', - Test\Fixture\Methods\NoParameterWithNullableTypeDeclarationRule\Failure\MethodInInterfaceWithParameterWithNullableTypeDeclaration::class, + Test\Fixture\Methods\NoParameterWithNullableTypeDeclarationRule\MethodInInterfaceWithParameterWithNullableTypeDeclaration::class, ), 9, ], - ], - 'method-in-interface-with-parameter-with-nullable-union-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Failure/MethodInInterfaceWithParameterWithNullableUnionTypeDeclaration.php', [ \sprintf( 'Method %s::foo() has parameter $bar with a nullable type declaration.', - Test\Fixture\Methods\NoParameterWithNullableTypeDeclarationRule\Failure\MethodInInterfaceWithParameterWithNullableUnionTypeDeclaration::class, + Test\Fixture\Methods\NoParameterWithNullableTypeDeclarationRule\MethodInInterfaceWithParameterWithNullableUnionTypeDeclaration::class, ), 9, ], + [ + 'Method foo() in anonymous class has parameter $bar with a nullable type declaration.', + 28, + ], + [ + 'Method foo() in anonymous class has parameter $bar with a nullable type declaration.', + 35, + ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Methods\NoParameterWithNullableTypeDeclarationRule(); diff --git a/test/Integration/Methods/PrivateInFinalClassRuleTest.php b/test/Integration/Methods/PrivateInFinalClassRuleTest.php index 41436b14..e00391b5 100644 --- a/test/Integration/Methods/PrivateInFinalClassRuleTest.php +++ b/test/Integration/Methods/PrivateInFinalClassRuleTest.php @@ -15,68 +15,47 @@ use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Methods\PrivateInFinalClassRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class PrivateInFinalClassRuleTest extends Test\Integration\AbstractTestCase +final class PrivateInFinalClassRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'abstract-class-with-protected-method' => __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Success/AbstractClassWithProtectedMethod.php', - 'class-with-protected-method' => __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Success/ClassWithProtectedMethod.php', - 'final-class-with-private-method' => __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Success/FinalClassWithPrivateMethod.php', - 'final-class-with-protected-method-extending-class-extending-class-with-same-protected-method' => __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Success/FinalClassWithProtectedMethodExtendingClassExtendingClassWithSameProtectedMethod.php', - 'final-class-with-protected-method-extending-class-with-same-protected-method' => __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Success/FinalClassWithProtectedMethodExtendingClassWithSameProtectedMethod.php', - 'final-class-with-protected-method-from-trait' => __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Success/FinalClassWithProtectedMethodFromTrait.php', - 'final-class-with-public-method' => __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Success/FinalClassWithPublicMethod.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testPrivateInFinalClassRule(): void { - $paths = [ - 'anonymous-class-with-protected-method' => [ - __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Failure/AnonymousClassWithProtectedMethod.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule'), + [ [ - 'Method method() in anonymous class is protected, but since the containing class is final, it can be private.', - 8, + \sprintf( + 'Method %s::method() is protected, but since the containing class is final, it can be private.', + Test\Fixture\Methods\PrivateInFinalClassRule\FinalClassWithProtectedMethod::class, + ), + 9, ], - ], - 'final-class-with-protected-method' => [ - __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Failure/FinalClassWithProtectedMethod.php', [ \sprintf( 'Method %s::method() is protected, but since the containing class is final, it can be private.', - Test\Fixture\Methods\PrivateInFinalClassRule\Failure\FinalClassWithProtectedMethod::class, + Test\Fixture\Methods\PrivateInFinalClassRule\FinalClassWithProtectedMethodFromTrait::class, ), 9, ], + [ + 'Method method() in anonymous class is protected, but since the containing class is final, it can be private.', + 8, + ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Methods\PrivateInFinalClassRule(); diff --git a/test/Integration/Statements/NoSwitchRuleTest.php b/test/Integration/Statements/NoSwitchRuleTest.php index 24e62d77..eb615f5d 100644 --- a/test/Integration/Statements/NoSwitchRuleTest.php +++ b/test/Integration/Statements/NoSwitchRuleTest.php @@ -15,59 +15,37 @@ use Ergebnis\PHPStan\Rules\Statements; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Statements\NoSwitchRule * + * @extends \PHPStan\Testing\RuleTestCase + * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier */ -final class NoSwitchRuleTest extends Test\Integration\AbstractTestCase +final class NoSwitchRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'isset-not-used' => __DIR__ . '/../../Fixture/Statements/NoSwitchRule/Success/switch-not-used.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoSwitchRule(): void { - $paths = [ - 'switch-used-with-correct-case' => [ - __DIR__ . '/../../Fixture/Statements/NoSwitchRule/Failure/switch-used-with-correct-case.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Statements/NoSwitchRule'), + [ [ 'Control structures using switch should not be used.', 7, ], - ], - 'switch-used-with-incorrect-case' => [ - __DIR__ . '/../../Fixture/Statements/NoSwitchRule/Failure/switch-used-with-incorrect-case.php', [ 'Control structures using switch should not be used.', 7, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Statements\NoSwitchRule(); diff --git a/test/Util/Helper.php b/test/Util/Helper.php new file mode 100644 index 00000000..ec2004da --- /dev/null +++ b/test/Util/Helper.php @@ -0,0 +1,35 @@ + + */ + private static function phpFilesIn(string $directory): array + { + $finder = Finder\Finder::create() + ->files() + ->in($directory) + ->name('/\.php$/') + ->sortByName(); + + return \array_map(static function (Finder\SplFileInfo $fileInfo): string { + return $fileInfo->getPathname(); + }, \iterator_to_array($finder, false)); + } +}