mirror of
https://github.com/danog/psalm.git
synced 2024-12-12 09:19:40 +01:00
dabfb16e34
* Run tests in random order Being able to run tests in any order is a pre-requisite for being able to run them in parallel. * Reset type coverage between tests, fix affected tests * Reset parser and lexer between test runs and on php version change Previously lexer was reset, but parser kept the reference to the old one, and reference to the parser was kept by StatementsProvider. This resulted in order-dependent tests - if the parser was first initialized with phpVersion set to 7.4 then arrow functions worked fine, but were failing when the parser was initially constructed with settings for 7.3 This can be demonstrated on current master by upgrading to nikic/php-parser:4.9 and running: ``` vendor/bin/phpunit --no-coverage --filter="inferredArgArrowFunction" tests/ClosureTest.php ``` Now all tests using PHP 7.4 features must set the PHP version accordingly. * Marked more tests using 7.4 syntax * Reset newline-between-annotation flag between tests * Resolve real paths before passing them to checkPaths When checkPaths is called from psalm.php the paths are resolved, so we just mimicking SUT behaviour here. * Restore newline-between-annotations in DocCommentTest * Tweak Appveyor caches * Tweak TravisCI caches * Tweak CircleCI caches * Run tests in parallel Use `vendor/bin/paratest` instead of `vendor/bin/phpunit` * Use default paratest runner on Windows WrapperRunner is not supported on Windows. * TRAVIS_TAG could be empty * Restore appveyor conditional caching
107 lines
3.4 KiB
PHP
107 lines
3.4 KiB
PHP
<?php
|
|
namespace Psalm\Tests\FileUpdates;
|
|
|
|
use function array_keys;
|
|
use const DIRECTORY_SEPARATOR;
|
|
use function getcwd;
|
|
use Psalm\Internal\Analyzer\FileAnalyzer;
|
|
use Psalm\Internal\Analyzer\ProjectAnalyzer;
|
|
use Psalm\Internal\Provider\Providers;
|
|
use Psalm\Tests\Internal\Provider;
|
|
use Psalm\Tests\TestConfig;
|
|
use function strpos;
|
|
|
|
class CachedStorageTest extends \Psalm\Tests\TestCase
|
|
{
|
|
/**
|
|
* @return void
|
|
*/
|
|
public function setUp() : void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->file_provider = new \Psalm\Tests\Internal\Provider\FakeFileProvider();
|
|
|
|
$config = new TestConfig();
|
|
|
|
$providers = new Providers(
|
|
$this->file_provider,
|
|
new Provider\ParserInstanceCacheProvider(),
|
|
new Provider\FileStorageInstanceCacheProvider(),
|
|
new Provider\ClassLikeStorageInstanceCacheProvider(),
|
|
new Provider\FakeFileReferenceCacheProvider(),
|
|
new Provider\ProjectCacheProvider()
|
|
);
|
|
|
|
$this->project_analyzer = new ProjectAnalyzer(
|
|
$config,
|
|
$providers
|
|
);
|
|
$this->project_analyzer->setPhpVersion('7.3');
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
public function testValidInclude()
|
|
{
|
|
$test_name = $this->getTestName();
|
|
if (strpos($test_name, 'SKIPPED-') !== false) {
|
|
$this->markTestSkipped('Skipped due to a bug.');
|
|
}
|
|
|
|
$this->project_analyzer->getCodebase()->diff_methods = true;
|
|
|
|
$codebase = $this->project_analyzer->getCodebase();
|
|
|
|
$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();
|
|
|
|
$codebase->analyzer->analyzeFiles($this->project_analyzer, 1, false);
|
|
|
|
$codebase->reloadFiles($this->project_analyzer, array_keys($analyzable_files + $vendor_files));
|
|
|
|
$codebase->analyzer->analyzeFiles($this->project_analyzer, 1, false);
|
|
}
|
|
}
|