2019-02-09 07:59:23 +01:00
|
|
|
<?php
|
2019-11-14 03:34:10 +01:00
|
|
|
|
2019-02-09 07:59:23 +01:00
|
|
|
namespace Psalm\PhpUnitPlugin\Tests\Helper;
|
|
|
|
|
2019-02-10 07:19:06 +01:00
|
|
|
use Codeception\Exception\Skip;
|
|
|
|
use Codeception\Exception\TestRuntimeException;
|
|
|
|
use Composer\Semver\Comparator;
|
|
|
|
use Composer\Semver\VersionParser;
|
2019-05-17 00:26:16 +02:00
|
|
|
use PackageVersions\Versions;
|
2019-02-10 07:19:06 +01:00
|
|
|
|
2019-02-09 07:59:23 +01:00
|
|
|
// here you can define custom actions
|
|
|
|
// all public methods declared in helper class will be available in $I
|
|
|
|
|
|
|
|
class Acceptance extends \Codeception\Module
|
|
|
|
{
|
2020-06-19 00:38:51 +02:00
|
|
|
/** @var array<string,string> */
|
2019-11-14 03:34:10 +01:00
|
|
|
public const VERSION_OPERATORS = [
|
2019-02-10 07:19:06 +01:00
|
|
|
'newer than' => '>',
|
|
|
|
'older than' => '<',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given /I have PHPUnit (newer than|older than) "([0-9.]+)" \(because of "([^"]+)"\)/
|
2019-02-13 22:03:21 +01:00
|
|
|
*
|
|
|
|
* @return void
|
2019-02-10 07:19:06 +01:00
|
|
|
*/
|
2019-02-13 22:03:21 +01:00
|
|
|
public function havePHPUnitOfACertainVersionRangeBecauseOf(string $operator, string $version, string $reason)
|
2019-02-10 07:19:06 +01:00
|
|
|
{
|
|
|
|
if (!isset(self::VERSION_OPERATORS[$operator])) {
|
|
|
|
throw new TestRuntimeException("Unknown operator: $operator");
|
|
|
|
}
|
|
|
|
|
|
|
|
$op = (string) self::VERSION_OPERATORS[$operator];
|
|
|
|
|
2019-06-29 23:00:39 +02:00
|
|
|
$currentVersion = (string) explode('@', Versions::getVersion('phpunit/phpunit'))[0];
|
2019-02-10 07:19:06 +01:00
|
|
|
$this->debug(sprintf("Current version: %s", $currentVersion));
|
|
|
|
|
|
|
|
$parser = new VersionParser();
|
|
|
|
|
|
|
|
$currentVersion = $parser->normalize($currentVersion);
|
|
|
|
$version = $parser->normalize($version);
|
2019-02-09 07:59:23 +01:00
|
|
|
|
2019-02-10 07:19:06 +01:00
|
|
|
$result = Comparator::compare($currentVersion, $op, $version);
|
|
|
|
$this->debug("Comparing $currentVersion $op $version => $result");
|
|
|
|
if (!$result) {
|
|
|
|
throw new Skip("This scenario requires PHPUnit $op $version because of $reason");
|
|
|
|
}
|
|
|
|
}
|
2019-02-09 07:59:23 +01:00
|
|
|
}
|