provideConfigFilePath()); $this->bootFromConfigFileInfos([$configFileInfo]); $this->applicationFileProcessor = $this->getService(\Rector\Core\Application\ApplicationFileProcessor::class); $this->parameterProvider = $this->getService(\RectorPrefix20210519\Symplify\PackageBuilder\Parameter\ParameterProvider::class); $this->dynamicSourceLocatorProvider = $this->getService(\Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider::class); $this->removedAndAddedFilesCollector = $this->getService(\Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector::class); $this->removedAndAddedFilesCollector->reset(); /** @var AdditionalAutoloader $additionalAutoloader */ $additionalAutoloader = $this->getService(\Rector\Core\Autoloading\AdditionalAutoloader::class); $additionalAutoloader->autoloadPaths(); /** @var BootstrapFilesIncluder $bootstrapFilesIncluder */ $bootstrapFilesIncluder = $this->getService(\Rector\Core\Autoloading\BootstrapFilesIncluder::class); $bootstrapFilesIncluder->includeBootstrapFiles(); /** @var Configuration $configuration */ $configuration = $this->getService(\Rector\Core\Configuration\Configuration::class); $configuration->setIsDryRun(\true); } /** * @return Iterator */ protected function yieldFilesFromDirectory(string $directory, string $suffix = '*.php.inc') : \Iterator { return \RectorPrefix20210519\Symplify\EasyTesting\DataProvider\StaticFixtureFinder::yieldDirectoryExclusively($directory, $suffix); } protected function doTestFileInfo(\Symplify\SmartFileSystem\SmartFileInfo $fixtureFileInfo) : void { $inputFileInfoAndExpectedFileInfo = \RectorPrefix20210519\Symplify\EasyTesting\StaticFixtureSplitter::splitFileInfoToLocalInputAndExpectedFileInfos($fixtureFileInfo); $inputFileInfo = $inputFileInfoAndExpectedFileInfo->getInputFileInfo(); $this->originalTempFileInfo = $inputFileInfo; $expectedFileInfo = $inputFileInfoAndExpectedFileInfo->getExpectedFileInfo(); $this->doTestFileMatchesExpectedContent($inputFileInfo, $expectedFileInfo, $fixtureFileInfo); } protected function getFixtureTempDirectory() : string { return \sys_get_temp_dir() . '/_temp_fixture_easy_testing'; } private function doTestFileMatchesExpectedContent(\Symplify\SmartFileSystem\SmartFileInfo $originalFileInfo, \Symplify\SmartFileSystem\SmartFileInfo $expectedFileInfo, \Symplify\SmartFileSystem\SmartFileInfo $fixtureFileInfo) : void { $this->parameterProvider->changeParameter(\Rector\Core\Configuration\Option::SOURCE, [$originalFileInfo->getRealPath()]); $changedContent = $this->processFileInfo($originalFileInfo); // file is removed, we cannot compare it if ($this->removedAndAddedFilesCollector->isFileRemoved($originalFileInfo)) { return; } $relativeFilePathFromCwd = $fixtureFileInfo->getRelativeFilePathFromCwd(); try { $this->assertStringEqualsFile($expectedFileInfo->getRealPath(), $changedContent, $relativeFilePathFromCwd); } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { \RectorPrefix20210519\Symplify\EasyTesting\DataProvider\StaticFixtureUpdater::updateFixtureContent($originalFileInfo, $changedContent, $fixtureFileInfo); $contents = $expectedFileInfo->getContents(); // make sure we don't get a diff in which every line is different (because of differences in EOL) $contents = $this->normalizeNewlines($contents); // if not exact match, check the regex version (useful for generated hashes/uuids in the code) $this->assertStringMatchesFormat($contents, $changedContent, $relativeFilePathFromCwd); } } private function normalizeNewlines(string $string) : string { return \RectorPrefix20210519\Nette\Utils\Strings::replace($string, '#\\r\\n|\\r|\\n#', "\n"); } private function processFileInfo(\Symplify\SmartFileSystem\SmartFileInfo $fileInfo) : string { $this->dynamicSourceLocatorProvider->setFileInfo($fileInfo); // needed for PHPStan, because the analyzed file is just created in /temp - need for trait and similar deps /** @var NodeScopeResolver $nodeScopeResolver */ $nodeScopeResolver = $this->getService(\PHPStan\Analyser\NodeScopeResolver::class); $nodeScopeResolver->setAnalysedFiles([$fileInfo->getRealPath()]); $file = new \Rector\Core\ValueObject\Application\File($fileInfo, $fileInfo->getContents()); $this->applicationFileProcessor->run([$file]); return $file->getFileContent(); } }