2017-04-25 05:45:02 +02:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2017-12-15 12:18:33 +01:00
|
|
|
use PHPUnit\Framework\TestCase as BaseTestCase;
|
2017-04-25 05:45:02 +02:00
|
|
|
use Psalm\Checker\FileChecker;
|
|
|
|
|
2017-12-15 12:18:33 +01:00
|
|
|
class TestCase extends BaseTestCase
|
2017-04-25 05:45:02 +02:00
|
|
|
{
|
|
|
|
/** @var \PhpParser\Parser */
|
|
|
|
protected static $parser;
|
|
|
|
|
|
|
|
/** @var TestConfig */
|
|
|
|
protected static $config;
|
|
|
|
|
2017-07-25 23:04:58 +02:00
|
|
|
/** @var string */
|
|
|
|
protected static $src_dir_path;
|
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
/** @var \Psalm\Checker\ProjectChecker */
|
|
|
|
protected $project_checker;
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
/** @var Provider\FakeFileProvider */
|
|
|
|
protected $file_provider;
|
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function setUpBeforeClass()
|
|
|
|
{
|
|
|
|
parent::setUpBeforeClass();
|
2017-07-25 23:04:58 +02:00
|
|
|
self::$src_dir_path = getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR;
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
FileChecker::clearCache();
|
2017-07-25 22:11:02 +02:00
|
|
|
|
|
|
|
$this->file_provider = new Provider\FakeFileProvider();
|
|
|
|
|
|
|
|
$this->project_checker = new \Psalm\Checker\ProjectChecker(
|
|
|
|
$this->file_provider,
|
2017-10-15 17:57:44 +02:00
|
|
|
new Provider\FakeParserCacheProvider()
|
2017-07-25 22:11:02 +02:00
|
|
|
);
|
2017-04-25 05:45:02 +02:00
|
|
|
$this->project_checker->setConfig(new TestConfig());
|
2017-09-03 00:15:52 +02:00
|
|
|
$this->project_checker->infer_types_from_usage = true;
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-07-29 21:05:06 +02:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
$this->project_checker->classlike_storage_provider->deleteAll();
|
|
|
|
$this->project_checker->file_storage_provider->deleteAll();
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
* @param string $contents
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function addFile($file_path, $contents)
|
|
|
|
{
|
|
|
|
$this->file_provider->registerFile($file_path, $contents);
|
|
|
|
$this->project_checker->queueFileForScanning($file_path);
|
|
|
|
}
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|