1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 12:55:26 +01:00
psalm/tests/TestConfig.php
Jarred Stelfox 3c69c78ee3 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.
2020-02-24 21:20:06 -05:00

62 lines
1.6 KiB
PHP

<?php
namespace Psalm\Tests;
use const DIRECTORY_SEPARATOR;
use function getcwd;
use Psalm\Config;
class TestConfig extends Config
{
/** @var Config\ProjectFileFilter|null */
private static $cached_project_files = null;
/**
* @psalm-suppress PossiblyNullPropertyAssignmentValue because cache_directory isn't strictly nullable
*/
public function __construct()
{
parent::__construct();
$this->throw_exception = true;
$this->use_docblock_types = true;
$this->level = 1;
$this->cache_directory = null;
$this->base_dir = getcwd() . DIRECTORY_SEPARATOR;
if (!self::$cached_project_files) {
self::$cached_project_files = Config\ProjectFileFilter::loadFromXMLElement(
new \SimpleXMLElement($this->getContents()),
$this->base_dir,
true
);
}
$this->project_files = self::$cached_project_files;
$this->collectPredefinedConstants();
$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;
}
public function getProjectDirectories()
{
return [];
}
}