mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
9027bc6190
The idea behind this is that Psalm should not use project autoloader for its own things. So if we have a project with autoloader and no code, then any project autoloader hit means Psalm failed to load something itself. Right now it highlights several issues in CoreGenericClasses stub: - usage of `callback` instead of `callable` - `@property-read` not resolving template parameters
55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Psalm\Tests\EndToEnd;
|
|
|
|
use Symfony\Component\Process\Process;
|
|
|
|
use function array_merge;
|
|
|
|
trait PsalmRunnerTrait
|
|
{
|
|
/** @var string */
|
|
private $psalm = __DIR__ . '/../../psalm';
|
|
|
|
/** @var string */
|
|
private $psalter = __DIR__ . '/../../psalter';
|
|
|
|
/**
|
|
* @param list<string> $args
|
|
*
|
|
* @return array{STDOUT: string, STDERR: string, CODE: int|null}
|
|
*/
|
|
private function runPsalm(
|
|
array $args,
|
|
string $workingDir,
|
|
bool $shouldFail = false,
|
|
bool $relyOnConfigDir = true
|
|
): array {
|
|
// As config files all contain `resolveFromConfigFile="true"` Psalm
|
|
// shouldn't need to be run from the same directory that the code being
|
|
// analysed exists in.
|
|
|
|
// Windows doesn't read shabangs, so to allow this to work on windows
|
|
// we run `php psalm` rather than just `psalm`.
|
|
|
|
if ($relyOnConfigDir) {
|
|
$process = new Process(array_merge(['php', $this->psalm, '-c=' . $workingDir . '/psalm.xml'], $args), null);
|
|
} else {
|
|
$process = new Process(array_merge(['php', $this->psalm], $args), $workingDir);
|
|
}
|
|
|
|
if (!$shouldFail) {
|
|
$process->mustRun();
|
|
} else {
|
|
$process->run();
|
|
$this->assertGreaterThan(0, $process->getExitCode());
|
|
}
|
|
|
|
return [
|
|
'STDOUT' => $process->getOutput(),
|
|
'STDERR' => $process->getErrorOutput(),
|
|
'CODE' => $process->getExitCode(),
|
|
];
|
|
}
|
|
}
|