Skip to content
Permalink
Browse files

Break apart FileManipulationTest

  • Loading branch information...
muglug committed May 2, 2019
1 parent ae53150 commit d64ca306330b1ef5c678fb5d8cab09e994f93b77
@@ -0,0 +1,95 @@
<?php
namespace Psalm\Tests\FileManipulation;
use Psalm\Context;
use Psalm\Internal\Analyzer\FileAnalyzer;
use Psalm\Tests\Internal\Provider;
use Psalm\Tests\TestConfig;
abstract class FileManipulationTest extends \Psalm\Tests\TestCase
{
/** @var \Psalm\Internal\Analyzer\ProjectAnalyzer */
protected $project_analyzer;
/**
* @return void
*/
public function setUp()
{
FileAnalyzer::clearCache();
\Psalm\Internal\FileManipulation\FunctionDocblockManipulator::clearCache();
$this->file_provider = new Provider\FakeFileProvider();
}
/**
* @dataProvider providerValidCodeParse
*
* @param string $input_code
* @param string $output_code
* @param string $php_version
* @param string[] $issues_to_fix
* @param bool $safe_types
*
* @return void
*/
public function testValidCode($input_code, $output_code, $php_version, array $issues_to_fix, $safe_types)
{
$test_name = $this->getTestName();
if (strpos($test_name, 'SKIPPED-') !== false) {
$this->markTestSkipped('Skipped due to a bug.');
}
$config = new TestConfig();
$this->project_analyzer = new \Psalm\Internal\Analyzer\ProjectAnalyzer(
$config,
new \Psalm\Internal\Provider\Providers(
$this->file_provider,
new Provider\FakeParserCacheProvider()
)
);
if (empty($issues_to_fix)) {
$config->addPluginPath('examples/plugins/ClassUnqualifier.php');
$config->initializePlugins($this->project_analyzer);
}
$context = new Context();
$file_path = self::$src_dir_path . 'somefile.php';
$this->addFile(
$file_path,
$input_code
);
$this->project_analyzer->setPhpVersion($php_version);
$keyed_issues_to_fix = [];
foreach ($issues_to_fix as $issue) {
$keyed_issues_to_fix[$issue] = true;
}
$this->project_analyzer->setIssuesToFix($keyed_issues_to_fix);
$this->project_analyzer->alterCodeAfterCompletion(
false,
$safe_types
);
$this->project_analyzer->getCodebase()->reportUnusedCode();
$this->analyzeFile($file_path, $context);
$this->project_analyzer->checkClassReferences();
$this->project_analyzer->getCodebase()->analyzer->updateFile($file_path, false);
$this->assertSame($output_code, $this->project_analyzer->getCodebase()->getFileContents($file_path));
}
/**
* @return array<string,array{string,string,string,string[],bool}>
*/
abstract public function providerValidCodeParse();
}

0 comments on commit d64ca30

Please sign in to comment.
You can’t perform that action at this time.