2018-11-14 06:36:33 +01:00
|
|
|
<?php
|
2019-11-14 03:34:10 +01:00
|
|
|
|
2018-11-14 06:36:33 +01:00
|
|
|
namespace Psalm\PhpUnitPlugin;
|
|
|
|
|
2019-02-10 07:19:06 +01:00
|
|
|
use Composer\Semver\Comparator;
|
|
|
|
use Composer\Semver\VersionParser;
|
2019-05-17 00:26:16 +02:00
|
|
|
use PackageVersions\Versions;
|
2018-11-14 06:36:33 +01:00
|
|
|
use SimpleXMLElement;
|
|
|
|
use Psalm\Plugin\PluginEntryPointInterface;
|
|
|
|
use Psalm\Plugin\RegistrationInterface;
|
|
|
|
|
2019-03-01 19:24:20 +01:00
|
|
|
/** @psalm-suppress UnusedClass */
|
2018-11-14 06:36:33 +01:00
|
|
|
class Plugin implements PluginEntryPointInterface
|
|
|
|
{
|
|
|
|
/** @return void */
|
|
|
|
public function __invoke(RegistrationInterface $psalm, SimpleXMLElement $config = null)
|
|
|
|
{
|
2018-12-01 03:41:48 +01:00
|
|
|
$psalm->addStubFile(__DIR__ . '/stubs/Assert.php');
|
2019-02-10 07:19:06 +01:00
|
|
|
if ($this->packageVersionIs('phpunit/phpunit', '>=', '7.5')) {
|
|
|
|
$psalm->addStubFile(__DIR__ . '/stubs/Assert_75.php');
|
|
|
|
}
|
2018-11-14 06:36:33 +01:00
|
|
|
$psalm->addStubFile(__DIR__ . '/stubs/TestCase.php');
|
2018-11-25 00:27:52 +01:00
|
|
|
$psalm->addStubFile(__DIR__ . '/stubs/MockBuilder.php');
|
2018-11-25 07:40:30 +01:00
|
|
|
$psalm->addStubFile(__DIR__ . '/stubs/InvocationMocker.php');
|
2018-12-08 23:26:47 +01:00
|
|
|
$psalm->addStubFile(__DIR__ . '/stubs/Prophecy.php');
|
2019-02-17 07:28:22 +01:00
|
|
|
|
|
|
|
class_exists(Hooks\TestCaseHandler::class, true);
|
|
|
|
$psalm->registerHooksFromClass(Hooks\TestCaseHandler::class);
|
2018-11-14 06:36:33 +01:00
|
|
|
}
|
2019-02-10 07:19:06 +01:00
|
|
|
|
|
|
|
private function packageVersionIs(string $package, string $op, string $ref): bool
|
|
|
|
{
|
2019-05-17 00:26:16 +02:00
|
|
|
$currentVersion = (string) explode('@', Versions::getVersion($package))[0];
|
2019-02-10 07:19:06 +01:00
|
|
|
|
|
|
|
$parser = new VersionParser();
|
|
|
|
|
|
|
|
$currentVersion = $parser->normalize($currentVersion);
|
|
|
|
$ref = $parser->normalize($ref);
|
|
|
|
|
|
|
|
return Comparator::compare($currentVersion, $op, $ref);
|
|
|
|
}
|
2018-11-14 06:36:33 +01:00
|
|
|
}
|