2018-10-17 17:03:32 +02:00
|
|
|
<?php
|
2021-12-15 04:58:32 +01:00
|
|
|
|
2018-10-17 17:03:32 +02:00
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2021-06-08 04:55:21 +02:00
|
|
|
use Psalm\Config;
|
2021-11-27 01:06:33 +01:00
|
|
|
use Psalm\Internal\Analyzer\ProjectAnalyzer;
|
2021-06-08 04:55:21 +02:00
|
|
|
use Psalm\Internal\IncludeCollector;
|
2021-07-02 01:10:21 +02:00
|
|
|
use Psalm\Internal\Provider\FakeFileProvider;
|
2021-12-03 20:11:20 +01:00
|
|
|
use Psalm\Internal\Provider\Providers;
|
2021-06-08 04:55:21 +02:00
|
|
|
use Psalm\Internal\RuntimeCaches;
|
2021-12-03 20:11:20 +01:00
|
|
|
use Psalm\IssueBuffer;
|
2021-06-08 04:55:21 +02:00
|
|
|
use Psalm\Plugin\EventHandler\AfterCodebasePopulatedInterface;
|
2021-01-06 15:05:53 +01:00
|
|
|
use Psalm\Plugin\EventHandler\Event\AfterCodebasePopulatedEvent;
|
2021-12-03 20:11:20 +01:00
|
|
|
use Psalm\Report;
|
|
|
|
use Psalm\Report\ReportOptions;
|
2021-12-04 21:55:53 +01:00
|
|
|
use Psalm\Tests\Internal\Provider\ClassLikeStorageInstanceCacheProvider;
|
|
|
|
use Psalm\Tests\Internal\Provider\FakeFileReferenceCacheProvider;
|
|
|
|
use Psalm\Tests\Internal\Provider\FileStorageInstanceCacheProvider;
|
|
|
|
use Psalm\Tests\Internal\Provider\ParserInstanceCacheProvider;
|
|
|
|
use Psalm\Tests\Internal\Provider\ProjectCacheProvider;
|
2021-06-08 04:55:21 +02:00
|
|
|
use Psalm\Tests\Progress\EchoProgress;
|
|
|
|
|
2019-07-05 22:24:00 +02:00
|
|
|
use function define;
|
|
|
|
use function defined;
|
|
|
|
use function get_class;
|
|
|
|
use function getcwd;
|
|
|
|
use function microtime;
|
|
|
|
use function ob_end_clean;
|
|
|
|
use function ob_get_clean;
|
|
|
|
use function ob_start;
|
2020-08-23 16:32:07 +02:00
|
|
|
use function realpath;
|
2018-10-17 17:03:32 +02:00
|
|
|
|
2021-06-08 04:55:21 +02:00
|
|
|
use const DIRECTORY_SEPARATOR;
|
|
|
|
|
2019-03-23 19:27:54 +01:00
|
|
|
class ProjectCheckerTest extends TestCase
|
2018-10-17 17:03:32 +02:00
|
|
|
{
|
2022-12-16 19:58:47 +01:00
|
|
|
protected static TestConfig $config;
|
2018-10-17 17:03:32 +02:00
|
|
|
|
2022-12-16 19:58:47 +01:00
|
|
|
protected ProjectAnalyzer $project_analyzer;
|
2018-10-17 17:03:32 +02:00
|
|
|
|
2021-12-05 18:51:26 +01:00
|
|
|
public static function setUpBeforeClass(): void
|
2018-10-17 17:03:32 +02:00
|
|
|
{
|
|
|
|
self::$config = new TestConfig();
|
|
|
|
|
|
|
|
if (!defined('PSALM_VERSION')) {
|
2021-05-17 15:27:08 +02:00
|
|
|
define('PSALM_VERSION', '4.0.0');
|
2018-10-17 17:03:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!defined('PHP_PARSER_VERSION')) {
|
|
|
|
define('PHP_PARSER_VERSION', '4.0.0');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-05 18:51:26 +01:00
|
|
|
public function setUp(): void
|
2018-10-17 17:03:32 +02:00
|
|
|
{
|
2020-08-23 16:32:07 +02:00
|
|
|
RuntimeCaches::clearAll();
|
2021-07-02 01:10:21 +02:00
|
|
|
$this->file_provider = new FakeFileProvider();
|
2018-10-17 17:03:32 +02:00
|
|
|
}
|
|
|
|
|
2021-11-27 01:06:33 +01:00
|
|
|
private function getProjectAnalyzerWithConfig(Config $config): ProjectAnalyzer
|
2018-10-17 17:03:32 +02:00
|
|
|
{
|
2020-07-11 23:17:22 +02:00
|
|
|
$config->setIncludeCollector(new IncludeCollector());
|
2021-12-03 20:11:20 +01:00
|
|
|
return new ProjectAnalyzer(
|
2018-10-17 17:03:32 +02:00
|
|
|
$config,
|
2021-12-03 20:11:20 +01:00
|
|
|
new Providers(
|
2018-10-17 17:03:32 +02:00
|
|
|
$this->file_provider,
|
2021-12-04 21:55:53 +01:00
|
|
|
new ParserInstanceCacheProvider(),
|
|
|
|
new FileStorageInstanceCacheProvider(),
|
|
|
|
new ClassLikeStorageInstanceCacheProvider(),
|
|
|
|
new FakeFileReferenceCacheProvider(),
|
2022-12-18 17:15:15 +01:00
|
|
|
new ProjectCacheProvider(),
|
2019-05-30 16:30:41 +02:00
|
|
|
),
|
2022-12-18 17:15:15 +01:00
|
|
|
new ReportOptions(),
|
2018-10-17 17:03:32 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testCheck(): void
|
2018-10-17 17:03:32 +02:00
|
|
|
{
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
|
2018-10-17 17:03:32 +02:00
|
|
|
Config::loadFromXML(
|
|
|
|
(string)getcwd(),
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
2019-05-10 00:23:14 +02:00
|
|
|
<directory name="tests/fixtures/DummyProject" />
|
2018-10-17 17:03:32 +02:00
|
|
|
</projectFiles>
|
2022-12-18 17:15:15 +01:00
|
|
|
</psalm>',
|
|
|
|
),
|
2018-10-17 17:03:32 +02:00
|
|
|
);
|
2021-11-27 01:06:33 +01:00
|
|
|
$this->project_analyzer->setPhpVersion('8.1', 'tests');
|
2018-10-17 17:03:32 +02:00
|
|
|
|
2019-05-30 16:30:41 +02:00
|
|
|
$this->project_analyzer->progress = new EchoProgress();
|
|
|
|
|
2018-10-17 17:03:32 +02:00
|
|
|
ob_start();
|
2019-05-10 00:23:14 +02:00
|
|
|
$this->project_analyzer->check('tests/fixtures/DummyProject');
|
2018-10-17 17:03:32 +02:00
|
|
|
$output = ob_get_clean();
|
|
|
|
|
2023-01-05 15:12:29 +01:00
|
|
|
$this->assertStringContainsString('Target PHP version: 8.1 (set by tests)', $output);
|
|
|
|
$this->assertStringContainsString('Scanning files...', $output);
|
|
|
|
$this->assertStringContainsString('Analyzing files...', $output);
|
2018-10-17 17:03:32 +02:00
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
$this->assertSame(0, IssueBuffer::getErrorCount());
|
2018-10-17 17:03:32 +02:00
|
|
|
|
2019-03-23 14:50:47 +01:00
|
|
|
$codebase = $this->project_analyzer->getCodebase();
|
|
|
|
|
2019-10-15 18:09:08 +02:00
|
|
|
$this->assertSame([0, 5], $codebase->analyzer->getTotalTypeCoverage($codebase));
|
2019-03-23 14:50:47 +01:00
|
|
|
|
2018-10-17 17:03:32 +02:00
|
|
|
$this->assertSame(
|
2019-03-23 14:50:47 +01:00
|
|
|
'Psalm was able to infer types for 100% of the codebase',
|
|
|
|
$codebase->analyzer->getTypeInferenceSummary(
|
2022-12-18 17:15:15 +01:00
|
|
|
$codebase,
|
|
|
|
),
|
2018-10-17 17:03:32 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testAfterCodebasePopulatedIsInvoked(): void
|
2019-02-24 19:48:57 +01:00
|
|
|
{
|
2019-03-23 19:27:54 +01:00
|
|
|
$hook = new class implements AfterCodebasePopulatedInterface {
|
2022-12-16 19:58:47 +01:00
|
|
|
public static bool $called = false;
|
2019-03-23 19:27:54 +01:00
|
|
|
|
2021-12-05 18:51:26 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint
|
|
|
|
*/
|
2021-01-06 15:05:53 +01:00
|
|
|
public static function afterCodebasePopulated(AfterCodebasePopulatedEvent $event)
|
2019-02-24 19:48:57 +01:00
|
|
|
{
|
|
|
|
self::$called = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
|
|
|
|
Config::loadFromXML(
|
|
|
|
(string)getcwd(),
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
2019-05-10 00:23:14 +02:00
|
|
|
<directory name="tests/fixtures/DummyProject" />
|
2019-02-24 19:48:57 +01:00
|
|
|
</projectFiles>
|
2022-12-18 17:15:15 +01:00
|
|
|
</psalm>',
|
|
|
|
),
|
2019-02-24 19:48:57 +01:00
|
|
|
);
|
|
|
|
|
2019-03-01 14:45:18 +01:00
|
|
|
$hook_class = get_class($hook);
|
|
|
|
|
2021-01-06 15:05:53 +01:00
|
|
|
$this->project_analyzer->getCodebase()->config->eventDispatcher->after_codebase_populated[] = $hook_class;
|
2019-02-24 19:48:57 +01:00
|
|
|
|
|
|
|
ob_start();
|
2019-05-10 00:23:14 +02:00
|
|
|
$this->project_analyzer->check('tests/fixtures/DummyProject');
|
2019-02-24 20:14:14 +01:00
|
|
|
ob_end_clean();
|
2019-02-24 19:48:57 +01:00
|
|
|
|
|
|
|
$this->assertTrue($hook::$called);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testCheckAfterNoChange(): void
|
2018-10-17 17:03:32 +02:00
|
|
|
{
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
|
2018-10-17 17:03:32 +02:00
|
|
|
Config::loadFromXML(
|
|
|
|
(string)getcwd(),
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
2019-05-10 00:23:14 +02:00
|
|
|
<directory name="tests/fixtures/DummyProject" />
|
2018-10-17 17:03:32 +02:00
|
|
|
</projectFiles>
|
2022-12-18 17:15:15 +01:00
|
|
|
</psalm>',
|
|
|
|
),
|
2018-10-17 17:03:32 +02:00
|
|
|
);
|
|
|
|
|
2019-06-09 18:37:28 +02:00
|
|
|
$this->assertNotNull($this->project_analyzer->stdout_report_options);
|
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
$this->project_analyzer->stdout_report_options->format = Report::TYPE_JSON;
|
2018-10-17 17:03:32 +02:00
|
|
|
|
2019-05-10 00:23:14 +02:00
|
|
|
$this->project_analyzer->check('tests/fixtures/DummyProject', true);
|
2020-07-20 10:52:01 +02:00
|
|
|
ob_start();
|
2021-12-03 20:11:20 +01:00
|
|
|
IssueBuffer::finish($this->project_analyzer, true, microtime(true));
|
2020-07-20 10:52:01 +02:00
|
|
|
ob_end_clean();
|
2018-10-17 17:03:32 +02:00
|
|
|
|
|
|
|
$this->assertSame(
|
2019-03-23 14:50:47 +01:00
|
|
|
'Psalm was able to infer types for 100% of the codebase',
|
|
|
|
$this->project_analyzer->getCodebase()->analyzer->getTypeInferenceSummary(
|
2022-12-18 17:15:15 +01:00
|
|
|
$this->project_analyzer->getCodebase(),
|
|
|
|
),
|
2018-10-17 17:03:32 +02:00
|
|
|
);
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->project_analyzer->getCodebase()->reloadFiles($this->project_analyzer, []);
|
2018-10-17 17:03:32 +02:00
|
|
|
|
2019-05-10 00:23:14 +02:00
|
|
|
$this->project_analyzer->check('tests/fixtures/DummyProject', true);
|
2018-10-17 17:03:32 +02:00
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
$this->assertSame(0, IssueBuffer::getErrorCount());
|
2018-10-17 17:03:32 +02:00
|
|
|
|
|
|
|
$this->assertSame(
|
2020-06-06 22:57:25 +02:00
|
|
|
'Psalm was able to infer types for 100% of the codebase',
|
2019-03-23 14:50:47 +01:00
|
|
|
$this->project_analyzer->getCodebase()->analyzer->getTypeInferenceSummary(
|
2022-12-18 17:15:15 +01:00
|
|
|
$this->project_analyzer->getCodebase(),
|
|
|
|
),
|
2018-10-17 17:03:32 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testCheckAfterFileChange(): void
|
2018-10-17 17:03:32 +02:00
|
|
|
{
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
|
2018-10-17 17:03:32 +02:00
|
|
|
Config::loadFromXML(
|
|
|
|
(string)getcwd(),
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
2019-05-10 00:23:14 +02:00
|
|
|
<directory name="tests/fixtures/DummyProject" />
|
2018-10-17 17:03:32 +02:00
|
|
|
</projectFiles>
|
2022-12-18 17:15:15 +01:00
|
|
|
</psalm>',
|
|
|
|
),
|
2018-10-17 17:03:32 +02:00
|
|
|
);
|
|
|
|
|
2019-06-09 18:37:28 +02:00
|
|
|
$this->assertNotNull($this->project_analyzer->stdout_report_options);
|
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
$this->project_analyzer->stdout_report_options->format = Report::TYPE_JSON;
|
2018-10-17 17:03:32 +02:00
|
|
|
|
2019-05-10 00:23:14 +02:00
|
|
|
$this->project_analyzer->check('tests/fixtures/DummyProject', true);
|
2020-07-20 10:52:01 +02:00
|
|
|
ob_start();
|
2021-12-03 20:11:20 +01:00
|
|
|
IssueBuffer::finish($this->project_analyzer, true, microtime(true));
|
2020-07-20 10:52:01 +02:00
|
|
|
ob_end_clean();
|
2018-10-17 17:03:32 +02:00
|
|
|
|
|
|
|
$this->assertSame(
|
2019-03-23 14:50:47 +01:00
|
|
|
'Psalm was able to infer types for 100% of the codebase',
|
|
|
|
$this->project_analyzer->getCodebase()->analyzer->getTypeInferenceSummary(
|
2022-12-18 17:15:15 +01:00
|
|
|
$this->project_analyzer->getCodebase(),
|
|
|
|
),
|
2018-10-17 17:03:32 +02:00
|
|
|
);
|
|
|
|
|
2019-05-10 00:23:14 +02:00
|
|
|
$bat_file_path = getcwd()
|
|
|
|
. DIRECTORY_SEPARATOR . 'tests'
|
|
|
|
. DIRECTORY_SEPARATOR . 'fixtures'
|
|
|
|
. DIRECTORY_SEPARATOR . 'DummyProject'
|
|
|
|
. DIRECTORY_SEPARATOR . 'Bat.php';
|
2018-10-17 17:03:32 +02:00
|
|
|
|
|
|
|
$bat_replacement_contents = '<?php
|
|
|
|
|
2019-02-08 23:41:03 +01:00
|
|
|
namespace Vimeo\Test\DummyProject;
|
2018-10-17 17:03:32 +02:00
|
|
|
|
|
|
|
class Bat
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$a = new Bar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
';
|
|
|
|
|
|
|
|
$this->file_provider->registerFile($bat_file_path, $bat_replacement_contents);
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->project_analyzer->getCodebase()->reloadFiles($this->project_analyzer, []);
|
2018-10-17 17:03:32 +02:00
|
|
|
|
2019-05-10 00:23:14 +02:00
|
|
|
$this->project_analyzer->check('tests/fixtures/DummyProject', true);
|
2018-10-17 17:03:32 +02:00
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
$this->assertSame(0, IssueBuffer::getErrorCount());
|
2018-10-17 17:03:32 +02:00
|
|
|
|
|
|
|
$this->assertSame(
|
2019-03-23 14:50:47 +01:00
|
|
|
'Psalm was able to infer types for 100% of the codebase',
|
|
|
|
$this->project_analyzer->getCodebase()->analyzer->getTypeInferenceSummary(
|
2022-12-18 17:15:15 +01:00
|
|
|
$this->project_analyzer->getCodebase(),
|
|
|
|
),
|
2018-10-17 17:03:32 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testCheckDir(): void
|
2018-10-17 17:03:32 +02:00
|
|
|
{
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
|
2018-10-17 17:03:32 +02:00
|
|
|
Config::loadFromXML(
|
|
|
|
(string)getcwd(),
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
2019-05-10 00:23:14 +02:00
|
|
|
<directory name="tests/fixtures/DummyProject" />
|
2018-10-17 17:03:32 +02:00
|
|
|
</projectFiles>
|
2022-12-18 17:15:15 +01:00
|
|
|
</psalm>',
|
|
|
|
),
|
2018-10-17 17:03:32 +02:00
|
|
|
);
|
|
|
|
|
2021-11-27 01:06:33 +01:00
|
|
|
$this->project_analyzer->setPhpVersion('8.1', 'tests');
|
|
|
|
|
2019-05-30 16:30:41 +02:00
|
|
|
$this->project_analyzer->progress = new EchoProgress();
|
|
|
|
|
2018-10-17 17:03:32 +02:00
|
|
|
ob_start();
|
2019-05-10 00:23:14 +02:00
|
|
|
$this->project_analyzer->checkDir('tests/fixtures/DummyProject');
|
2018-10-17 17:03:32 +02:00
|
|
|
$output = ob_get_clean();
|
|
|
|
|
2023-01-05 15:12:29 +01:00
|
|
|
$this->assertStringContainsString('Target PHP version: 8.1 (set by tests)', $output);
|
|
|
|
$this->assertStringContainsString('Scanning files...', $output);
|
|
|
|
$this->assertStringContainsString('Analyzing files...', $output);
|
2018-10-17 17:03:32 +02:00
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
$this->assertSame(0, IssueBuffer::getErrorCount());
|
2018-10-17 17:03:32 +02:00
|
|
|
|
|
|
|
$this->assertSame(
|
2019-03-23 14:50:47 +01:00
|
|
|
'Psalm was able to infer types for 100% of the codebase',
|
|
|
|
$this->project_analyzer->getCodebase()->analyzer->getTypeInferenceSummary(
|
2022-12-18 17:15:15 +01:00
|
|
|
$this->project_analyzer->getCodebase(),
|
|
|
|
),
|
2018-10-17 17:03:32 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testCheckPaths(): void
|
2018-10-17 17:03:32 +02:00
|
|
|
{
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
|
2018-10-17 17:03:32 +02:00
|
|
|
Config::loadFromXML(
|
|
|
|
(string)getcwd(),
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
2019-05-10 00:23:14 +02:00
|
|
|
<directory name="tests/fixtures/DummyProject" />
|
2018-10-17 17:03:32 +02:00
|
|
|
</projectFiles>
|
2022-12-18 17:15:15 +01:00
|
|
|
</psalm>',
|
|
|
|
),
|
2018-10-17 17:03:32 +02:00
|
|
|
);
|
|
|
|
|
2021-11-27 01:06:33 +01:00
|
|
|
$this->project_analyzer->setPhpVersion('8.1', 'tests');
|
|
|
|
|
2019-05-30 16:30:41 +02:00
|
|
|
$this->project_analyzer->progress = new EchoProgress();
|
|
|
|
|
2018-10-17 17:03:32 +02:00
|
|
|
ob_start();
|
2020-08-23 16:32:07 +02:00
|
|
|
// checkPaths expects absolute paths,
|
|
|
|
// otherwise it's unable to match them against configured folders
|
2019-10-15 18:09:08 +02:00
|
|
|
$this->project_analyzer->checkPaths([
|
2020-08-23 16:32:07 +02:00
|
|
|
realpath(getcwd() . '/tests/fixtures/DummyProject/Bar.php'),
|
|
|
|
realpath(getcwd() . '/tests/fixtures/DummyProject/SomeTrait.php'),
|
2019-10-15 18:09:08 +02:00
|
|
|
]);
|
2018-10-17 17:03:32 +02:00
|
|
|
$output = ob_get_clean();
|
|
|
|
|
2023-01-05 15:12:29 +01:00
|
|
|
$this->assertStringContainsString('Target PHP version: 8.1 (set by tests)', $output);
|
|
|
|
$this->assertStringContainsString('Scanning files...', $output);
|
|
|
|
$this->assertStringContainsString('Analyzing files...', $output);
|
2018-10-17 17:03:32 +02:00
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
$this->assertSame(0, IssueBuffer::getErrorCount());
|
2018-10-17 17:03:32 +02:00
|
|
|
|
|
|
|
$this->assertSame(
|
2019-03-23 14:50:47 +01:00
|
|
|
'Psalm was able to infer types for 100% of the codebase',
|
|
|
|
$this->project_analyzer->getCodebase()->analyzer->getTypeInferenceSummary(
|
2022-12-18 17:15:15 +01:00
|
|
|
$this->project_analyzer->getCodebase(),
|
|
|
|
),
|
2018-10-17 17:03:32 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testCheckFile(): void
|
2018-10-17 17:03:32 +02:00
|
|
|
{
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
|
2018-10-17 17:03:32 +02:00
|
|
|
Config::loadFromXML(
|
|
|
|
(string)getcwd(),
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
2019-05-10 00:23:14 +02:00
|
|
|
<directory name="tests/fixtures/DummyProject" />
|
2018-10-17 17:03:32 +02:00
|
|
|
</projectFiles>
|
2022-12-18 17:15:15 +01:00
|
|
|
</psalm>',
|
|
|
|
),
|
2018-10-17 17:03:32 +02:00
|
|
|
);
|
|
|
|
|
2021-11-27 01:06:33 +01:00
|
|
|
$this->project_analyzer->setPhpVersion('8.1', 'tests');
|
|
|
|
|
2019-05-30 16:30:41 +02:00
|
|
|
$this->project_analyzer->progress = new EchoProgress();
|
|
|
|
|
2018-10-17 17:03:32 +02:00
|
|
|
ob_start();
|
2020-08-23 16:32:07 +02:00
|
|
|
// checkPaths expects absolute paths,
|
|
|
|
// otherwise it's unable to match them against configured folders
|
2019-10-15 18:09:08 +02:00
|
|
|
$this->project_analyzer->checkPaths([
|
2020-08-23 16:32:07 +02:00
|
|
|
realpath(getcwd() . '/tests/fixtures/DummyProject/Bar.php'),
|
|
|
|
realpath(getcwd() . '/tests/fixtures/DummyProject/SomeTrait.php'),
|
2019-10-15 18:09:08 +02:00
|
|
|
]);
|
2018-10-17 17:03:32 +02:00
|
|
|
$output = ob_get_clean();
|
|
|
|
|
2023-01-05 15:12:29 +01:00
|
|
|
$this->assertStringContainsString('Target PHP version: 8.1 (set by tests)', $output);
|
|
|
|
$this->assertStringContainsString('Scanning files...', $output);
|
|
|
|
$this->assertStringContainsString('Analyzing files...', $output);
|
2018-10-17 17:03:32 +02:00
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
$this->assertSame(0, IssueBuffer::getErrorCount());
|
2018-10-17 17:03:32 +02:00
|
|
|
|
|
|
|
$this->assertSame(
|
2019-03-23 14:50:47 +01:00
|
|
|
'Psalm was able to infer types for 100% of the codebase',
|
|
|
|
$this->project_analyzer->getCodebase()->analyzer->getTypeInferenceSummary(
|
2022-12-18 17:15:15 +01:00
|
|
|
$this->project_analyzer->getCodebase(),
|
|
|
|
),
|
2018-10-17 17:03:32 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|