From f22deb684f60a917f09ed3d682142a95b0043fcb Mon Sep 17 00:00:00 2001 From: David Naber Date: Sat, 1 Apr 2017 11:50:10 +0200 Subject: [PATCH] Handles exceptions on invalid version constraints #2386 --- src/Util/Test.php | 3 ++- tests/Util/TestTest.php | 19 +++++++++++++++++++ tests/_files/RequirementsTest.php | 13 +++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Util/Test.php b/src/Util/Test.php index a6b653bdb12..5fa6909f1ac 100644 --- a/src/Util/Test.php +++ b/src/Util/Test.php @@ -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; @@ -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); } } } diff --git a/tests/Util/TestTest.php b/tests/Util/TestTest.php index b068440d502..d740dd01298 100644 --- a/tests/Util/TestTest.php +++ b/tests/Util/TestTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\CodeCoverageException; use PHPUnit\Framework\Exception; use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Warning; class TestTest extends TestCase { @@ -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 = [ diff --git a/tests/_files/RequirementsTest.php b/tests/_files/RequirementsTest.php index a967339e6df..2c09b4da705 100644 --- a/tests/_files/RequirementsTest.php +++ b/tests/_files/RequirementsTest.php @@ -423,4 +423,17 @@ public function testVersionConstraintCaretOrTilde() public function testVersionConstraintRegexpIgnoresWhitespace() { } + + /** + * @requires PHP ~^12345 + */ + public function testVersionConstraintInvalidPhpConstraint() + { + } + /** + * @requires PHPUnit ~^12345 + */ + public function testVersionConstraintInvalidPhpUnitConstraint() + { + } }