Skip to content

Commit

Permalink
Merge branch 'master' into remove-class-name-cli-option
Browse files Browse the repository at this point in the history
  • Loading branch information
realFlowControl committed Sep 10, 2019
2 parents a6f4846 + e7e7525 commit 8f3fc17
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion phive.xml
Original file line number Diff line number Diff line change
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.1" location="./tools/psalm" copy="true"/>
</phive>
2 changes: 0 additions & 2 deletions src/Util/Annotation/DocBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
* reflection symbol.
*
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*
* @psalm-mutation-free
*/
final class DocBlock
{
Expand Down
5 changes: 2 additions & 3 deletions src/Util/Annotation/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
use PHPUnit\Util\Exception;

/**
* Yes, this is a singleton registry. The reason why this can actually be a singleton
* without having kittens die is that reflection information (and therefore docblock
* information) is static within a single process.
* Reflection information, and therefore DocBlock information, is static within
* a single PHP process. It is therefore okay to use a Singleton registry here.
*
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Util/Log/TeamCity.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
)
);
}
}
}
File renamed without changes.
Binary file modified tools/psalm
Binary file not shown.

0 comments on commit 8f3fc17

Please sign in to comment.