2017-04-25 05:45:02 +02:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
|
|
|
use PHPUnit_Framework_TestCase;
|
|
|
|
use Psalm\Checker\FileChecker;
|
|
|
|
|
|
|
|
class TestCase extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/** @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,
|
|
|
|
new Provider\FakeCacheProvider()
|
|
|
|
);
|
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
|
|
|
}
|