Skip to content

Commit

Permalink
Update structure of requirements array
Browse files Browse the repository at this point in the history
In order to maintain BC, existing keys are no
longer used. Instead a new key is introduced.
See #2386
  • Loading branch information
dnaber-de authored and sebastianbergmann committed Apr 1, 2017
1 parent 558b430 commit cdf97ab
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 31 deletions.
30 changes: 15 additions & 15 deletions src/Util/Test.php
Expand Up @@ -212,8 +212,8 @@ public static function getRequirements($className, $methodName)
continue;
}
try {
$requires[ $matches[ 'name' ][ $i ] ] = [
'constraint' => self::$versionConstraintParser->parse(trim($matches[ 'constraint' ][$i]))
$requires[$matches['name'][$i] . '_constraint'] = [
'constraint' => self::$versionConstraintParser->parse(trim($matches['constraint'][$i]))
];
} catch (\PharIo\Version\Exception $e) {
throw $e; //Todo how should we handle errors
Expand Down Expand Up @@ -259,19 +259,19 @@ public static function getMissingRequirements($className, $methodName)
$missing = [];

if (!empty($required['PHP'])) {
if (!empty($required['PHP']['constraint'])) {
$version = new \PharIo\Version\Version(self::semanticPhpVersion());
if (!$required['PHP']['constraint']->complies($version)) {
$missing[] = sprintf(
'PHP Version does not match the required constraint %s.',
$required['PHP']['constraint']->asString()
);
}
} else {
$operator = empty($required[ 'PHP' ][ 'operator' ]) ? '>=' : $required[ 'PHP' ][ 'operator' ];
if (!version_compare(PHP_VERSION, $required['PHP']['version'], $operator)) {
$missing[] = sprintf('PHP %s %s is required.', $operator, $required[ 'PHP' ][ 'version' ]);
}
$operator = empty($required['PHP']['operator']) ? '>=' : $required['PHP']['operator'];

if (!version_compare(PHP_VERSION, $required['PHP']['version'], $operator)) {
$missing[] = sprintf('PHP %s %s is required.', $operator, $required['PHP']['version']);
}
} elseif (!empty($required['PHP_constraint'])) {
$version = new \PharIo\Version\Version(self::semanticPhpVersion());

if (!$required['PHP_constraint']['constraint']->complies($version)) {
$missing[] = sprintf(
'PHP Version does not match the required constraint %s.',
$required['PHP_constraint']['constraint']->asString()
);
}
}

Expand Down
34 changes: 18 additions & 16 deletions tests/Util/TestTest.php
Expand Up @@ -315,22 +315,24 @@ public function requirementsProvider()
public function testGetRequirementsWithVersionConstraints($test, $result)
{
$requirements = Test::getRequirements(\RequirementsTest::class, $test);
$this->assertArrayHasKey(
'PHP',
$requirements
);
$this->assertArrayHasKey(
'constraint',
$requirements[ 'PHP' ]
);
$this->assertInstanceOf(
VersionConstraint::class,
$requirements[ 'PHP' ]['constraint']
);
$this->assertSame(
$result[ 'PHP' ][ 'constraint' ],
$requirements[ 'PHP' ]['constraint']->asString()
);
foreach ($result as $type => $expected_requirement) {
$this->assertArrayHasKey(
"{$type}_constraint",
$requirements
);
$this->assertArrayHasKey(
'constraint',
$requirements["{$type}_constraint"]
);
$this->assertInstanceOf(
VersionConstraint::class,
$requirements["{$type}_constraint"]['constraint']
);
$this->assertSame(
$expected_requirement['constraint'],
$requirements["{$type}_constraint"]['constraint']->asString()
);
}
}

public function requirementsWithVersionConstraintsProvider()
Expand Down

0 comments on commit cdf97ab

Please sign in to comment.