2018-10-12 05:00:32 +02:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests\FileUpdates;
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
use Psalm\Internal\Analyzer\FileAnalyzer;
|
|
|
|
use Psalm\Internal\Analyzer\ProjectAnalyzer;
|
|
|
|
use Psalm\Internal\Provider\Providers;
|
2018-10-12 05:00:32 +02:00
|
|
|
use Psalm\Tests\TestConfig;
|
2018-11-12 16:57:05 +01:00
|
|
|
use Psalm\Tests\Internal\Provider;
|
2018-10-12 05:00:32 +02:00
|
|
|
|
|
|
|
class CachedStorageTest extends \Psalm\Tests\TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
FileAnalyzer::clearCache();
|
2018-10-12 05:00:32 +02:00
|
|
|
|
2018-11-12 16:57:05 +01:00
|
|
|
$this->file_provider = new \Psalm\Tests\Internal\Provider\FakeFileProvider();
|
2018-10-12 05:00:32 +02:00
|
|
|
|
|
|
|
$config = new TestConfig();
|
|
|
|
|
|
|
|
$providers = new Providers(
|
|
|
|
$this->file_provider,
|
|
|
|
new Provider\ParserInstanceCacheProvider(),
|
|
|
|
new Provider\FileStorageInstanceCacheProvider(),
|
|
|
|
new Provider\ClassLikeStorageInstanceCacheProvider(),
|
|
|
|
new Provider\FakeFileReferenceCacheProvider()
|
|
|
|
);
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->project_analyzer = new ProjectAnalyzer(
|
2018-10-12 05:00:32 +02:00
|
|
|
$config,
|
|
|
|
$providers,
|
|
|
|
false,
|
|
|
|
true,
|
2018-11-06 03:57:36 +01:00
|
|
|
ProjectAnalyzer::TYPE_CONSOLE,
|
2018-10-12 05:00:32 +02:00
|
|
|
1,
|
|
|
|
false
|
|
|
|
);
|
2019-02-07 21:27:43 +01:00
|
|
|
$this->project_analyzer->setPhpVersion('7.3');
|
2018-10-12 05:00:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testValidInclude()
|
|
|
|
{
|
|
|
|
$test_name = $this->getTestName();
|
|
|
|
if (strpos($test_name, 'SKIPPED-') !== false) {
|
|
|
|
$this->markTestSkipped('Skipped due to a bug.');
|
|
|
|
}
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->project_analyzer->getCodebase()->diff_methods = true;
|
2018-10-12 05:00:32 +02:00
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$codebase = $this->project_analyzer->getCodebase();
|
2018-10-12 05:00:32 +02:00
|
|
|
|
|
|
|
$vendor_files = [
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'V1.php' => '<?php
|
|
|
|
namespace AnotherPackage;
|
|
|
|
interface StorageInterface {
|
|
|
|
public function getRecord(): OperationInterface;
|
|
|
|
}',
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'V2.php' => '<?php
|
|
|
|
namespace AnotherPackage;
|
|
|
|
interface OperationInterface {
|
|
|
|
public function getResult(): ResultInterface;
|
|
|
|
}',
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'V3.php' => '<?php
|
|
|
|
namespace AnotherPackage;
|
|
|
|
interface ResultInterface {}',
|
|
|
|
];
|
|
|
|
|
|
|
|
$analyzable_files = [
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
use AnotherPackage\StorageInterface;
|
|
|
|
class C {
|
|
|
|
/** @var ?StorageInterface */
|
|
|
|
private $storage;
|
|
|
|
public function zugzug() : void {
|
|
|
|
if (!$this->storage) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$result = $this->storage->getRecord()->getResult();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($vendor_files as $file_path => $contents) {
|
|
|
|
$this->file_provider->registerFile($file_path, $contents);
|
|
|
|
$codebase->scanner->addFilesToShallowScan([$file_path => $file_path]);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($analyzable_files as $file_path => $contents) {
|
|
|
|
$this->file_provider->registerFile($file_path, $contents);
|
|
|
|
$codebase->addFilesToAnalyze([$file_path => $file_path]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$codebase->scanFiles();
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$codebase->analyzer->analyzeFiles($this->project_analyzer, 1, false);
|
2018-10-12 05:00:32 +02:00
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$codebase->reloadFiles($this->project_analyzer, array_keys($analyzable_files + $vendor_files));
|
2018-10-12 05:00:32 +02:00
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$codebase->analyzer->analyzeFiles($this->project_analyzer, 1, false);
|
2018-10-12 05:00:32 +02:00
|
|
|
}
|
|
|
|
}
|