From 5b65bb52fa500e1fe591eb6ff410cd0292d01185 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 4 Oct 2018 00:50:07 +0800 Subject: [PATCH] tests: fix conflicting validating by autoloading only Wrong files in tests --- composer.json | 98 ++++++++++++++++++- .../RemoveNodeRector/Correct/correct2.php.inc | 14 +++ .../RemoveNodeRector/Wrong/wrong2.php.inc | 14 +++ .../PHPUnit/AbstractRectorTestCase.php | 10 +- .../FilesFinder/FilesFinderTest.php | 33 +++++-- .../Correct/correct2.php.inc | 2 +- .../DoctrineRepositoryAsServiceTest.php | 2 +- .../{wrong2.php.inc => PostController.php} | 2 +- .../Correct/correct2.php.inc | 3 + .../Source/AnotherTrait.php | 8 ++ .../Wrong/wrong2.php.inc | 3 + ...Test.php => FunctionReplaceRectorTest.php} | 4 +- .../Correct/correct.php.inc | 2 +- .../Correct/correct2.php.inc | 2 + .../Source/PHPUnit_Framework_Something.php | 6 ++ .../Source/PHPUnit_Framework_TestCase.php | 6 ++ .../Source/PHPUnit_Something.php | 6 ++ .../Source/PHPUnit_SpecialClass.php | 6 ++ .../Wrong/wrong.php.inc | 2 +- .../Wrong/wrong2.php.inc | 2 + .../Correct/correct.php.inc | 2 +- .../Correct/correct2.php.inc | 2 +- .../ParentTypehintedArgumentRectorTest.php | 4 +- .../Source/ParserInterface.php | 2 +- .../{wrong2.php.inc => MyMetadataFactory.php} | 2 +- ... SomeClassImplementingParserInterface.php} | 2 +- .../ParentTypehintedArgumentRector/config.yml | 12 +-- .../Wrong/wrong.php.inc | 2 +- ...p => ChangeMethodVisibilityRectorTest.php} | 2 +- .../Source/ParentObject.php | 4 +- .../Wrong/wrong2.php.inc | 2 +- tests/Source/SomeClass.php | 10 ++ 32 files changed, 234 insertions(+), 37 deletions(-) rename tests/Rector/Architecture/DoctrineRepositoryAsService/Wrong/{wrong2.php.inc => PostController.php} (85%) create mode 100644 tests/Rector/Class_/ParentClassToTraitsRector/Source/AnotherTrait.php rename tests/Rector/Function_/FunctionReplaceRector/{FunctionReplacerRectorTest.php => FunctionReplaceRectorTest.php} (82%) create mode 100644 tests/Rector/Namespace_/PseudoNamespaceToNamespaceRector/Source/PHPUnit_Framework_Something.php create mode 100644 tests/Rector/Namespace_/PseudoNamespaceToNamespaceRector/Source/PHPUnit_Framework_TestCase.php create mode 100644 tests/Rector/Namespace_/PseudoNamespaceToNamespaceRector/Source/PHPUnit_Something.php create mode 100644 tests/Rector/Namespace_/PseudoNamespaceToNamespaceRector/Source/PHPUnit_SpecialClass.php rename tests/Rector/Typehint/ParentTypehintedArgumentRector/Wrong/{wrong2.php.inc => MyMetadataFactory.php} (78%) rename tests/Rector/Typehint/ParentTypehintedArgumentRector/Wrong/{wrong.php.inc => SomeClassImplementingParserInterface.php} (78%) rename tests/Rector/Visibility/ChangeMethodVisibilityRector/{ChangePropertyVisibilityRectorTest.php => ChangeMethodVisibilityRectorTest.php} (91%) create mode 100644 tests/Source/SomeClass.php diff --git a/composer.json b/composer.json index ce2feac5913..9ab13014d33 100644 --- a/composer.json +++ b/composer.json @@ -85,8 +85,102 @@ "packages/Symfony/tests", "packages/Twig/tests", "packages/Utils/tests", - "tests/Issues", - "tests/Rector" + "tests/Source", + "tests/Rector/Architecture/DependencyInjection/ActionInjectionToConstructorInjectionRector/Wrong", + "tests/Rector/Architecture/DependencyInjection/AnnotatedPropertyInjectToConstructorInjectionRector/Wrong", + "tests/Issues/Issue594/Wrong", + "tests/Rector/Assign/PropertyAssignToMethodCallRector/Wrong", + "tests/Rector/RectorOrder/Wrong", + "tests/Rector/DomainDrivenDesign/ValueObjectRemoverRector/Wrong", + "tests/Rector/DomainDrivenDesign/ValueObjectRemoverDocBlockRector/Wrong", + "tests/Rector/StaticCall/StaticCallToFunctionRector/Wrong", + "tests/Rector/MethodCall/MethodCallToAnotherMethodCallWithArgumentsRector/Wrong", + "tests/Rector/MethodCall/StaticMethodNameReplacerRector/Wrong", + "tests/Rector/MethodCall/MethodNameReplacerRector/Wrong", + "tests/Rector/MethodBody/ReturnThisRemoveRector/Wrong", + "tests/Rector/MethodBody/NormalToFluentRector/Wrong", + "tests/Rector/MethodBody/FluentReplaceRector/Wrong", + "tests/Rector/MagicDisclosure/GetAndSetToMethodCallRector/Wrong", + "tests/Rector/MagicDisclosure/UnsetAndIssetToMethodCallRector/Wrong", + "tests/Rector/MagicDisclosure/ToStringToMethodCallRector/Wrong", + "tests/Rector/Typehint/ReturnTypehintRector/Wrong", + "tests/Rector/Typehint/ParentTypehintedArgumentRector/Wrong", + "tests/Rector/Argument/ArgumentRemoverRector/Wrong", + "tests/Rector/Argument/ArgumentAdderRector/Wrong", + "tests/Rector/Argument/ArgumentDefaultValueReplacerRector/Wrong", + "tests/Rector/Namespace_/NamespaceReplacerRector/Wrong", + "tests/Rector/Namespace_/PseudoNamespaceToNamespaceRector/Wrong", + "tests/Rector/Namespace_/PseudoNamespaceToNamespaceRector/Source", + "tests/Rector/Function_/FunctionToStaticCallRector/Wrong", + "tests/Rector/Function_/FunctionReplaceRector/Wrong", + "tests/Rector/Function_/FunctionToMethodCallRector/Wrong", + "tests/Rector/Property/PropertyNameReplacerRector/Wrong", + "tests/Rector/Property/PropertyToMethodRector/Wrong", + "tests/Rector/Architecture/DependencyInjection/AnnotatedPropertyInjectToConstructorInjectionRector/Wrong", + "tests/Rector/Architecture/DependencyInjection/ActionInjectionToConstructorInjectionRector/Wrong", + "tests/Rector/Architecture/DoctrineRepositoryAsService/Wrong", + "tests/Rector/Interface_/MergeInterfacesRector/Wrong", + "tests/Rector/Visibility/ChangeMethodVisibilityRector/Wrong", + "tests/Rector/Visibility/ChangePropertyVisibilityRector/Wrong", + "tests/Rector/Visibility/ChangeConstantVisibilityRector/Wrong", + "tests/Rector/Annotation/AnnotationReplacerRector/Wrong", + "tests/Rector/CodeQuality/UnnecessaryTernaryExpressionRector/Wrong", + "tests/Rector/CodeQuality/InArrayAndArrayKeysToArrayKeyExistsRector/Wrong", + "tests/Rector/Constant/ClassConstantReplacerRector/Wrong", + "tests/Rector/Constant/RenameClassConstantsUseToStringsRector/Wrong", + "tests/Rector/Class_/ParentClassToTraitsRector/Wrong", + "tests/Rector/Class_/ClassReplacerRector/Wrong", + "packages/PHPUnit/tests/Rector/DelegateExceptionArgumentsRector/Wrong", + "packages/PHPUnit/tests/Rector/ArrayToYieldDataProviderRector/Wrong", + "packages/PHPUnit/tests/Rector/ExceptionAnnotationRector/Wrong", + "packages/PHPUnit/tests/Rector/TryCatchToExpectExceptionRector/Wrong", + "packages/PHPUnit/tests/Rector/SpecificMethod/AssertPropertyExistsRector/Wrong", + "packages/PHPUnit/tests/Rector/SpecificMethod/AssertIssetToSpecificMethodRector/Wrong", + "packages/PHPUnit/tests/Rector/SpecificMethod/AssertRegExpRector/Wrong", + "packages/PHPUnit/tests/Rector/SpecificMethod/AssertComparisonToSpecificMethodRector/Wrong", + "packages/PHPUnit/tests/Rector/SpecificMethod/AssertCompareToSpecificMethodRector/Wrong", + "packages/PHPUnit/tests/Rector/SpecificMethod/AssertSameBoolNullToSpecificMethodRector/Wrong", + "packages/PHPUnit/tests/Rector/SpecificMethod/AssertTrueFalseToSpecificMethodRector/Wrong", + "packages/PHPUnit/tests/Rector/SpecificMethod/AssertTrueFalseInternalTypeToSpecificMethodRector/Wrong", + "packages/PHPUnit/tests/Rector/SpecificMethod/AssertNotOperatorRector/Wrong", + "packages/PHPUnit/tests/Rector/SpecificMethod/AssertInstanceOfComparisonRector/Wrong", + "packages/PHPUnit/tests/Rector/SpecificMethod/AssertFalseStrposToContainsRector/Wrong", + "packages/PHPUnit/tests/Rector/GetMockRector/Wrong", + "packages/Sylius/tests/Rector/Review/Wrong", + "packages/Silverstripe/tests/Rector/DefineConstantToStaticCallRector/Wrong", + "packages/Silverstripe/tests/Rector/ConstantToStaticCallRector/Wrong", + "packages/Symfony/tests/Rector/HttpKernel/GetRequestRector/Wrong", + "packages/Symfony/tests/Rector/Controller/RedirectToRouteRector/Wrong", + "packages/Symfony/tests/Rector/Controller/AddFlashRector/Wrong", + "packages/Symfony/tests/Rector/Controller/ActionSuffixRemoverRector/Wrong", + "packages/Symfony/tests/Rector/Validator/ConstraintUrlOptionRector/Wrong", + "packages/Symfony/tests/Rector/Console/ConsoleExceptionToErrorEventConstantRector/Wrong", + "packages/Symfony/tests/Rector/Yaml/SessionStrictTrueByDefaultYamlRector/Wrong", + "packages/Symfony/tests/Rector/Yaml/SpaceBetweenKeyAndValueYamlRector/Wrong", + "packages/Symfony/tests/Rector/Yaml/ParseFileRector/Wrong", + "packages/Symfony/tests/Rector/DependencyInjection/ContainerBuilderCompileEnvArgumentRector/Wrong", + "packages/Symfony/tests/Rector/VarDumper/VarDumperTestTraitMethodArgsRector/Wrong", + "packages/Symfony/tests/Rector/FrameworkBundle/ContainerGetToConstructorInjectionRector/Wrong", + "packages/Symfony/tests/Rector/FrameworkBundle/GetParameterToConstructorInjectionRector/Wrong", + "packages/Symfony/tests/Rector/FrameworkBundle/GetToConstructorInjectionRector/Wrong", + "packages/Symfony/tests/Rector/Form/OptionNameRector/Wrong", + "packages/Symfony/tests/Rector/Form/FormIsValidRector/Wrong", + "packages/Symfony/tests/Rector/Form/StringFormTypeToClassRector/Wrong", + "packages/Symfony/tests/Rector/Form/FormTypeGetParentRector/Wrong", + "packages/Symfony/tests/Rector/Process/ProcessBuilderGetProcessRector/Wrong", + "packages/Symfony/tests/Rector/Process/ProcessBuilderInstanceRector/Wrong", + "packages/Twig/tests/Rector/SimpleFunctionAndFilterRector/Wrong", + "packages/Doctrine/tests/Rector/AliasToClassRector/Wrong", + "packages/PhpParser/tests/Rector/RemoveNodeRector/Wrong", + "packages/PhpParser/tests/Rector/IdentifierRector/Wrong", + "packages/PhpParser/tests/Rector/ParamAndStaticVarNameRector/Wrong", + "packages/PhpParser/tests/Rector/UseWithAliasRector/Wrong", + "packages/PhpParser/tests/Rector/CatchAndClosureUseNameRector/Wrong", + "packages/PhpParser/tests/Rector/SetLineRector/Wrong", + "packages/CakePHP/tests/Rector/MethodCall/ModalToGetSetRector/Wrong", + "packages/Sensio/tests/Rector/FrameworkExtraBundle/TemplateAnnotationRector/Wrong", + "packages/Php/tests/Rector/TypedPropertyRector/Wrong", + "packages/Php/tests/Rector/ExceptionHandlerTypehintRector/Wrong" ], "files": [ "tests/Rector/Psr4/MultipleClassFileToPsr4ClassesRector/Source/exceptions.php", diff --git a/packages/PhpParser/tests/Rector/RemoveNodeRector/Correct/correct2.php.inc b/packages/PhpParser/tests/Rector/RemoveNodeRector/Correct/correct2.php.inc index 33e442ce80d..3a920353489 100644 --- a/packages/PhpParser/tests/Rector/RemoveNodeRector/Correct/correct2.php.inc +++ b/packages/PhpParser/tests/Rector/RemoveNodeRector/Correct/correct2.php.inc @@ -1,9 +1,23 @@ parameterProvider->changeParameter('source', [$file]); - $reconstructedFileContent = $this->fileProcessor->processFileToString(new SmartFileInfo($file)); + try { + $reconstructedFileContent = $this->fileProcessor->processFileToString(new SmartFileInfo($file)); + } catch (AnalysedCodeException $analysedCodeException) { + // change message to include responsible file + $message = sprintf('Analyze error in "%s" file:%s%s', $file, PHP_EOL, $analysedCodeException->getMessage()); + $exceptionClass = get_class($analysedCodeException); + throw new $exceptionClass($message); + } $this->assertStringEqualsFile( $reconstructedFile, diff --git a/tests/FileSystem/FilesFinder/FilesFinderTest.php b/tests/FileSystem/FilesFinder/FilesFinderTest.php index 2a541bf5550..3932503de5a 100644 --- a/tests/FileSystem/FilesFinder/FilesFinderTest.php +++ b/tests/FileSystem/FilesFinder/FilesFinderTest.php @@ -6,6 +6,7 @@ use Iterator; use Rector\FileSystem\FilesFinder; use Rector\Tests\AbstractContainerAwareTestCase; use Symfony\Component\Finder\SplFileInfo; +use function Safe\sort; final class FilesFinderTest extends AbstractContainerAwareTestCase { @@ -20,25 +21,39 @@ final class FilesFinderTest extends AbstractContainerAwareTestCase } /** - * @param string[] $suffixes * @dataProvider provideData() */ - public function test(array $suffixes, int $count, string $fileName): void + public function testSingleSuffix(string $suffix, int $count, string $expectedFileName): void { - $foundFiles = $this->filesFinder->findInDirectoriesAndFiles([__DIR__ . '/FilesFinderSource'], $suffixes); + $foundFiles = $this->filesFinder->findInDirectoriesAndFiles([__DIR__ . '/FilesFinderSource'], [$suffix]); $this->assertCount($count, $foundFiles); /** @var SplFileInfo $foundFile */ $foundFile = array_pop($foundFiles); - $this->assertSame($fileName, $foundFile->getBasename()); + $this->assertSame($expectedFileName, $foundFile->getBasename()); } public function provideData(): Iterator { - yield [['php'], 1, 'SomeFile.php']; - yield [['yml'], 1, 'some_config.yml']; - yield [['yaml'], 1, 'other_config.yaml']; - yield [['php'], 1, 'SomeFile.php']; - yield [['yaml', 'yml'], 2, 'some_config.yml']; + yield ['php', 1, 'SomeFile.php']; + yield ['yml', 1, 'some_config.yml']; + yield ['yaml', 1, 'other_config.yaml']; + yield ['php', 1, 'SomeFile.php']; + } + + public function testMultipleSuffixes(): void + { + $foundFiles = $this->filesFinder->findInDirectoriesAndFiles([__DIR__ . '/FilesFinderSource'], ['yaml', 'yml']); + $this->assertCount(2, $foundFiles); + + $foundFileNames = []; + foreach ($foundFiles as $foundFile) { + $foundFileNames[] = $foundFile->getFilename(); + } + $expectedFoundFileNames = ['some_config.yml', 'other_config.yaml']; + + sort($foundFileNames); + sort($expectedFoundFileNames); + $this->assertSame($expectedFoundFileNames, $foundFileNames); } } diff --git a/tests/Rector/Architecture/DoctrineRepositoryAsService/Correct/correct2.php.inc b/tests/Rector/Architecture/DoctrineRepositoryAsService/Correct/correct2.php.inc index 4134c929f2a..d3f92abfe65 100644 --- a/tests/Rector/Architecture/DoctrineRepositoryAsService/Correct/correct2.php.inc +++ b/tests/Rector/Architecture/DoctrineRepositoryAsService/Correct/correct2.php.inc @@ -1,6 +1,6 @@