Skip to content

Commit

Permalink
Handles exceptions on invalid version constraints sebastianbergmann#2386
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaber-de committed Apr 1, 2017
1 parent 5593284 commit f22deb6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Util/Test.php
Expand Up @@ -16,6 +16,7 @@
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\SelfDescribing;
use PHPUnit\Framework\SkippedTestError;
use PHPUnit\Framework\Warning;
use PHPUnit\Runner\Version;
use ReflectionClass;
use ReflectionException;
Expand Down Expand Up @@ -216,7 +217,7 @@ public static function getRequirements($className, $methodName)
'constraint' => self::$versionConstraintParser->parse(trim($matches['constraint'][$i]))
];
} catch (\PharIo\Version\Exception $e) {
throw $e; //Todo how should we handle errors
throw new Warning($e->getMessage(), $e->getCode(), $e);
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/Util/TestTest.php
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Framework\CodeCoverageException;
use PHPUnit\Framework\Exception;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Warning;

class TestTest extends TestCase
{
Expand Down Expand Up @@ -439,6 +440,24 @@ public function requirementsWithVersionConstraintsProvider()
]
];
}

/**
* @dataProvider requirementsWithInvalidVersionConstraintsThrowsExceptionProvider
*/
public function testGetRequirementsWithInvalidVersionConstraintsThrowsException($test)
{
$this->expectException(Warning::class);
Test::getRequirements(\RequirementsTest::class, $test);
}

public function requirementsWithInvalidVersionConstraintsThrowsExceptionProvider()
{
return [
['testVersionConstraintInvalidPhpConstraint'],
['testVersionConstraintInvalidPhpUnitConstraint']
];
}

public function testGetRequirementsMergesClassAndMethodDocBlocks()
{
$expectedAnnotations = [
Expand Down
13 changes: 13 additions & 0 deletions tests/_files/RequirementsTest.php
Expand Up @@ -423,4 +423,17 @@ public function testVersionConstraintCaretOrTilde()
public function testVersionConstraintRegexpIgnoresWhitespace()
{
}

/**
* @requires PHP ~^12345
*/
public function testVersionConstraintInvalidPhpConstraint()
{
}
/**
* @requires PHPUnit ~^12345
*/
public function testVersionConstraintInvalidPhpUnitConstraint()
{
}
}

0 comments on commit f22deb6

Please sign in to comment.