Skip to content

Commit

Permalink
Merge branch '8.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Sep 9, 2019
2 parents 04d565a + 3d432d2 commit 71ab6af
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion phive.xml
Expand Up @@ -4,5 +4,5 @@
<phar name="php-cs-fixer" version="^2.14" installed="2.15.3" location="./tools/php-cs-fixer" copy="true"/>
<phar name="phpdox" version="^0.11" installed="0.12.0" location="./tools/phpdox" copy="true"/>
<phar name="phploc" version="^4.0" installed="4.0.1" location="./tools/phploc" copy="true"/>
<phar name="psalm" version="^3.2" installed="3.4.12" location="./tools/psalm" copy="true"/>
<phar name="psalm" version="^3.5" installed="3.5.0" location="./tools/psalm" copy="true"/>
</phive>
4 changes: 2 additions & 2 deletions src/Util/Log/TeamCity.php
Expand Up @@ -203,7 +203,7 @@ public function startTestSuite(TestSuite $suite): void
} else {
$split = \explode('::', $suiteName);

if (\count($split) === 2 && \method_exists($split[0], $split[1])) {
if (\count($split) === 2 && \class_exists($split[0]) && \method_exists($split[0], $split[1])) {
$fileName = self::getFileName($split[0]);
$parameters['locationHint'] = "php_qn://$fileName::\\$suiteName";
$parameters['name'] = $split[1];
Expand All @@ -229,7 +229,7 @@ public function endTestSuite(TestSuite $suite): void
if (!\class_exists($suiteName, false)) {
$split = \explode('::', $suiteName);

if (\count($split) === 2 && \method_exists($split[0], $split[1])) {
if (\count($split) === 2 && \class_exists($split[0]) && \method_exists($split[0], $split[1])) {
$parameters['name'] = $split[1];
}
}
Expand Down
24 changes: 23 additions & 1 deletion src/Util/Test.php
Expand Up @@ -144,6 +144,7 @@ public static function getRequirements(string $className, string $methodName): a
/**
* Returns the missing requirements for a test.
*
* @throws Exception
* @throws Warning
*/
public static function getMissingRequirements(string $className, string $methodName): array
Expand All @@ -155,6 +156,8 @@ public static function getMissingRequirements(string $className, string $methodN
if (!empty($required['PHP'])) {
$operator = empty($required['PHP']['operator']) ? '>=' : $required['PHP']['operator'];

self::ensureOperatorIsValid($operator);

if (!\version_compare(\PHP_VERSION, $required['PHP']['version'], $operator)) {
$missing[] = \sprintf('PHP %s %s is required.', $operator, $required['PHP']['version']);
$hint = $hint ?? 'PHP';
Expand All @@ -177,6 +180,8 @@ public static function getMissingRequirements(string $className, string $methodN

$operator = empty($required['PHPUnit']['operator']) ? '>=' : $required['PHPUnit']['operator'];

self::ensureOperatorIsValid($operator);

if (!\version_compare($phpunitVersion, $required['PHPUnit']['version'], $operator)) {
$missing[] = \sprintf('PHPUnit %s %s is required.', $operator, $required['PHPUnit']['version']);
$hint = $hint ?? 'PHPUnit';
Expand Down Expand Up @@ -212,7 +217,7 @@ public static function getMissingRequirements(string $className, string $methodN
foreach ($required['functions'] as $function) {
$pieces = \explode('::', $function);

if (\count($pieces) === 2 && \method_exists($pieces[0], $pieces[1])) {
if (\count($pieces) === 2 && \class_exists($pieces[0]) && \method_exists($pieces[0], $pieces[1])) {
continue;
}

Expand Down Expand Up @@ -253,6 +258,8 @@ public static function getMissingRequirements(string $className, string $methodN

$operator = empty($req['operator']) ? '>=' : $req['operator'];

self::ensureOperatorIsValid($operator);

if ($actualVersion === false || !\version_compare($actualVersion, $req['version'], $operator)) {
$missing[] = \sprintf('Extension %s %s %s is required.', $extension, $operator, $req['version']);
$hint = $hint ?? 'extension_' . $extension;
Expand Down Expand Up @@ -859,4 +866,19 @@ private static function mergeArraysRecursively(array $a, array $b): array

return $a;
}

/*
* @throws Exception
*/
private static function ensureOperatorIsValid(string $operator): void
{
if (!\in_array($operator, ['<', 'lt', '<=', 'le', '>', 'gt', '>=', 'ge', '==', '=', 'eq', '!=', '<>', 'ne'])) {
throw new Exception(
\sprintf(
'"%s" is not a valid version_compare() operator',
$operator
)
);
}
}
}
Binary file modified tools/psalm
Binary file not shown.

0 comments on commit 71ab6af

Please sign in to comment.