1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

TestCase/TestConfig: Allow plugins to reuse these files

See: https://github.com/vimeo/psalm/issues/2869\#issuecomment-590490908

Previously, If a plugin tried to reuse the TestConf / TestCase
an exception would likely occur since the default testconfig
is hardcoded to our internal psalm codebase

This commit allows a custom config to be passed into a testcase
thus, a plugin's codebase does not need to match our own.
This commit is contained in:
Jarred Stelfox 2020-02-24 11:43:44 -08:00 committed by Matthew Brown
parent 6c9ea71e24
commit 3c69c78ee3
2 changed files with 22 additions and 10 deletions

View File

@ -7,6 +7,7 @@ use const DIRECTORY_SEPARATOR;
use function getcwd;
use function ini_set;
use PHPUnit\Framework\TestCase as BaseTestCase;
use Psalm\Config;
use Psalm\Internal\Analyzer\FileAnalyzer;
use Psalm\Internal\Analyzer\ProjectAnalyzer;
use Psalm\Internal\Provider\Providers;
@ -43,6 +44,14 @@ class TestCase extends BaseTestCase
self::$src_dir_path = getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR;
}
/**
* @return Config
*/
protected function getConfig() : Config
{
return new TestConfig();
}
/**
* @return void
*/
@ -54,7 +63,7 @@ class TestCase extends BaseTestCase
$this->file_provider = new \Psalm\Tests\Internal\Provider\FakeFileProvider();
$config = new TestConfig();
$config = $this->getConfig();
$providers = new Providers(
$this->file_provider,

View File

@ -26,15 +26,7 @@ class TestConfig extends Config
if (!self::$cached_project_files) {
self::$cached_project_files = Config\ProjectFileFilter::loadFromXMLElement(
new \SimpleXMLElement(
'<?xml version="1.0"?>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="src/Psalm/Internal/Stubs" />
</ignoreFiles>
</projectFiles>'
),
new \SimpleXMLElement($this->getContents()),
$this->base_dir,
true
);
@ -46,6 +38,17 @@ class TestConfig extends Config
$this->collectPredefinedFunctions();
}
protected function getContents() : string
{
return '<?xml version="1.0"?>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="src/Psalm/Internal/Stubs" />
</ignoreFiles>
</projectFiles>';
}
public function getComposerFilePathForClassLike($fq_classlike_name)
{
return false;